-
-
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 #52 from samchon/feature/schema
Exact JSON schema downgrading.
- Loading branch information
Showing
10 changed files
with
283 additions
and
14 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
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,54 @@ | ||
import { TestValidator } from "@nestia/e2e"; | ||
import { HttpLlm, ILlmSchema, OpenApi } from "@samchon/openapi"; | ||
|
||
export const test_llm_schema_union = (): void => { | ||
const components: OpenApi.IComponents = { | ||
schemas: { | ||
union1: { | ||
oneOf: [ | ||
{ | ||
type: "string", | ||
}, | ||
{ | ||
type: "number", | ||
}, | ||
{ | ||
$ref: "#/components/schemas/union2", | ||
}, | ||
], | ||
}, | ||
union2: { | ||
oneOf: [ | ||
{ | ||
type: "boolean", | ||
}, | ||
{ | ||
type: "null", | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
const schema: OpenApi.IJsonSchema = { | ||
oneOf: [ | ||
{ | ||
type: "boolean", | ||
}, | ||
{ | ||
$ref: "#/components/schemas/union1", | ||
}, | ||
], | ||
}; | ||
const llm: ILlmSchema | null = HttpLlm.schema({ | ||
components, | ||
schema, | ||
}); | ||
TestValidator.equals("nullable")(llm)({ | ||
oneOf: [ | ||
{ type: "boolean", nullable: true }, | ||
{ type: "string", nullable: true }, | ||
{ type: "number", nullable: true }, | ||
{ type: "boolean", nullable: true }, | ||
], | ||
}); | ||
}; |
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,38 @@ | ||
import { TestValidator } from "@nestia/e2e"; | ||
import { HttpLlm, ILlmSchema, OpenApi } from "@samchon/openapi"; | ||
|
||
export const test_llm_schema_union = (): void => { | ||
const components: OpenApi.IComponents = { | ||
schemas: { | ||
named: { | ||
oneOf: [ | ||
{ | ||
const: 4, | ||
}, | ||
{ | ||
const: 5, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
const schema: OpenApi.IJsonSchema = { | ||
oneOf: [ | ||
{ | ||
const: 3, | ||
}, | ||
{ | ||
$ref: "#/components/schemas/named", | ||
}, | ||
], | ||
}; | ||
|
||
const llm: ILlmSchema | null = HttpLlm.schema({ | ||
components, | ||
schema, | ||
}); | ||
TestValidator.equals("union")(llm)({ | ||
type: "number", | ||
enum: [3, 4, 5], | ||
}); | ||
}; |
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
67 changes: 67 additions & 0 deletions
67
test/features/openapi/test_json_schema_downgrade_v20_nullable.ts
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,67 @@ | ||
import { TestValidator } from "@nestia/e2e"; | ||
import { OpenApi, SwaggerV2 } from "@samchon/openapi"; | ||
import { SwaggerV2Downgrader } from "@samchon/openapi/lib/converters/SwaggerV2Downgrader"; | ||
|
||
export const test_json_schema_downgrade_v20_nullable = (): void => { | ||
const original: OpenApi.IComponents = { | ||
schemas: { | ||
union: { | ||
oneOf: [ | ||
{ | ||
type: "null", | ||
}, | ||
{ | ||
type: "string", | ||
}, | ||
{ | ||
type: "number", | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
const components: Record<string, SwaggerV2.IJsonSchema> = {}; | ||
const schema: SwaggerV2.IJsonSchema = SwaggerV2Downgrader.downgradeSchema({ | ||
original, | ||
downgraded: components, | ||
})({ | ||
oneOf: [ | ||
{ | ||
type: "boolean", | ||
}, | ||
{ | ||
$ref: "#/components/schemas/union", | ||
}, | ||
], | ||
} satisfies OpenApi.IJsonSchema); | ||
TestValidator.equals("nullable")({ | ||
components, | ||
schema, | ||
})({ | ||
components: { | ||
"union.Nullable": { | ||
"x-oneOf": [ | ||
{ | ||
type: "string", | ||
"x-nullable": true, | ||
}, | ||
{ | ||
type: "number", | ||
"x-nullable": true, | ||
}, | ||
], | ||
}, | ||
}, | ||
schema: { | ||
"x-oneOf": [ | ||
{ | ||
type: "boolean", | ||
"x-nullable": true, | ||
}, | ||
{ | ||
$ref: "#/definitions/union.Nullable", | ||
}, | ||
], | ||
}, | ||
}); | ||
}; |
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
71 changes: 71 additions & 0 deletions
71
test/features/openapi/test_json_schema_downgrade_v30_nullable.ts
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,71 @@ | ||
import { TestValidator } from "@nestia/e2e"; | ||
import { OpenApi, OpenApiV3 } from "@samchon/openapi"; | ||
import { OpenApiV3Downgrader } from "@samchon/openapi/lib/converters/OpenApiV3Downgrader"; | ||
|
||
export const test_json_schema_downgrade_v30_nullable = (): void => { | ||
const original: OpenApi.IComponents = { | ||
schemas: { | ||
union: { | ||
oneOf: [ | ||
{ | ||
type: "null", | ||
}, | ||
{ | ||
type: "string", | ||
}, | ||
{ | ||
type: "number", | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
const components: OpenApiV3.IComponents = { | ||
schemas: {}, | ||
}; | ||
const schema: OpenApiV3.IJsonSchema = OpenApiV3Downgrader.downgradeSchema({ | ||
original, | ||
downgraded: components, | ||
})({ | ||
oneOf: [ | ||
{ | ||
type: "boolean", | ||
}, | ||
{ | ||
$ref: "#/components/schemas/union", | ||
}, | ||
], | ||
} satisfies OpenApi.IJsonSchema); | ||
TestValidator.equals("nullable")({ | ||
components, | ||
schema, | ||
})({ | ||
components: { | ||
schemas: { | ||
"union.Nullable": { | ||
oneOf: [ | ||
{ | ||
type: "string", | ||
nullable: true, | ||
}, | ||
{ | ||
type: "number", | ||
nullable: true, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
schema: { | ||
oneOf: [ | ||
{ | ||
type: "boolean", | ||
nullable: true, | ||
}, | ||
{ | ||
$ref: "#/components/schemas/union.Nullable", | ||
}, | ||
], | ||
}, | ||
}); | ||
}; |