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

Merge pull request #470 from hey-api/fix/negative-enum-numeric-values

fix: negative numbers in numeric enums

authored by

Jordan Shatford and committed by
GitHub
ab68dfa1 dfad4258

+30 -13
+5
.changeset/early-radios-sort.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: negative numbers in numeric enums
+7 -4
packages/openapi-ts/src/compiler/typedef.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { addLeadingJSDocComment, type Comments, tsNodeToString } from './utils'; 3 + import { 4 + addLeadingJSDocComment, 5 + type Comments, 6 + ots, 7 + tsNodeToString, 8 + } from './utils'; 4 9 5 10 export const createTypeNode = ( 6 11 base: any | ts.TypeNode, ··· 11 16 } 12 17 13 18 if (typeof base === 'number') { 14 - return ts.factory.createLiteralTypeNode( 15 - ts.factory.createNumericLiteral(base), 16 - ); 19 + return ts.factory.createLiteralTypeNode(ots.number(base)); 17 20 } 18 21 19 22 return ts.factory.createTypeReferenceNode(
+3
packages/openapi-ts/test/__snapshots__/test/generated/v3/enums.gen.ts.snap
··· 114 114 * Период 115 115 */ 116 116 export const ValueEnum = { 117 + '_-10': -10, 118 + '_-1': -1, 119 + '_0': 0, 117 120 '_1': 1, 118 121 '_3': 3, 119 122 '_6': 6,
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap
··· 1643 1643 value: { 1644 1644 type: 'number', 1645 1645 description: 'Период', 1646 - enum: [1, 3, 6, 12] 1646 + enum: [-10, -1, 0, 1, 3, 6, 12] 1647 1647 } 1648 1648 } 1649 1649 } as const;
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap
··· 770 770 /** 771 771 * Период 772 772 */ 773 - value?: 1 | 3 | 6 | 12; 773 + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 774 774 }; 775 775 776 776 /**
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap
··· 770 770 /** 771 771 * Период 772 772 */ 773 - value?: 1 | 3 | 6 | 12; 773 + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 774 774 }; 775 775 776 776 /**
+3
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/enums.gen.ts.snap
··· 114 114 * Период 115 115 */ 116 116 export const ValueEnum = { 117 + '_-10': -10, 118 + '_-1': -1, 119 + '_0': 0, 117 120 '_1': 1, 118 121 '_3': 3, 119 122 '_6': 6,
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap
··· 770 770 /** 771 771 * Период 772 772 */ 773 - value?: 1 | 3 | 6 | 12; 773 + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 774 774 }; 775 775 776 776 /**
+3
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/enums.gen.ts.snap
··· 114 114 * Период 115 115 */ 116 116 export enum ValueEnum { 117 + '_-10' = -10, 118 + '_-1' = -1, 119 + '_0' = 0, 117 120 '_1' = 1, 118 121 '_3' = 3, 119 122 '_6' = 6,
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap
··· 770 770 /** 771 771 * Период 772 772 */ 773 - value?: 1 | 3 | 6 | 12; 773 + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 774 774 }; 775 775 776 776 /**
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap
··· 770 770 /** 771 771 * Период 772 772 */ 773 - value?: 1 | 3 | 6 | 12; 773 + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 774 774 }; 775 775 776 776 /**
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap
··· 1530 1530 properties: { 1531 1531 value: { 1532 1532 type: 'number', 1533 - enum: [1, 3, 6, 12] 1533 + enum: [-10, -1, 0, 1, 3, 6, 12] 1534 1534 } 1535 1535 } 1536 1536 } as const;
+1 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap
··· 1643 1643 value: { 1644 1644 type: 'number', 1645 1645 description: 'Период', 1646 - enum: [1, 3, 6, 12] 1646 + enum: [-10, -1, 0, 1, 3, 6, 12] 1647 1647 } 1648 1648 } 1649 1649 } as const;
+1 -1
packages/openapi-ts/test/spec/v3.json
··· 3190 3190 "value": { 3191 3191 "type": "number", 3192 3192 "description": "Период", 3193 - "enum": [1, 3, 6, 12] 3193 + "enum": [-10, -1, 0, 1, 3, 6, 12] 3194 3194 } 3195 3195 } 3196 3196 },