Skip to content

Commit

Permalink
Make OpenApi.components.schemas to be optional.
Browse files Browse the repository at this point in the history
It is the regular spec of OpenAPI v3.1.
  • Loading branch information
samchon committed Apr 14, 2024
1 parent 7b8cbc9 commit 76b59e2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export namespace OpenApi {
SCHEMA DEFINITIONS
----------------------------------------------------------- */
export interface IComponents {
schemas: Record<string, IJsonSchema>;
schemas?: Record<string, IJsonSchema>;
securitySchemes?: Record<string, ISecurityScheme>;
}

Expand Down
12 changes: 7 additions & 5 deletions src/internal/OpenApiV3Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
12 changes: 7 additions & 5 deletions src/internal/OpenApiV3_1Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
12 changes: 7 additions & 5 deletions src/internal/SwaggerV2Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 76b59e2

Please sign in to comment.