From 13062267a4b73e3ce449a5062246c7dc30297f9a Mon Sep 17 00:00:00 2001 From: Makrand Gupta <9060170+makrandgupta@users.noreply.github.com> Date: Mon, 23 Jun 2025 23:38:46 -0400 Subject: [PATCH 1/2] Safely access schema to prevent crashes Signed-off-by: Makrand Gupta <9060170+makrandgupta@users.noreply.github.com> --- lib/spec/openapi/utils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/spec/openapi/utils.js b/lib/spec/openapi/utils.js index b20200eb..d90c107f 100644 --- a/lib/spec/openapi/utils.js +++ b/lib/spec/openapi/utils.js @@ -182,7 +182,7 @@ function plainJsonObjectToOpenapi3 (container, jsonSchema, externalSchemas, secu } // description should be optional - if (jsonSchemaElement.description) result.description = jsonSchemaElement.description + if (jsonSchemaElement?.description) result.description = jsonSchemaElement.description return result } break @@ -239,16 +239,16 @@ function resolveSchemaExamplesRecursive (schema) { function schemaToMedia (schema) { const media = { schema } - if (schema.examples?.length === 1) { + if (schema?.examples?.length === 1) { media.example = schema.examples[0] delete schema.examples - } else if (schema.examples?.length > 1) { + } else if (schema?.examples?.length > 1) { media.examples = convertExamplesArrayToObject(schema.examples) // examples is invalid property of media object schema delete schema.examples } - if (schema[xExamples]) { + if (schema && schema[xExamples]) { media.examples = schema[xExamples] delete schema[xExamples] } From 16fe863bcaea7539a9a213cbd0baac4354c0d539 Mon Sep 17 00:00:00 2001 From: Makrand Gupta <9060170+makrandgupta@users.noreply.github.com> Date: Tue, 24 Jun 2025 00:15:45 -0400 Subject: [PATCH 2/2] Add fallback for security scheme Signed-off-by: Makrand Gupta <9060170+makrandgupta@users.noreply.github.com> --- lib/spec/openapi/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spec/openapi/utils.js b/lib/spec/openapi/utils.js index d90c107f..af5ed9ed 100644 --- a/lib/spec/openapi/utils.js +++ b/lib/spec/openapi/utils.js @@ -451,7 +451,7 @@ function prepareOpenapiMethod (schema, ref, openapiObject, url) { ] .reduce((acc, securitySchemeGroup) => { Object.keys(securitySchemeGroup).forEach((securitySchemeLabel) => { - const scheme = openapiObject.components.securitySchemes[securitySchemeLabel] + const scheme = openapiObject.components.securitySchemes[securitySchemeLabel] ?? {} const isBearer = scheme.type === 'http' && scheme.scheme === 'bearer' const category = isBearer ? 'header' : scheme.in const name = isBearer ? 'authorization' : scheme.name