-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from samchon/features/checker
Enhance test program and functions
- Loading branch information
Showing
19 changed files
with
945 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { OpenApi, SwaggerV2 } from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
export const test_document_convert_v20 = async (): Promise<void> => { | ||
const path: string = `${__dirname}/../../../examples/v2.0`; | ||
for (const file of await fs.promises.readdir(path)) { | ||
if (file.endsWith(".json") === false) continue; | ||
const swagger: SwaggerV2.IDocument = typia.assert<SwaggerV2.IDocument>( | ||
JSON.parse(await fs.promises.readFile(`${path}/${file}`, "utf8")), | ||
); | ||
const openapi: OpenApi.IDocument = OpenApi.convert(swagger); | ||
typia.assert(openapi); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { OpenApi, OpenApiV3 } from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
export const test_document_convert_v30 = async (): Promise<void> => { | ||
const path: string = `${__dirname}/../../../examples/v3.0`; | ||
for (const file of await fs.promises.readdir(path)) { | ||
if (file.endsWith(".json") === false) continue; | ||
const swagger: OpenApiV3.IDocument = typia.assert<OpenApiV3.IDocument>( | ||
JSON.parse(await fs.promises.readFile(`${path}/${file}`, "utf8")), | ||
); | ||
const openapi: OpenApi.IDocument = OpenApi.convert(swagger); | ||
typia.assert(openapi); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { OpenApi, OpenApiV3_1 } from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
export const test_document_convert_v31 = async (): Promise<void> => { | ||
const path: string = `${__dirname}/../../../examples/v3.1`; | ||
for (const file of await fs.promises.readdir(path)) { | ||
if (file.endsWith(".json") === false) continue; | ||
const swagger: OpenApiV3_1.IDocument = typia.assert<OpenApiV3_1.IDocument>( | ||
JSON.parse(await fs.promises.readFile(`${path}/${file}`, "utf8")), | ||
); | ||
const openapi: OpenApi.IDocument = OpenApi.convert(swagger); | ||
typia.assert(openapi); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { OpenApi, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
export const test_document_downgrade_v20 = async (): Promise<void> => { | ||
const path: string = `${__dirname}/../../../examples/v3.1`; | ||
for (const directory of await fs.promises.readdir(path)) { | ||
const stats: fs.Stats = await fs.promises.lstat(`${path}/${directory}`); | ||
if (stats.isDirectory() === false) continue; | ||
for (const file of await fs.promises.readdir(`${path}/${directory}`)) { | ||
if (file.endsWith(".json") === false) continue; | ||
const swagger: | ||
| SwaggerV2.IDocument | ||
| OpenApiV3.IDocument | ||
| OpenApiV3_1.IDocument = typia.assert< | ||
SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument | ||
>( | ||
JSON.parse( | ||
await fs.promises.readFile(`${path}/${directory}/${file}`, "utf8"), | ||
), | ||
); | ||
const openapi: OpenApi.IDocument = OpenApi.convert(swagger); | ||
const downgraded: SwaggerV2.IDocument = OpenApi.downgrade(openapi, "2.0"); | ||
typia.assert(downgraded); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { OpenApi, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
export const test_document_downgrade_v30 = async (): Promise<void> => { | ||
const path: string = `${__dirname}/../../../examples/v3.1`; | ||
for (const directory of await fs.promises.readdir(path)) { | ||
const stats: fs.Stats = await fs.promises.lstat(`${path}/${directory}`); | ||
if (stats.isDirectory() === false) continue; | ||
for (const file of await fs.promises.readdir(`${path}/${directory}`)) { | ||
if (file.endsWith(".json") === false) continue; | ||
const swagger: | ||
| SwaggerV2.IDocument | ||
| OpenApiV3.IDocument | ||
| OpenApiV3_1.IDocument = typia.assert< | ||
SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument | ||
>( | ||
JSON.parse( | ||
await fs.promises.readFile(`${path}/${directory}/${file}`, "utf8"), | ||
), | ||
); | ||
const openapi: OpenApi.IDocument = OpenApi.convert(swagger); | ||
const downgraded: OpenApiV3.IDocument = OpenApi.downgrade(openapi, "3.0"); | ||
typia.assert(downgraded); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IMigrateDocument, OpenApi, SwaggerV2 } from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
export const test_document_migrate_v20 = async (): Promise<void> => { | ||
const path: string = `${__dirname}/../../../examples/v2.0`; | ||
for (const file of await fs.promises.readdir(path)) { | ||
if (file.endsWith(".json") === false) continue; | ||
const swagger: SwaggerV2.IDocument = typia.assert<SwaggerV2.IDocument>( | ||
JSON.parse(await fs.promises.readFile(`${path}/${file}`, "utf8")), | ||
); | ||
const openapi: OpenApi.IDocument = OpenApi.convert(swagger); | ||
const migrate: IMigrateDocument = OpenApi.migrate(openapi); | ||
typia.assert(migrate); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IMigrateDocument, OpenApi, OpenApiV3 } from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
export const test_document_migrate_v30 = async (): Promise<void> => { | ||
const path: string = `${__dirname}/../../../examples/v3.0`; | ||
for (const file of await fs.promises.readdir(path)) { | ||
if (file.endsWith(".json") === false) continue; | ||
const swagger: OpenApiV3.IDocument = typia.assert<OpenApiV3.IDocument>( | ||
JSON.parse(await fs.promises.readFile(`${path}/${file}`, "utf8")), | ||
); | ||
const openapi: OpenApi.IDocument = OpenApi.convert(swagger); | ||
const migrate: IMigrateDocument = OpenApi.migrate(openapi); | ||
typia.assert(migrate); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IMigrateDocument, OpenApi, OpenApiV3_1 } from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
export const test_document_migrate_v31 = async (): Promise<void> => { | ||
const path: string = `${__dirname}/../../../examples/v3.1`; | ||
for (const file of await fs.promises.readdir(path)) { | ||
if (file.endsWith(".json") === false) continue; | ||
const swagger: OpenApiV3_1.IDocument = typia.assert<OpenApiV3_1.IDocument>( | ||
JSON.parse(await fs.promises.readFile(`${path}/${file}`, "utf8")), | ||
); | ||
const openapi: OpenApi.IDocument = OpenApi.convert(swagger); | ||
const migrate: IMigrateDocument = OpenApi.migrate(openapi); | ||
typia.assert(migrate); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { TestValidator } from "@nestia/e2e"; | ||
import { OpenApiTypeChecker } from "@samchon/openapi"; | ||
|
||
export const test_json_schema_type_checker_cover_any = (): void => { | ||
TestValidator.equals("any covers (string | null)")(true)( | ||
OpenApiTypeChecker.covers({})( | ||
{ | ||
type: undefined, | ||
}, | ||
{ | ||
oneOf: [ | ||
{ | ||
type: "string", | ||
}, | ||
{ | ||
type: "null", | ||
}, | ||
], | ||
}, | ||
), | ||
); | ||
TestValidator.equals("any covers union type")(true)( | ||
OpenApiTypeChecker.covers({})( | ||
{ | ||
type: undefined, | ||
}, | ||
{ | ||
oneOf: [ | ||
{ | ||
type: "string", | ||
}, | ||
{ | ||
type: "number", | ||
}, | ||
], | ||
}, | ||
), | ||
); | ||
|
||
TestValidator.equals("(string | null) can't cover any")(false)( | ||
OpenApiTypeChecker.covers({})( | ||
{ | ||
oneOf: [ | ||
{ | ||
type: "string", | ||
}, | ||
{ | ||
type: "null", | ||
}, | ||
], | ||
}, | ||
{ | ||
type: undefined, | ||
}, | ||
), | ||
); | ||
TestValidator.equals("union can't cover any")(false)( | ||
OpenApiTypeChecker.covers({})( | ||
{ | ||
oneOf: [ | ||
{ | ||
type: "string", | ||
}, | ||
{ | ||
type: "number", | ||
}, | ||
], | ||
}, | ||
{ | ||
type: undefined, | ||
}, | ||
), | ||
); | ||
}; |
Oops, something went wrong.