Skip to content

Commit 397b63f

Browse files
committed
fix: parser process enum metadata
1 parent cb0124a commit 397b63f

4 files changed

Lines changed: 204 additions & 198 deletions

File tree

.changeset/wide-banks-pay.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@hey-api/shared": patch
3+
"@hey-api/openapi-ts": patch
4+
---
5+
6+
**parser**: fix: process enum metadata

packages/shared/src/openApi/2.0.x/parser/schema.ts

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import type {
1111
import { discriminatorValues } from '../../../openApi/shared/utils/discriminator';
1212
import { isTopLevelComponent, refToName } from '../../../utils/ref';
1313

14-
export const getSchemaType = ({
14+
export function getSchemaType({
1515
schema,
1616
}: {
1717
schema: OpenAPIV2.SchemaObject;
18-
}): SchemaType<OpenAPIV2.SchemaObject> | undefined => {
18+
}): SchemaType<OpenAPIV2.SchemaObject> | undefined {
1919
if (schema.type) {
2020
return schema.type;
2121
}
@@ -26,15 +26,15 @@ export const getSchemaType = ({
2626
}
2727

2828
return;
29-
};
29+
}
3030

31-
const parseSchemaJsDoc = ({
31+
function parseSchemaJsDoc({
3232
irSchema,
3333
schema,
3434
}: {
3535
irSchema: IR.SchemaObject;
3636
schema: OpenAPIV2.SchemaObject;
37-
}) => {
37+
}) {
3838
if (schema.example) {
3939
irSchema.example = schema.example;
4040
}
@@ -46,15 +46,15 @@ const parseSchemaJsDoc = ({
4646
if (schema.title) {
4747
irSchema.title = schema.title;
4848
}
49-
};
49+
}
5050

51-
const parseSchemaMeta = ({
51+
function parseSchemaMeta({
5252
irSchema,
5353
schema,
5454
}: {
5555
irSchema: IR.SchemaObject;
5656
schema: OpenAPIV2.SchemaObject;
57-
}) => {
57+
}) {
5858
if (schema.default !== undefined) {
5959
irSchema.default = schema.default;
6060
}
@@ -102,9 +102,9 @@ const parseSchemaMeta = ({
102102
if (schema.readOnly) {
103103
irSchema.accessScope = 'read';
104104
}
105-
};
105+
}
106106

107-
const parseArray = ({
107+
function parseArray({
108108
context,
109109
irSchema = {},
110110
schema,
@@ -114,7 +114,7 @@ const parseArray = ({
114114
irSchema?: IR.SchemaObject;
115115
schema: OpenAPIV2.SchemaObject;
116116
state: SchemaState;
117-
}): IR.SchemaObject => {
117+
}): IR.SchemaObject {
118118
if (schema.maxItems && schema.maxItems === schema.minItems) {
119119
irSchema.type = 'tuple';
120120
} else {
@@ -156,36 +156,36 @@ const parseArray = ({
156156
});
157157

158158
return irSchema;
159-
};
159+
}
160160

161-
const parseBoolean = ({
161+
function parseBoolean({
162162
irSchema = {},
163163
}: {
164164
context: Context;
165165
irSchema?: IR.SchemaObject;
166166
schema: OpenAPIV2.SchemaObject;
167167
state: SchemaState;
168-
}): IR.SchemaObject => {
168+
}): IR.SchemaObject {
169169
irSchema.type = 'boolean';
170170

171171
return irSchema;
172-
};
172+
}
173173

174-
const parseNumber = ({
174+
function parseNumber({
175175
irSchema = {},
176176
schema,
177177
}: {
178178
context: Context;
179179
irSchema?: IR.SchemaObject;
180180
schema: SchemaWithRequired<OpenAPIV2.SchemaObject, 'type'>;
181181
state: SchemaState;
182-
}): IR.SchemaObject => {
182+
}): IR.SchemaObject {
183183
irSchema.type = schema.type;
184184

185185
return irSchema;
186-
};
186+
}
187187

188-
const parseObject = ({
188+
function parseObject({
189189
context,
190190
irSchema = {},
191191
schema,
@@ -195,7 +195,7 @@ const parseObject = ({
195195
irSchema?: IR.SchemaObject;
196196
schema: OpenAPIV2.SchemaObject;
197197
state: SchemaState;
198-
}): IR.SchemaObject => {
198+
}): IR.SchemaObject {
199199
irSchema.type = 'object';
200200

201201
const schemaProperties: Record<string, IR.SchemaObject> = {};
@@ -251,30 +251,30 @@ const parseObject = ({
251251
}
252252

253253
return irSchema;
254-
};
254+
}
255255

256-
const parseString = ({
256+
function parseString({
257257
irSchema = {},
258258
}: {
259259
context: Context;
260260
irSchema?: IR.SchemaObject;
261261
schema: OpenAPIV2.SchemaObject;
262262
state: SchemaState;
263-
}): IR.SchemaObject => {
263+
}): IR.SchemaObject {
264264
irSchema.type = 'string';
265265

266266
return irSchema;
267-
};
267+
}
268268

269-
export const parseExtensions = ({ source, target }: { source: object; target: object }) => {
269+
export function parseExtensions({ source, target }: { source: object; target: object }) {
270270
for (const key in source) {
271271
if (key.startsWith('x-')) {
272272
(target as Record<string, unknown>)[key] = (source as Record<string, unknown>)[key];
273273
}
274274
}
275-
};
275+
}
276276

277-
const initIrSchema = ({ schema }: { schema: OpenAPIV2.SchemaObject }): IR.SchemaObject => {
277+
function initIrSchema({ schema }: { schema: OpenAPIV2.SchemaObject }): IR.SchemaObject {
278278
const irSchema: IR.SchemaObject = {};
279279

280280
parseSchemaJsDoc({
@@ -288,17 +288,17 @@ const initIrSchema = ({ schema }: { schema: OpenAPIV2.SchemaObject }): IR.Schema
288288
});
289289

290290
return irSchema;
291-
};
291+
}
292292

293-
const parseAllOf = ({
293+
function parseAllOf({
294294
context,
295295
schema,
296296
state,
297297
}: {
298298
context: Context;
299299
schema: SchemaWithRequired<OpenAPIV2.SchemaObject, 'allOf'>;
300300
state: SchemaState;
301-
}): IR.SchemaObject => {
301+
}): IR.SchemaObject {
302302
let irSchema = initIrSchema({ schema });
303303

304304
const schemaItems: Array<IR.SchemaObject> = [];
@@ -441,17 +441,17 @@ const parseAllOf = ({
441441
}
442442

443443
return irSchema;
444-
};
444+
}
445445

446-
const parseEnum = ({
446+
function parseEnum({
447447
context,
448448
schema,
449449
state,
450450
}: {
451451
context: Context;
452452
schema: SchemaWithRequired<OpenAPIV2.SchemaObject, 'enum'>;
453453
state: SchemaState;
454-
}): IR.SchemaObject => {
454+
}): IR.SchemaObject {
455455
let irSchema = initIrSchema({ schema });
456456

457457
parseSchemaMeta({ irSchema, schema });
@@ -520,17 +520,17 @@ const parseEnum = ({
520520
});
521521

522522
return irSchema;
523-
};
523+
}
524524

525-
const parseRef = ({
525+
function parseRef({
526526
context,
527527
schema,
528528
state,
529529
}: {
530530
context: Context;
531531
schema: SchemaWithRequired<OpenAPIV2.SchemaObject, '$ref'>;
532532
state: SchemaState;
533-
}): IR.SchemaObject => {
533+
}): IR.SchemaObject {
534534
const irSchema: IR.SchemaObject = {};
535535
// Inline non-component refs (e.g. #/paths/...) and deep path refs (e.g. #/definitions/Foo/properties/bar)
536536
// to avoid generating orphaned named types or referencing unregistered symbols
@@ -572,9 +572,9 @@ const parseRef = ({
572572
}
573573

574574
return irSchema;
575-
};
575+
}
576576

577-
const parseNullableType = ({
577+
function parseNullableType({
578578
context,
579579
irSchema,
580580
schema,
@@ -584,7 +584,7 @@ const parseNullableType = ({
584584
irSchema?: IR.SchemaObject;
585585
schema: SchemaWithRequired<OpenAPIV2.SchemaObject, 'type'>;
586586
state: SchemaState;
587-
}): IR.SchemaObject => {
587+
}): IR.SchemaObject {
588588
if (!irSchema) {
589589
irSchema = initIrSchema({ schema });
590590
}
@@ -617,17 +617,17 @@ const parseNullableType = ({
617617
});
618618

619619
return irSchema;
620-
};
620+
}
621621

622-
const parseType = ({
622+
function parseType({
623623
context,
624624
schema,
625625
state,
626626
}: {
627627
context: Context;
628628
schema: SchemaWithRequired<OpenAPIV2.SchemaObject, 'type'>;
629629
state: SchemaState;
630-
}): IR.SchemaObject => {
630+
}): IR.SchemaObject {
631631
const irSchema = initIrSchema({ schema });
632632

633633
parseSchemaMeta({ irSchema, schema });
@@ -659,9 +659,9 @@ const parseType = ({
659659
},
660660
state,
661661
});
662-
};
662+
}
663663

664-
const parseOneType = ({
664+
function parseOneType({
665665
context,
666666
irSchema,
667667
schema,
@@ -671,7 +671,7 @@ const parseOneType = ({
671671
irSchema?: IR.SchemaObject;
672672
schema: SchemaWithRequired<OpenAPIV2.SchemaObject, 'type'>;
673673
state: SchemaState;
674-
}): IR.SchemaObject => {
674+
}): IR.SchemaObject {
675675
if (!irSchema) {
676676
irSchema = initIrSchema({ schema });
677677

@@ -723,16 +723,16 @@ const parseOneType = ({
723723
schema,
724724
});
725725
}
726-
};
726+
}
727727

728-
const parseUnknown = ({
728+
function parseUnknown({
729729
irSchema,
730730
schema,
731731
}: {
732732
context: Context;
733733
irSchema?: IR.SchemaObject;
734734
schema: OpenAPIV2.SchemaObject;
735-
}): IR.SchemaObject => {
735+
}): IR.SchemaObject {
736736
if (!irSchema) {
737737
irSchema = initIrSchema({ schema });
738738
}
@@ -742,17 +742,17 @@ const parseUnknown = ({
742742
parseSchemaMeta({ irSchema, schema });
743743

744744
return irSchema;
745-
};
745+
}
746746

747-
export const schemaToIrSchema = ({
747+
export function schemaToIrSchema({
748748
context,
749749
schema,
750750
state,
751751
}: {
752752
context: Context;
753753
schema: OpenAPIV2.SchemaObject;
754754
state: SchemaState | undefined;
755-
}): IR.SchemaObject => {
755+
}): IR.SchemaObject {
756756
if (!state) {
757757
state = {
758758
circularReferenceTracker: new Set(),
@@ -797,17 +797,17 @@ export const schemaToIrSchema = ({
797797
}
798798

799799
return parseUnknown({ context, schema });
800-
};
800+
}
801801

802-
export const parseSchema = ({
802+
export function parseSchema({
803803
$ref,
804804
context,
805805
schema,
806806
}: {
807807
$ref: string;
808808
context: Context;
809809
schema: OpenAPIV2.SchemaObject;
810-
}) => {
810+
}) {
811811
if (!context.ir.components) {
812812
context.ir.components = {};
813813
}
@@ -824,4 +824,4 @@ export const parseSchema = ({
824824
circularReferenceTracker: new Set(),
825825
},
826826
});
827-
};
827+
}

0 commit comments

Comments
 (0)