From 10e3639cd516a09e40f79883326bd05db979fb5f Mon Sep 17 00:00:00 2001 From: sinasab Date: Mon, 18 Sep 2023 14:55:13 -0700 Subject: [PATCH] Fixing failing test --- src/index.ts | 4 ++-- src/utils.ts | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index f4a2e4b..54e505a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -136,7 +136,7 @@ export const swagger = method: route.method, path: route.path, // @ts-ignore - models: app.definitions.type, + models: app.definitions?.type, contentType: route.hooks.type }) }) @@ -161,7 +161,7 @@ export const swagger = ...documentation.components, schemas: { // @ts-ignore - ...app.definitions.type, + ...app.definitions?.type, ...documentation.components?.schemas } } diff --git a/src/utils.ts b/src/utils.ts index 955557c..9e8d4bd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -22,16 +22,18 @@ export const mapProperties = ( if (schema in models) schema = models[schema] else throw new Error(`Can't find model ${schema}`) - return Object.entries(schema?.properties ?? []).map(([key, value]) => ({ - // @ts-ignore - ...value, - in: name, - name: key, - // @ts-ignore - type: value?.type, - // @ts-ignore - required: schema!.required?.includes(key) ?? false - })) + return Object.entries(schema?.properties ?? []).map(([key, value]) => { + const { type: valueType = undefined, ...rest } = value as any; + return { + // @ts-ignore + ...rest, + schema: { type: valueType }, + in: name, + name: key, + // @ts-ignore + required: schema!.required?.includes(key) ?? false, + }; + }); } const mapTypesResponse = ( @@ -118,7 +120,7 @@ export const registerSchemaPath = ({ if (typeof responseSchema === 'object') { if (Kind in responseSchema) { - const { type, properties, required, ...rest } = + const { type, properties, required, additionalProperties, ...rest } = responseSchema as typeof responseSchema & { type: string properties: Object @@ -162,7 +164,7 @@ export const registerSchemaPath = ({ content: mapTypesResponse(contentTypes, value) } } else { - const { type, properties, required, ...rest } = + const { type, properties, required, additionalProperties, ...rest } = value as typeof value & { type: string properties: Object @@ -286,7 +288,7 @@ export const filterPaths = ( .map((x) => ({ in: 'path', name: x.slice(1, x.length - 1), - type: 'string', + schema: { type: "string" }, required: true })), ...schema.parameters