From 76b59e2976f2a05274da5c7bc5ac582abb290381 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Sun, 14 Apr 2024 20:42:20 +0900 Subject: [PATCH] Make `OpenApi.components.schemas` to be optional. It is the regular spec of OpenAPI v3.1. --- package.json | 2 +- src/OpenApi.ts | 2 +- src/internal/OpenApiV3Converter.ts | 12 +++++++----- src/internal/OpenApiV3_1Converter.ts | 12 +++++++----- src/internal/SwaggerV2Converter.ts | 12 +++++++----- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 1ab36a8..8066a8d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@samchon/openapi", - "version": "0.1.8", + "version": "0.1.9", "description": "OpenAPI definitions and converters for 'typia' and 'nestia'.", "main": "./lib/index.js", "typings": "./lib/index.d.ts", diff --git a/src/OpenApi.ts b/src/OpenApi.ts index fbc7f86..f11f5c8 100644 --- a/src/OpenApi.ts +++ b/src/OpenApi.ts @@ -173,7 +173,7 @@ export namespace OpenApi { SCHEMA DEFINITIONS ----------------------------------------------------------- */ export interface IComponents { - schemas: Record; + schemas?: Record; securitySchemes?: Record; } diff --git a/src/internal/OpenApiV3Converter.ts b/src/internal/OpenApiV3Converter.ts index 7d43e28..e9dc017 100644 --- a/src/internal/OpenApiV3Converter.ts +++ b/src/internal/OpenApiV3Converter.ts @@ -185,11 +185,13 @@ export namespace OpenApiV3Converter { const convertComponents = ( input: OpenApiV3.IComponents, ): OpenApi.IComponents => ({ - schemas: Object.fromEntries( - Object.entries(input.schemas ?? {}) - .filter(([_, v]) => v !== undefined) - .map(([key, value]) => [key, convertSchema(value)]), - ), + schemas: input.schemas + ? Object.fromEntries( + Object.entries(input.schemas) + .filter(([_, v]) => v !== undefined) + .map(([key, value]) => [key, convertSchema(value)]), + ) + : undefined, securitySchemes: input.securitySchemes, }); const convertSchema = (input: OpenApiV3.IJsonSchema): OpenApi.IJsonSchema => { diff --git a/src/internal/OpenApiV3_1Converter.ts b/src/internal/OpenApiV3_1Converter.ts index cea73d9..b065972 100644 --- a/src/internal/OpenApiV3_1Converter.ts +++ b/src/internal/OpenApiV3_1Converter.ts @@ -209,11 +209,13 @@ export namespace OpenApiV3_1Converter { const convertComponents = ( input: OpenApiV3_1.IComponents, ): OpenApi.IComponents => ({ - schemas: Object.fromEntries( - Object.entries(input.schemas ?? {}) - .filter(([_, v]) => v !== undefined) - .map(([key, value]) => [key, convertSchema(value)] as const), - ), + schemas: input.schemas + ? Object.fromEntries( + Object.entries(input.schemas) + .filter(([_, v]) => v !== undefined) + .map(([key, value]) => [key, convertSchema(value)] as const), + ) + : undefined, securitySchemes: input.securitySchemes, }); const convertSchema = ( diff --git a/src/internal/SwaggerV2Converter.ts b/src/internal/SwaggerV2Converter.ts index 5de87c5..12543b4 100644 --- a/src/internal/SwaggerV2Converter.ts +++ b/src/internal/SwaggerV2Converter.ts @@ -165,11 +165,13 @@ export namespace SwaggerV2Converter { const convertComponents = ( input: SwaggerV2.IDocument, ): OpenApi.IComponents => ({ - schemas: Object.fromEntries( - Object.entries(input.definitions ?? {}) - .filter(([_, v]) => v !== undefined) - .map(([key, value]) => [key, convertSchema(value)]), - ), + schemas: input.definitions + ? Object.fromEntries( + Object.entries(input.definitions) + .filter(([_, v]) => v !== undefined) + .map(([key, value]) => [key, convertSchema(value)]), + ) + : undefined, securitySchemes: input.securityDefinitions ? Object.fromEntries( Object.entries(input.securityDefinitions)