diff --git a/lib/spec/openapi/utils.js b/lib/spec/openapi/utils.js index b20200eb..af5ed9ed 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] } @@ -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