Skip to content

Commit

Permalink
remove object.freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrysteblyuk committed Jul 26, 2023
1 parent 8197418 commit 5375ca9
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/oats/src/generate-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ interface ImportDefinition {
}

// bit of a lie here really
const VOID_SCHEMA: oas.SchemaObject = Object.freeze({ type: 'void' as any });
const EMPTY_OBJECT_SCHEMA: oas.SchemaObject = Object.freeze({
type: 'object',
additionalProperties: false
});
const voidSchema: oas.SchemaObject = { type: 'void' as any };
const emptyObjectSchema: oas.SchemaObject = { type: 'object', additionalProperties: false };

export type Resolve = (
ref: string,
Expand Down Expand Up @@ -247,14 +244,14 @@ export function run(options: Options) {
oasSchema: oas.OpenAPIObject
) {
if (!paramSchema) {
return generateTopLevelType(op, EMPTY_OBJECT_SCHEMA);
return generateTopLevelType(op, emptyObjectSchema);
}
const schema = oautil.deref(paramSchema, oasSchema);
const queryParams = schema
.map(schema => oautil.deref(schema, oasSchema))
.filter(schema => schema.in === 'query');
if (queryParams.length === 0) {
return generateTopLevelType(op, EMPTY_OBJECT_SCHEMA);
return generateTopLevelType(op, emptyObjectSchema);
}
if (queryParams.some(param => !!param.explode)) {
assert(queryParams.length === 1, 'only one explode: true parameter is supported');
Expand All @@ -280,7 +277,7 @@ export function run(options: Options) {
oasSchema: oas.OpenAPIObject,
normalize = (name: string) => name
) {
const empty = generateTopLevelType(op, type === 'header' ? EMPTY_OBJECT_SCHEMA : VOID_SCHEMA);
const empty = generateTopLevelType(op, type === 'header' ? emptyObjectSchema : voidSchema);

if (!paramSchema) {
return empty;
Expand Down Expand Up @@ -362,7 +359,7 @@ export function run(options: Options) {
requestBody: undefined | oas.ReferenceObject | oas.RequestBodyObject
) {
if (requestBody == null) {
return generateTopLevelType(op, VOID_SCHEMA);
return generateTopLevelType(op, voidSchema);
}
if (oautil.isReferenceObject(requestBody)) {
return generateTopLevelType(op, { $ref: requestBody.$ref });
Expand All @@ -372,7 +369,7 @@ export function run(options: Options) {
return generateTopLevelType(op, generateContentSchemaType(requestBody.content));
}
return generateTopLevelType(op, {
oneOf: [generateContentSchemaType(requestBody.content), VOID_SCHEMA]
oneOf: [generateContentSchemaType(requestBody.content), voidSchema]
});
}

Expand Down Expand Up @@ -419,7 +416,7 @@ export function run(options: Options) {
}
});
if (responseSchemas.length === 0) {
return generateTopLevelType(op, VOID_SCHEMA);
return generateTopLevelType(op, voidSchema);
}
return generateTopLevelType(op, {
oneOf: responseSchemas
Expand Down

0 comments on commit 5375ca9

Please sign in to comment.