-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_chatgpt_schema_oneof_discriminator.ts
62 lines (60 loc) · 1.39 KB
/
test_chatgpt_schema_oneof_discriminator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { TestValidator } from "@nestia/e2e";
import { IChatGptSchema } from "@samchon/openapi";
import { ChatGptConverter } from "@samchon/openapi/lib/converters/ChatGptConverter";
import typia, { IJsonSchemaCollection } from "typia";
export const test_chatgpt_schema_oneof_discriminator = (): void => {
const collection: IJsonSchemaCollection =
typia.json.schemas<[IPoint | ILine | ITriangle | IRectangle]>();
const schema = ChatGptConverter.schema({
components: collection.components,
schema: collection.schemas[0],
});
TestValidator.equals("discriminator")({
oneOf: [
{
$ref: "#/$defs/IPoint",
},
{
$ref: "#/$defs/ILine",
},
{
$ref: "#/$defs/ITriangle",
},
{
$ref: "#/$defs/IRectangle",
},
],
discriminator: {
propertyName: "type",
mapping: {
point: "#/$defs/IPoint",
line: "#/$defs/ILine",
triangle: "#/$defs/ITriangle",
rectangle: "#/$defs/IRectangle",
},
},
} satisfies IChatGptSchema as IChatGptSchema)(schema as IChatGptSchema);
};
interface IPoint {
type: "point";
x: number;
y: number;
}
interface ILine {
type: "line";
p1: IPoint;
p2: IPoint;
}
interface ITriangle {
type: "triangle";
p1: IPoint;
p2: IPoint;
p3: IPoint;
}
interface IRectangle {
type: "rectangle";
p1: IPoint;
p2: IPoint;
p3: IPoint;
p4: IPoint;
}