diff --git a/lib/services/mimetype-content-wrapper.ts b/lib/services/mimetype-content-wrapper.ts index 545d0444c..0f5054068 100644 --- a/lib/services/mimetype-content-wrapper.ts +++ b/lib/services/mimetype-content-wrapper.ts @@ -1,12 +1,21 @@ import { ContentObject } from '../interfaces/open-api-spec.interface'; +function removeUndefinedKeys(obj: { [x: string]: any }) { + Object.entries(obj).forEach(([key, value]) => { + if (value === undefined) { + delete obj[key]; + } + }); + return obj; +} + export class MimetypeContentWrapper { wrap( mimetype: string[], obj: Record ): Record<'content', ContentObject> { const content = mimetype.reduce( - (acc, item) => ({ ...acc, [item]: obj }), + (acc, item) => ({ ...acc, [item]: removeUndefinedKeys(obj) }), {} ); return { content }; diff --git a/lib/services/response-object-mapper.ts b/lib/services/response-object-mapper.ts index 72d991f8d..82d0dcc83 100644 --- a/lib/services/response-object-mapper.ts +++ b/lib/services/response-object-mapper.ts @@ -20,7 +20,7 @@ export class ResponseObjectMapper { $ref: getSchemaPath(name) } }, - ...(response.example ? { example: response.example } : {}) + example: response.example }) }; } @@ -32,7 +32,7 @@ export class ResponseObjectMapper { schema: { $ref: getSchemaPath(name) }, - ...(response.example ? { example: response.example } : {}) + example: response.example }) }; } @@ -45,8 +45,8 @@ export class ResponseObjectMapper { return response; } const content = this.mimetypeContentWrapper.wrap(produces, { - ...(response.schema ? { schema: response.schema } : {}), - ...(response.example ? { example: response.example } : {}) + schema: response.schema, + example: response.example }); return { ...omit(response, ['schema', 'example']),