Skip to content

Commit

Permalink
Merge pull request #11 from samchon/features/3rd
Browse files Browse the repository at this point in the history
Fix mis-converted property -> `Object.propertes`
  • Loading branch information
samchon authored Apr 15, 2024
2 parents cf36269 + 7a47eda commit 759ced8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 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.13",
"version": "0.1.14",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
Expand Down
13 changes: 8 additions & 5 deletions src/internal/OpenApiV3Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export namespace OpenApiV3Converter {
/* -----------------------------------------------------------
DEFINITIONS
----------------------------------------------------------- */
const convertComponents = (
export const convertComponents = (
input: OpenApiV3.IComponents,
): OpenApi.IComponents => ({
schemas: input.schemas
Expand All @@ -198,7 +198,9 @@ export namespace OpenApiV3Converter {
: undefined,
securitySchemes: input.securitySchemes,
});
const convertSchema = (input: OpenApiV3.IJsonSchema): OpenApi.IJsonSchema => {
export const convertSchema = (
input: OpenApiV3.IJsonSchema,
): OpenApi.IJsonSchema => {
const nullable: { value: boolean } = { value: false };
const union: OpenApi.IJsonSchema[] = [];
const attribute: OpenApi.IJsonSchema.__IAttribute = {
Expand Down Expand Up @@ -243,7 +245,7 @@ export namespace OpenApiV3Converter {
union.push({
...schema,
...{
properites: schema.properties
properties: schema.properties
? Object.fromEntries(
Object.entries(schema.properties)
.filter(([_, v]) => v !== undefined)
Expand Down Expand Up @@ -273,12 +275,13 @@ export namespace OpenApiV3Converter {
? { type: undefined }
: union.length === 1
? { ...union[0] }
: { oneOf: union }),
: { oneOf: union.map((u) => ({ ...u, nullable: undefined })) }),
...attribute,
...{ nullable: undefined },
};
};

namespace TypeChecker {
export namespace TypeChecker {
export const isBoolean = (
schema: OpenApiV3.IJsonSchema,
): schema is OpenApiV3.IJsonSchema.IBoolean =>
Expand Down
3 changes: 2 additions & 1 deletion src/internal/OpenApiV3_1Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,9 @@ export namespace OpenApiV3_1Converter {
? { type: undefined }
: union.length === 1
? { ...union[0] }
: { oneOf: union }),
: { oneOf: union.map((u) => ({ ...u, nullable: undefined })) }),
...attribute,
...{ nullable: undefined },
};
};

Expand Down
6 changes: 4 additions & 2 deletions src/internal/SwaggerV2Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export namespace SwaggerV2Converter {
),
};
const visit = (schema: SwaggerV2.IJsonSchema): void => {
// NULLABLE PROPERTY
if (
(schema as SwaggerV2.IJsonSchema.__ISignificant<any>)["x-nullable"] ===
true
Expand Down Expand Up @@ -289,7 +290,7 @@ export namespace SwaggerV2Converter {
union.push({
...schema,
...{
properites: schema.properties
properties: schema.properties
? Object.fromEntries(
Object.entries(schema.properties)
.filter(([_, v]) => v !== undefined)
Expand Down Expand Up @@ -323,8 +324,9 @@ export namespace SwaggerV2Converter {
? { type: undefined }
: union.length === 1
? { ...union[0] }
: { oneOf: union }),
: { oneOf: union.map((u) => ({ ...u, "x-nullable": undefined })) }),
...attribute,
...{ "x-nullable": undefined },
};
};

Expand Down
1 change: 1 addition & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const main = async (): Promise<void> => {
const document: OpenApi.IDocument = JSON.parse(
await fs.promises.readFile(`${NORMALIZED}/${file}`, "utf8"),
);
if (file === "shopping.json") typia.assertEquals(document);
typia.assert<OpenApi.IDocument>(document);
typia.assert<OpenApiV3_1.IDocument>(document);
}
Expand Down

0 comments on commit 759ced8

Please sign in to comment.