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 #417 from hey-api/fix/unhandled-syntax

authored by

Lubos and committed by
GitHub
6f065f9d fa40f516

+134 -7
+5
.changeset/fluffy-suns-exist.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: unhandled SyntaxKind unknown when specification has numeric enums
+14 -7
packages/openapi-ts/src/compiler/typedef.ts
··· 2 2 3 3 import { addLeadingComment, type Comments, tsNodeToString } from './utils'; 4 4 5 - export const createTypeNode = (base: any | ts.TypeNode, args?: (any | ts.TypeNode)[]): ts.TypeNode => 6 - ts.isTypeNode(base) 7 - ? base 8 - : ts.factory.createTypeReferenceNode( 9 - base, 10 - args?.map(arg => createTypeNode(arg)) 11 - ); 5 + export const createTypeNode = (base: any | ts.TypeNode, args?: (any | ts.TypeNode)[]): ts.TypeNode => { 6 + if (ts.isTypeNode(base)) { 7 + return base; 8 + } 9 + 10 + if (typeof base === 'number') { 11 + return ts.factory.createLiteralTypeNode(ts.factory.createNumericLiteral(base)); 12 + } 13 + 14 + return ts.factory.createTypeReferenceNode( 15 + base, 16 + args?.map(arg => createTypeNode(arg)) 17 + ); 18 + }; 12 19 13 20 /** 14 21 * Create a type alias declaration. Example `export type X = Y;`.
+10
packages/openapi-ts/test/__snapshots__/test/generated/v3/enums.gen.ts.snap
··· 109 109 BAZ: 'baz', 110 110 QUX: 'qux', 111 111 } as const; 112 + 113 + /** 114 + * Период 115 + */ 116 + export const ValueEnum = { 117 + _1: 1, 118 + _3: 3, 119 + _6: 6, 120 + _12: 12, 121 + } as const;
+11
packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap
··· 1630 1630 maxItems: 2, 1631 1631 } as const; 1632 1632 1633 + export const $ModelWithNumericEnumUnion = { 1634 + type: 'object', 1635 + properties: { 1636 + value: { 1637 + type: 'number', 1638 + description: 'Период', 1639 + enum: [1, 3, 6, 12], 1640 + }, 1641 + }, 1642 + } as const; 1643 + 1633 1644 export const $SimpleParameter = { 1634 1645 description: 'This is a reusable parameter', 1635 1646 name: 'parameter',
+7
packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap
··· 786 786 787 787 export type ModelWithAnyOfConstantSizeArrayAndIntersect = [number & string, number & string]; 788 788 789 + export type ModelWithNumericEnumUnion = { 790 + /** 791 + * Период 792 + */ 793 + value?: 1 | 3 | 6 | 12; 794 + }; 795 + 789 796 /** 790 797 * This is a reusable parameter 791 798 */
+11
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/schemas.gen.ts.snap
··· 1630 1630 maxItems: 2, 1631 1631 } as const; 1632 1632 1633 + export const $ModelWithNumericEnumUnion = { 1634 + type: 'object', 1635 + properties: { 1636 + value: { 1637 + type: 'number', 1638 + description: 'Период', 1639 + enum: [1, 3, 6, 12], 1640 + }, 1641 + }, 1642 + } as const; 1643 + 1633 1644 export const $SimpleParameter = { 1634 1645 description: 'This is a reusable parameter', 1635 1646 name: 'parameter',
+7
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap
··· 786 786 787 787 export type ModelWithAnyOfConstantSizeArrayAndIntersect = [number & string, number & string]; 788 788 789 + export type ModelWithNumericEnumUnion = { 790 + /** 791 + * Период 792 + */ 793 + value?: 1 | 3 | 6 | 12; 794 + }; 795 + 789 796 /** 790 797 * This is a reusable parameter 791 798 */
+10
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/enums.gen.ts.snap
··· 109 109 BAZ: 'baz', 110 110 QUX: 'qux', 111 111 } as const; 112 + 113 + /** 114 + * Период 115 + */ 116 + export const ValueEnum = { 117 + _1: 1, 118 + _3: 3, 119 + _6: 6, 120 + _12: 12, 121 + } as const;
+7
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap
··· 786 786 787 787 export type ModelWithAnyOfConstantSizeArrayAndIntersect = [number & string, number & string]; 788 788 789 + export type ModelWithNumericEnumUnion = { 790 + /** 791 + * Период 792 + */ 793 + value?: 1 | 3 | 6 | 12; 794 + }; 795 + 789 796 /** 790 797 * This is a reusable parameter 791 798 */
+11
packages/openapi-ts/test/__snapshots__/test/generated/v3_date/schemas.gen.ts.snap
··· 1630 1630 maxItems: 2, 1631 1631 } as const; 1632 1632 1633 + export const $ModelWithNumericEnumUnion = { 1634 + type: 'object', 1635 + properties: { 1636 + value: { 1637 + type: 'number', 1638 + description: 'Период', 1639 + enum: [1, 3, 6, 12], 1640 + }, 1641 + }, 1642 + } as const; 1643 + 1633 1644 export const $SimpleParameter = { 1634 1645 description: 'This is a reusable parameter', 1635 1646 name: 'parameter',
+10
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/enums.gen.ts.snap
··· 109 109 BAZ = 'baz', 110 110 QUX = 'qux', 111 111 } 112 + 113 + /** 114 + * Период 115 + */ 116 + export enum ValueEnum { 117 + '_1' = 1, 118 + '_3' = 3, 119 + '_6' = 6, 120 + '_12' = 12, 121 + }
+11
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/schemas.gen.ts.snap
··· 1630 1630 maxItems: 2, 1631 1631 } as const; 1632 1632 1633 + export const $ModelWithNumericEnumUnion = { 1634 + type: 'object', 1635 + properties: { 1636 + value: { 1637 + type: 'number', 1638 + description: 'Период', 1639 + enum: [1, 3, 6, 12], 1640 + }, 1641 + }, 1642 + } as const; 1643 + 1633 1644 export const $SimpleParameter = { 1634 1645 description: 'This is a reusable parameter', 1635 1646 name: 'parameter',
+7
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap
··· 786 786 787 787 export type ModelWithAnyOfConstantSizeArrayAndIntersect = [number & string, number & string]; 788 788 789 + export type ModelWithNumericEnumUnion = { 790 + /** 791 + * Период 792 + */ 793 + value?: 1 | 3 | 6 | 12; 794 + }; 795 + 789 796 /** 790 797 * This is a reusable parameter 791 798 */
+7
packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap
··· 786 786 787 787 export type ModelWithAnyOfConstantSizeArrayAndIntersect = [number & string, number & string]; 788 788 789 + export type ModelWithNumericEnumUnion = { 790 + /** 791 + * Период 792 + */ 793 + value?: 1 | 3 | 6 | 12; 794 + }; 795 + 789 796 /** 790 797 * This is a reusable parameter 791 798 */
+6
packages/openapi-ts/test/spec/v3.json
··· 3157 3157 }, 3158 3158 "minItems": 2, 3159 3159 "maxItems": 2 3160 + }, 3161 + "ModelWithNumericEnumUnion": { 3162 + "type": "object", 3163 + "properties": { 3164 + "value": { "type": "number", "description": "Период", "enum": [1, 3, 6, 12] } 3165 + } 3160 3166 } 3161 3167 } 3162 3168 }