fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #745 from hey-api/fix/one-of-composition-properties

fix: handle properties in one-of composition

authored by

Lubos and committed by
GitHub
0e14810c 88f79bf3

+381 -53
+5
.changeset/unlucky-birds-work.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: handle properties in one-of composition
+47 -27
packages/openapi-ts/src/openApi/v3/parser/getModelComposition.ts
··· 116 116 117 117 if (properties.length) { 118 118 const foundComposition = findModelComposition(definition); 119 - if (foundComposition?.type === 'one-of') { 120 - composition.properties.forEach((property) => { 121 - property.properties = [...property.properties, ...properties]; 122 - }); 123 - } else { 124 - composition.properties = [ 125 - ...composition.properties, 126 - { 127 - $refs: [], 128 - base: 'unknown', 129 - description: '', 130 - enum: [], 131 - enums: [], 132 - export: 'interface', 133 - imports: [], 134 - in: '', 135 - isDefinition: false, 136 - isNullable: false, 137 - isReadOnly: false, 138 - isRequired: false, 139 - link: null, 140 - name: 'properties', 141 - properties, 142 - template: null, 143 - type: 'unknown', 144 - }, 145 - ]; 119 + if (foundComposition) { 120 + const propertiesProperty: Model = { 121 + $refs: [], 122 + base: 'unknown', 123 + description: '', 124 + enum: [], 125 + enums: [], 126 + export: 'interface', 127 + imports: [], 128 + in: '', 129 + isDefinition: false, 130 + isNullable: false, 131 + isReadOnly: false, 132 + isRequired: false, 133 + link: null, 134 + name: 'properties', 135 + properties, 136 + template: null, 137 + type: 'unknown', 138 + }; 139 + 140 + if (foundComposition.type === 'one-of') { 141 + composition.properties = [ 142 + { 143 + ...composition, 144 + base: '', 145 + description: null, 146 + enum: [], 147 + in: '', 148 + isDefinition: false, 149 + isNullable: false, 150 + isReadOnly: false, 151 + isRequired: true, 152 + link: null, 153 + name: '', 154 + template: null, 155 + type: '', 156 + }, 157 + propertiesProperty, 158 + ]; 159 + composition.export = 'all-of'; 160 + } else { 161 + composition.properties = [ 162 + ...composition.properties, 163 + propertiesProperty, 164 + ]; 165 + } 146 166 } 147 167 } 148 168
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap
··· 1709 1709 } 1710 1710 } as const; 1711 1711 1712 + export const $ModelWithOneOfAndProperties = { 1713 + type: 'object', 1714 + oneOf: [ 1715 + { 1716 + '$ref': '#/components/parameters/SimpleParameter' 1717 + }, 1718 + { 1719 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1720 + } 1721 + ], 1722 + required: ['baz', 'qux'], 1723 + properties: { 1724 + baz: { 1725 + type: 'integer', 1726 + format: 'uint16', 1727 + minimum: 0, 1728 + nullable: true 1729 + }, 1730 + qux: { 1731 + type: 'integer', 1732 + format: 'uint8', 1733 + minimum: 0 1734 + } 1735 + } 1736 + } as const; 1737 + 1712 1738 export const $ParameterSimpleParameterUnused = { 1713 1739 description: 'Model used to test deduplication strategy (unused)', 1714 1740 type: 'string'
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap
··· 783 783 784 784 export type CompositionWithOneOfAndProperties = { 785 785 foo: ParameterSimpleParameter; 786 - baz: number | null; 787 - qux: number; 788 786 } | { 789 787 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 788 + } & { 790 789 baz: number | null; 791 790 qux: number; 792 791 }; ··· 956 955 * </pre> 957 956 */ 958 957 template?: string; 958 + }; 959 + 960 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 961 + baz: number | null; 962 + qux: number; 959 963 }; 960 964 961 965 /**
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/schemas.gen.ts.snap
··· 1709 1709 } 1710 1710 } as const; 1711 1711 1712 + export const $ModelWithOneOfAndProperties = { 1713 + type: 'object', 1714 + oneOf: [ 1715 + { 1716 + '$ref': '#/components/parameters/SimpleParameter' 1717 + }, 1718 + { 1719 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1720 + } 1721 + ], 1722 + required: ['baz', 'qux'], 1723 + properties: { 1724 + baz: { 1725 + type: 'integer', 1726 + format: 'uint16', 1727 + minimum: 0, 1728 + nullable: true 1729 + }, 1730 + qux: { 1731 + type: 'integer', 1732 + format: 'uint8', 1733 + minimum: 0 1734 + } 1735 + } 1736 + } as const; 1737 + 1712 1738 export const $ParameterSimpleParameterUnused = { 1713 1739 description: 'Model used to test deduplication strategy (unused)', 1714 1740 type: 'string'
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap
··· 687 687 688 688 export type CompositionWithOneOfAndProperties = { 689 689 foo: ParameterSimpleParameter; 690 - baz: number | null; 691 - qux: number; 692 690 } | { 693 691 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 692 + } & { 694 693 baz: number | null; 695 694 qux: number; 696 695 }; ··· 833 832 * </pre> 834 833 */ 835 834 template?: string; 835 + }; 836 + 837 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 838 + baz: number | null; 839 + qux: number; 836 840 }; 837 841 838 842 /**
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/schemas.gen.ts.snap
··· 1709 1709 } 1710 1710 } as const; 1711 1711 1712 + export const $ModelWithOneOfAndProperties = { 1713 + type: 'object', 1714 + oneOf: [ 1715 + { 1716 + '$ref': '#/components/parameters/SimpleParameter' 1717 + }, 1718 + { 1719 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1720 + } 1721 + ], 1722 + required: ['baz', 'qux'], 1723 + properties: { 1724 + baz: { 1725 + type: 'integer', 1726 + format: 'uint16', 1727 + minimum: 0, 1728 + nullable: true 1729 + }, 1730 + qux: { 1731 + type: 'integer', 1732 + format: 'uint8', 1733 + minimum: 0 1734 + } 1735 + } 1736 + } as const; 1737 + 1712 1738 export const $ParameterSimpleParameterUnused = { 1713 1739 description: 'Model used to test deduplication strategy (unused)', 1714 1740 type: 'string'
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/types.gen.ts.snap
··· 783 783 784 784 export type CompositionWithOneOfAndProperties = { 785 785 foo: ParameterSimpleParameter; 786 - baz: number | null; 787 - qux: number; 788 786 } | { 789 787 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 788 + } & { 790 789 baz: number | null; 791 790 qux: number; 792 791 }; ··· 956 955 * </pre> 957 956 */ 958 957 template?: string; 958 + }; 959 + 960 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 961 + baz: number | null; 962 + qux: number; 959 963 }; 960 964 961 965 /**
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap
··· 687 687 688 688 export type CompositionWithOneOfAndProperties = { 689 689 foo: ParameterSimpleParameter; 690 - baz: number | null; 691 - qux: number; 692 690 } | { 693 691 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 692 + } & { 694 693 baz: number | null; 695 694 qux: number; 696 695 }; ··· 833 832 * </pre> 834 833 */ 835 834 template?: string; 835 + }; 836 + 837 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 838 + baz: number | null; 839 + qux: number; 836 840 }; 837 841 838 842 /**
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap
··· 750 750 751 751 export type CompositionWithOneOfAndProperties = { 752 752 foo: ParameterSimpleParameter; 753 - baz: number | null; 754 - qux: number; 755 753 } | { 756 754 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 755 + } & { 757 756 baz: number | null; 758 757 qux: number; 759 758 }; ··· 912 911 * </pre> 913 912 */ 914 913 template?: string; 914 + }; 915 + 916 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 917 + baz: number | null; 918 + qux: number; 915 919 }; 916 920 917 921 /**
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/schemas.gen.ts.snap
··· 1709 1709 } 1710 1710 } as const; 1711 1711 1712 + export const $ModelWithOneOfAndProperties = { 1713 + type: 'object', 1714 + oneOf: [ 1715 + { 1716 + '$ref': '#/components/parameters/SimpleParameter' 1717 + }, 1718 + { 1719 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1720 + } 1721 + ], 1722 + required: ['baz', 'qux'], 1723 + properties: { 1724 + baz: { 1725 + type: 'integer', 1726 + format: 'uint16', 1727 + minimum: 0, 1728 + nullable: true 1729 + }, 1730 + qux: { 1731 + type: 'integer', 1732 + format: 'uint8', 1733 + minimum: 0 1734 + } 1735 + } 1736 + } as const; 1737 + 1712 1738 export const $ParameterSimpleParameterUnused = { 1713 1739 description: 'Model used to test deduplication strategy (unused)', 1714 1740 type: 'string'
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/types.gen.ts.snap
··· 783 783 784 784 export type CompositionWithOneOfAndProperties = { 785 785 foo: ParameterSimpleParameter; 786 - baz: number | null; 787 - qux: number; 788 786 } | { 789 787 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 788 + } & { 790 789 baz: number | null; 791 790 qux: number; 792 791 }; ··· 956 955 * </pre> 957 956 */ 958 957 template?: string; 958 + }; 959 + 960 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 961 + baz: number | null; 962 + qux: number; 959 963 }; 960 964 961 965 /**
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/schemas.gen.ts.snap
··· 1709 1709 } 1710 1710 } as const; 1711 1711 1712 + export const $ModelWithOneOfAndProperties = { 1713 + type: 'object', 1714 + oneOf: [ 1715 + { 1716 + '$ref': '#/components/parameters/SimpleParameter' 1717 + }, 1718 + { 1719 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1720 + } 1721 + ], 1722 + required: ['baz', 'qux'], 1723 + properties: { 1724 + baz: { 1725 + type: 'integer', 1726 + format: 'uint16', 1727 + minimum: 0, 1728 + nullable: true 1729 + }, 1730 + qux: { 1731 + type: 'integer', 1732 + format: 'uint8', 1733 + minimum: 0 1734 + } 1735 + } 1736 + } as const; 1737 + 1712 1738 export const $ParameterSimpleParameterUnused = { 1713 1739 description: 'Model used to test deduplication strategy (unused)', 1714 1740 type: 'string'
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/types.gen.ts.snap
··· 783 783 784 784 export type CompositionWithOneOfAndProperties = { 785 785 foo: ParameterSimpleParameter; 786 - baz: number | null; 787 - qux: number; 788 786 } | { 789 787 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 788 + } & { 790 789 baz: number | null; 791 790 qux: number; 792 791 }; ··· 956 955 * </pre> 957 956 */ 958 957 template?: string; 958 + }; 959 + 960 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 961 + baz: number | null; 962 + qux: number; 959 963 }; 960 964 961 965 /**
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3_node/schemas.gen.ts.snap
··· 1709 1709 } 1710 1710 } as const; 1711 1711 1712 + export const $ModelWithOneOfAndProperties = { 1713 + type: 'object', 1714 + oneOf: [ 1715 + { 1716 + '$ref': '#/components/parameters/SimpleParameter' 1717 + }, 1718 + { 1719 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1720 + } 1721 + ], 1722 + required: ['baz', 'qux'], 1723 + properties: { 1724 + baz: { 1725 + type: 'integer', 1726 + format: 'uint16', 1727 + minimum: 0, 1728 + nullable: true 1729 + }, 1730 + qux: { 1731 + type: 'integer', 1732 + format: 'uint8', 1733 + minimum: 0 1734 + } 1735 + } 1736 + } as const; 1737 + 1712 1738 export const $ParameterSimpleParameterUnused = { 1713 1739 description: 'Model used to test deduplication strategy (unused)', 1714 1740 type: 'string'
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_node/types.gen.ts.snap
··· 783 783 784 784 export type CompositionWithOneOfAndProperties = { 785 785 foo: ParameterSimpleParameter; 786 - baz: number | null; 787 - qux: number; 788 786 } | { 789 787 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 788 + } & { 790 789 baz: number | null; 791 790 qux: number; 792 791 }; ··· 956 955 * </pre> 957 956 */ 958 957 template?: string; 958 + }; 959 + 960 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 961 + baz: number | null; 962 + qux: number; 959 963 }; 960 964 961 965 /**
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap
··· 1561 1561 } 1562 1562 } as const; 1563 1563 1564 + export const $ModelWithOneOfAndProperties = { 1565 + type: 'object', 1566 + oneOf: [ 1567 + { 1568 + '$ref': '#/components/parameters/SimpleParameter' 1569 + }, 1570 + { 1571 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1572 + } 1573 + ], 1574 + required: ['baz', 'qux'], 1575 + properties: { 1576 + baz: { 1577 + type: 'integer', 1578 + format: 'uint16', 1579 + minimum: 0, 1580 + nullable: true 1581 + }, 1582 + qux: { 1583 + type: 'integer', 1584 + format: 'uint8', 1585 + minimum: 0 1586 + } 1587 + } 1588 + } as const; 1589 + 1564 1590 export const $ParameterSimpleParameterUnused = { 1565 1591 type: 'string' 1566 1592 } as const;
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap
··· 1709 1709 } 1710 1710 } as const; 1711 1711 1712 + export const $ModelWithOneOfAndProperties = { 1713 + type: 'object', 1714 + oneOf: [ 1715 + { 1716 + '$ref': '#/components/parameters/SimpleParameter' 1717 + }, 1718 + { 1719 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1720 + } 1721 + ], 1722 + required: ['baz', 'qux'], 1723 + properties: { 1724 + baz: { 1725 + type: 'integer', 1726 + format: 'uint16', 1727 + minimum: 0, 1728 + nullable: true 1729 + }, 1730 + qux: { 1731 + type: 'integer', 1732 + format: 'uint8', 1733 + minimum: 0 1734 + } 1735 + } 1736 + } as const; 1737 + 1712 1738 export const $ParameterSimpleParameterUnused = { 1713 1739 description: 'Model used to test deduplication strategy (unused)', 1714 1740 type: 'string'
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_tree_shakeable/types.gen.ts.snap
··· 783 783 784 784 export type CompositionWithOneOfAndProperties = { 785 785 foo: ParameterSimpleParameter; 786 - baz: number | null; 787 - qux: number; 788 786 } | { 789 787 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 788 + } & { 790 789 baz: number | null; 791 790 qux: number; 792 791 }; ··· 956 955 * </pre> 957 956 */ 958 957 template?: string; 958 + }; 959 + 960 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 961 + baz: number | null; 962 + qux: number; 959 963 }; 960 964 961 965 /**
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap
··· 687 687 688 688 export type CompositionWithOneOfAndProperties = { 689 689 foo: ParameterSimpleParameter; 690 - baz: number | null; 691 - qux: number; 692 690 } | { 693 691 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 692 + } & { 694 693 baz: number | null; 695 694 qux: number; 696 695 }; ··· 833 832 * </pre> 834 833 */ 835 834 template?: string; 835 + }; 836 + 837 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 838 + baz: number | null; 839 + qux: number; 836 840 }; 837 841 838 842 /**
+26
packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/schemas.gen.ts.snap
··· 1709 1709 } 1710 1710 } as const; 1711 1711 1712 + export const $ModelWithOneOfAndProperties = { 1713 + type: 'object', 1714 + oneOf: [ 1715 + { 1716 + '$ref': '#/components/parameters/SimpleParameter' 1717 + }, 1718 + { 1719 + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' 1720 + } 1721 + ], 1722 + required: ['baz', 'qux'], 1723 + properties: { 1724 + baz: { 1725 + type: 'integer', 1726 + format: 'uint16', 1727 + minimum: 0, 1728 + nullable: true 1729 + }, 1730 + qux: { 1731 + type: 'integer', 1732 + format: 'uint8', 1733 + minimum: 0 1734 + } 1735 + } 1736 + } as const; 1737 + 1712 1738 export const $ParameterSimpleParameterUnused = { 1713 1739 description: 'Model used to test deduplication strategy (unused)', 1714 1740 type: 'string'
+6 -2
packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/types.gen.ts.snap
··· 783 783 784 784 export type CompositionWithOneOfAndProperties = { 785 785 foo: ParameterSimpleParameter; 786 - baz: number | null; 787 - qux: number; 788 786 } | { 789 787 bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 788 + } & { 790 789 baz: number | null; 791 790 qux: number; 792 791 }; ··· 956 955 * </pre> 957 956 */ 958 957 template?: string; 958 + }; 959 + 960 + export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { 961 + baz: number | null; 962 + qux: number; 959 963 }; 960 964 961 965 /**
+4 -4
packages/openapi-ts/test/sample.cjs
··· 17 17 }, 18 18 services: { 19 19 // asClass: true, 20 - // export: false, 20 + export: false, 21 21 // name: '^Parameters', 22 22 }, 23 23 types: { 24 24 // dates: 'types+transform', 25 - enums: 'typescript', 26 - // include: 27 - // '^ModelWithPrefixItemsConstantSizeArray|ModelWithAnyOfConstantSizeArray', 25 + // enums: 'typescript', 26 + include: 27 + '^(ModelWithOneOfAndProperties|CompositionWithOneOfAndProperties)', 28 28 // name: 'PascalCase', 29 29 }, 30 30 // useOptions: false,
+25
packages/openapi-ts/test/spec/v3.json
··· 3282 3282 } 3283 3283 } 3284 3284 }, 3285 + "ModelWithOneOfAndProperties": { 3286 + "type": "object", 3287 + "oneOf": [ 3288 + { 3289 + "$ref": "#/components/parameters/SimpleParameter" 3290 + }, 3291 + { 3292 + "$ref": "#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串" 3293 + } 3294 + ], 3295 + "required": ["baz", "qux"], 3296 + "properties": { 3297 + "baz": { 3298 + "type": "integer", 3299 + "format": "uint16", 3300 + "minimum": 0.0, 3301 + "nullable": true 3302 + }, 3303 + "qux": { 3304 + "type": "integer", 3305 + "format": "uint8", 3306 + "minimum": 0.0 3307 + } 3308 + } 3309 + }, 3285 3310 "ParameterSimpleParameterUnused": { 3286 3311 "description": "Model used to test deduplication strategy (unused)", 3287 3312 "type": "string"