From 322e194b2ffcc2c105ed54b5915081806c3536de Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 6 Feb 2022 12:32:30 +0100 Subject: [PATCH] fix(serverless-openapi): handle optional response correctly --- packages/serverless-openapi/src/lib/generator.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/serverless-openapi/src/lib/generator.ts b/packages/serverless-openapi/src/lib/generator.ts index ab574be..2eaade5 100644 --- a/packages/serverless-openapi/src/lib/generator.ts +++ b/packages/serverless-openapi/src/lib/generator.ts @@ -212,11 +212,17 @@ export class Generator { } private handleResponses( - responseSchemas: { [key: string]: { 'application/json': Schema } }, + responseSchemas: + | { [key: string]: { 'application/json': Schema } } + | undefined, openApi: OpenAPIV3.Document - ): OpenAPIV3.ResponsesObject { + ): OpenAPIV3.ResponsesObject | undefined { const responses: OpenAPIV3.ResponsesObject = {}; + if (!responseSchemas) { + return undefined; + } + for (const code of Object.keys(responseSchemas)) { const schemaJSON = responseSchemas[code]['application/json']; responses[code] = {