typia 9.7.2 → 10.0.0-dev.20251107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +153 -153
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.mjs +1 -1
- package/lib/programmers/internal/json_schema_station.d.mts +2 -2
- package/lib/programmers/internal/json_schema_station.d.ts +2 -2
- package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
- package/package.json +121 -121
- package/src/AssertionGuard.ts +41 -41
- package/src/CamelCase.ts +75 -75
- package/src/IRandomGenerator.ts +337 -337
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +90 -90
- package/src/Resolved.ts +72 -72
- package/src/SnakeCase.ts +127 -127
- package/src/TypeGuardError.ts +216 -216
- package/src/factories/MetadataCollection.ts +270 -270
- package/src/factories/MetadataCommentTagFactory.ts +632 -632
- package/src/factories/MetadataFactory.ts +402 -402
- package/src/factories/ProtobufFactory.ts +873 -873
- package/src/functional.ts +705 -705
- package/src/http.ts +972 -972
- package/src/internal/_ProtobufReader.ts +188 -188
- package/src/internal/_ProtobufSizer.ts +137 -137
- package/src/internal/_ProtobufWriter.ts +135 -135
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/json.ts +643 -643
- package/src/llm.ts +615 -615
- package/src/misc.ts +594 -594
- package/src/module.ts +889 -889
- package/src/notations.ts +751 -751
- package/src/programmers/FeatureProgrammer.ts +605 -605
- package/src/programmers/ImportProgrammer.ts +179 -179
- package/src/programmers/RandomProgrammer.ts +1195 -1195
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/internal/check_array_length.ts +43 -43
- package/src/programmers/internal/check_bigint.ts +46 -46
- package/src/programmers/internal/check_dynamic_key.ts +197 -197
- package/src/programmers/internal/check_dynamic_properties.ts +231 -231
- package/src/programmers/internal/check_everything.ts +21 -21
- package/src/programmers/internal/check_native.ts +23 -23
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_object.ts +72 -72
- package/src/programmers/internal/check_string.ts +46 -46
- package/src/programmers/internal/check_template.ts +46 -46
- package/src/programmers/internal/check_union_array_like.ts +331 -331
- package/src/programmers/internal/decode_union_object.ts +110 -110
- package/src/programmers/internal/feature_object_entries.ts +59 -59
- package/src/programmers/internal/json_schema_escaped.ts +78 -78
- package/src/programmers/internal/json_schema_object.ts +150 -150
- package/src/programmers/internal/json_schema_station.ts +2 -2
- package/src/programmers/internal/metadata_to_pattern.ts +40 -40
- package/src/programmers/internal/postfix_of_tuple.ts +3 -3
- package/src/programmers/internal/prune_object_properties.ts +69 -69
- package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
- package/src/programmers/internal/stringify_native.ts +5 -5
- package/src/programmers/internal/stringify_regular_properties.ts +77 -77
- package/src/programmers/internal/template_to_pattern.ts +21 -21
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
- package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
- package/src/protobuf.ts +820 -820
- package/src/reflect.ts +46 -46
- package/src/schemas/json/IJsonApplication.ts +77 -77
- package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
- package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
- package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
- package/src/schemas/metadata/Metadata.ts +669 -669
- package/src/schemas/metadata/MetadataAliasType.ts +57 -57
- package/src/schemas/metadata/MetadataApplication.ts +40 -40
- package/src/schemas/metadata/MetadataArray.ts +47 -47
- package/src/schemas/metadata/MetadataArrayType.ts +51 -51
- package/src/schemas/metadata/MetadataAtomic.ts +85 -85
- package/src/schemas/metadata/MetadataEscaped.ts +45 -45
- package/src/schemas/metadata/MetadataFunction.ts +45 -45
- package/src/schemas/metadata/MetadataObject.ts +46 -46
- package/src/schemas/metadata/MetadataObjectType.ts +137 -137
- package/src/schemas/metadata/MetadataParameter.ts +52 -52
- package/src/schemas/metadata/MetadataProperty.ts +53 -53
- package/src/schemas/metadata/MetadataTemplate.ts +78 -78
- package/src/schemas/metadata/MetadataTuple.ts +28 -28
- package/src/schemas/metadata/MetadataTupleType.ts +61 -61
- package/src/tags/Constant.ts +47 -47
- package/src/tags/ContentMediaType.ts +27 -27
- package/src/tags/Default.ts +52 -52
- package/src/tags/Example.ts +56 -56
- package/src/tags/Examples.ts +56 -56
- package/src/tags/ExclusiveMaximum.ts +44 -44
- package/src/tags/ExclusiveMinimum.ts +44 -44
- package/src/tags/Format.ts +78 -78
- package/src/tags/JsonSchemaPlugin.ts +36 -36
- package/src/tags/MaxItems.ts +31 -31
- package/src/tags/MaxLength.ts +25 -25
- package/src/tags/Maximum.ts +39 -39
- package/src/tags/MinItems.ts +31 -31
- package/src/tags/MinLength.ts +25 -25
- package/src/tags/Minimum.ts +39 -39
- package/src/tags/MultipleOf.ts +42 -42
- package/src/tags/Pattern.ts +49 -49
- package/src/tags/Sequence.ts +37 -37
- package/src/tags/TagBase.ts +102 -102
- package/src/tags/Type.ts +64 -64
- package/src/tags/UniqueItems.ts +34 -34
- package/src/tags/internal/FormatCheatSheet.ts +71 -71
- package/src/transformers/ITransformOptions.ts +70 -70
- package/src/transformers/ImportTransformer.ts +253 -253
- package/src/transformers/NoTransformConfigurationError.ts +16 -16
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
- package/src/typings/Equal.ts +18 -18
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
4
|
-
|
|
5
|
-
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
6
|
-
|
|
7
|
-
/** @internal */
|
|
8
|
-
export const decode_union_object = (props: {
|
|
9
|
-
checker: (next: {
|
|
10
|
-
input: ts.Expression;
|
|
11
|
-
object: MetadataObjectType;
|
|
12
|
-
explore: FeatureProgrammer.IExplore;
|
|
13
|
-
}) => ts.Expression;
|
|
14
|
-
decoder: (next: {
|
|
15
|
-
input: ts.Expression;
|
|
16
|
-
object: MetadataObjectType;
|
|
17
|
-
explore: FeatureProgrammer.IExplore;
|
|
18
|
-
}) => ts.Expression;
|
|
19
|
-
success: (exp: ts.Expression) => ts.Expression;
|
|
20
|
-
escaper: (next: { input: ts.Expression; expected: string }) => ts.Statement;
|
|
21
|
-
objects: MetadataObjectType[];
|
|
22
|
-
input: ts.Expression;
|
|
23
|
-
explore: FeatureProgrammer.IExplore;
|
|
24
|
-
}): ts.CallExpression =>
|
|
25
|
-
ts.factory.createCallExpression(
|
|
26
|
-
ts.factory.createArrowFunction(
|
|
27
|
-
undefined,
|
|
28
|
-
undefined,
|
|
29
|
-
[],
|
|
30
|
-
undefined,
|
|
31
|
-
undefined,
|
|
32
|
-
iterate({
|
|
33
|
-
escaper: props.escaper,
|
|
34
|
-
input: props.input,
|
|
35
|
-
unions: props.objects.map((object) => ({
|
|
36
|
-
type: "object",
|
|
37
|
-
is: () =>
|
|
38
|
-
props.success(
|
|
39
|
-
props.checker({
|
|
40
|
-
input: props.input,
|
|
41
|
-
explore: props.explore,
|
|
42
|
-
object,
|
|
43
|
-
}),
|
|
44
|
-
),
|
|
45
|
-
value: () =>
|
|
46
|
-
props.decoder({
|
|
47
|
-
input: props.input,
|
|
48
|
-
explore: props.explore,
|
|
49
|
-
object,
|
|
50
|
-
}),
|
|
51
|
-
})),
|
|
52
|
-
expected: `(${props.objects.map((t) => t.name).join(" | ")})`,
|
|
53
|
-
}),
|
|
54
|
-
),
|
|
55
|
-
undefined,
|
|
56
|
-
undefined,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
/** @internal */
|
|
60
|
-
const iterate = (props: {
|
|
61
|
-
escaper: (next: { input: ts.Expression; expected: string }) => ts.Statement;
|
|
62
|
-
unions: IUnion[];
|
|
63
|
-
expected: string;
|
|
64
|
-
input: ts.Expression;
|
|
65
|
-
}) => {
|
|
66
|
-
interface IBranch {
|
|
67
|
-
condition: null | ts.Expression;
|
|
68
|
-
value: ts.Expression;
|
|
69
|
-
}
|
|
70
|
-
const branches: IBranch[] = [];
|
|
71
|
-
|
|
72
|
-
for (const u of props.unions) {
|
|
73
|
-
const condition: ts.Expression = u.is();
|
|
74
|
-
if (condition.kind === ts.SyntaxKind.TrueKeyword) {
|
|
75
|
-
branches.push({
|
|
76
|
-
condition: null,
|
|
77
|
-
value: u.value(),
|
|
78
|
-
});
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
branches.push({
|
|
82
|
-
condition,
|
|
83
|
-
value: u.value(),
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
if (branches.length === 0)
|
|
87
|
-
return ts.factory.createBlock([props.escaper(props)], true);
|
|
88
|
-
else if (branches.length === 1 && branches[0]!.condition === null)
|
|
89
|
-
return branches[0]!.value;
|
|
90
|
-
|
|
91
|
-
const statements: ts.Statement[] = branches.map((b) =>
|
|
92
|
-
b.condition !== null
|
|
93
|
-
? ts.factory.createIfStatement(
|
|
94
|
-
b.condition,
|
|
95
|
-
ts.factory.createReturnStatement(b.value),
|
|
96
|
-
undefined,
|
|
97
|
-
)
|
|
98
|
-
: ts.factory.createReturnStatement(b.value),
|
|
99
|
-
);
|
|
100
|
-
if (branches.at(-1)!.condition !== null)
|
|
101
|
-
statements.push(props.escaper(props));
|
|
102
|
-
return ts.factory.createBlock(statements, true);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/** @internal */
|
|
106
|
-
interface IUnion {
|
|
107
|
-
type: string;
|
|
108
|
-
is: () => ts.Expression;
|
|
109
|
-
value: () => ts.Expression;
|
|
110
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
4
|
+
|
|
5
|
+
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const decode_union_object = (props: {
|
|
9
|
+
checker: (next: {
|
|
10
|
+
input: ts.Expression;
|
|
11
|
+
object: MetadataObjectType;
|
|
12
|
+
explore: FeatureProgrammer.IExplore;
|
|
13
|
+
}) => ts.Expression;
|
|
14
|
+
decoder: (next: {
|
|
15
|
+
input: ts.Expression;
|
|
16
|
+
object: MetadataObjectType;
|
|
17
|
+
explore: FeatureProgrammer.IExplore;
|
|
18
|
+
}) => ts.Expression;
|
|
19
|
+
success: (exp: ts.Expression) => ts.Expression;
|
|
20
|
+
escaper: (next: { input: ts.Expression; expected: string }) => ts.Statement;
|
|
21
|
+
objects: MetadataObjectType[];
|
|
22
|
+
input: ts.Expression;
|
|
23
|
+
explore: FeatureProgrammer.IExplore;
|
|
24
|
+
}): ts.CallExpression =>
|
|
25
|
+
ts.factory.createCallExpression(
|
|
26
|
+
ts.factory.createArrowFunction(
|
|
27
|
+
undefined,
|
|
28
|
+
undefined,
|
|
29
|
+
[],
|
|
30
|
+
undefined,
|
|
31
|
+
undefined,
|
|
32
|
+
iterate({
|
|
33
|
+
escaper: props.escaper,
|
|
34
|
+
input: props.input,
|
|
35
|
+
unions: props.objects.map((object) => ({
|
|
36
|
+
type: "object",
|
|
37
|
+
is: () =>
|
|
38
|
+
props.success(
|
|
39
|
+
props.checker({
|
|
40
|
+
input: props.input,
|
|
41
|
+
explore: props.explore,
|
|
42
|
+
object,
|
|
43
|
+
}),
|
|
44
|
+
),
|
|
45
|
+
value: () =>
|
|
46
|
+
props.decoder({
|
|
47
|
+
input: props.input,
|
|
48
|
+
explore: props.explore,
|
|
49
|
+
object,
|
|
50
|
+
}),
|
|
51
|
+
})),
|
|
52
|
+
expected: `(${props.objects.map((t) => t.name).join(" | ")})`,
|
|
53
|
+
}),
|
|
54
|
+
),
|
|
55
|
+
undefined,
|
|
56
|
+
undefined,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/** @internal */
|
|
60
|
+
const iterate = (props: {
|
|
61
|
+
escaper: (next: { input: ts.Expression; expected: string }) => ts.Statement;
|
|
62
|
+
unions: IUnion[];
|
|
63
|
+
expected: string;
|
|
64
|
+
input: ts.Expression;
|
|
65
|
+
}) => {
|
|
66
|
+
interface IBranch {
|
|
67
|
+
condition: null | ts.Expression;
|
|
68
|
+
value: ts.Expression;
|
|
69
|
+
}
|
|
70
|
+
const branches: IBranch[] = [];
|
|
71
|
+
|
|
72
|
+
for (const u of props.unions) {
|
|
73
|
+
const condition: ts.Expression = u.is();
|
|
74
|
+
if (condition.kind === ts.SyntaxKind.TrueKeyword) {
|
|
75
|
+
branches.push({
|
|
76
|
+
condition: null,
|
|
77
|
+
value: u.value(),
|
|
78
|
+
});
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
branches.push({
|
|
82
|
+
condition,
|
|
83
|
+
value: u.value(),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (branches.length === 0)
|
|
87
|
+
return ts.factory.createBlock([props.escaper(props)], true);
|
|
88
|
+
else if (branches.length === 1 && branches[0]!.condition === null)
|
|
89
|
+
return branches[0]!.value;
|
|
90
|
+
|
|
91
|
+
const statements: ts.Statement[] = branches.map((b) =>
|
|
92
|
+
b.condition !== null
|
|
93
|
+
? ts.factory.createIfStatement(
|
|
94
|
+
b.condition,
|
|
95
|
+
ts.factory.createReturnStatement(b.value),
|
|
96
|
+
undefined,
|
|
97
|
+
)
|
|
98
|
+
: ts.factory.createReturnStatement(b.value),
|
|
99
|
+
);
|
|
100
|
+
if (branches.at(-1)!.condition !== null)
|
|
101
|
+
statements.push(props.escaper(props));
|
|
102
|
+
return ts.factory.createBlock(statements, true);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** @internal */
|
|
106
|
+
interface IUnion {
|
|
107
|
+
type: string;
|
|
108
|
+
is: () => ts.Expression;
|
|
109
|
+
value: () => ts.Expression;
|
|
110
|
+
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
6
|
-
|
|
7
|
-
import { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
8
|
-
|
|
9
|
-
import { Escaper } from "../../utils/Escaper";
|
|
10
|
-
|
|
11
|
-
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
12
|
-
|
|
13
|
-
/** @internal */
|
|
14
|
-
export const feature_object_entries = <Output extends ts.ConciseBody>(props: {
|
|
15
|
-
config: Pick<FeatureProgrammer.IConfig<Output>, "decoder" | "path" | "trace">;
|
|
16
|
-
context: ITypiaContext;
|
|
17
|
-
object: MetadataObjectType;
|
|
18
|
-
input: ts.Expression;
|
|
19
|
-
from?: "object" | "top" | "array";
|
|
20
|
-
}) =>
|
|
21
|
-
props.object.properties.map((next) => {
|
|
22
|
-
const sole: string | null = next.key.getSoleLiteral();
|
|
23
|
-
const propInput =
|
|
24
|
-
sole === null
|
|
25
|
-
? ts.factory.createIdentifier("value")
|
|
26
|
-
: Escaper.variable(sole)
|
|
27
|
-
? ts.factory.createPropertyAccessExpression(
|
|
28
|
-
props.input,
|
|
29
|
-
ts.factory.createIdentifier(sole),
|
|
30
|
-
)
|
|
31
|
-
: ts.factory.createElementAccessExpression(
|
|
32
|
-
props.input,
|
|
33
|
-
ts.factory.createStringLiteral(sole),
|
|
34
|
-
);
|
|
35
|
-
return {
|
|
36
|
-
input: propInput,
|
|
37
|
-
key: next.key,
|
|
38
|
-
meta: next.value,
|
|
39
|
-
expression: props.config.decoder({
|
|
40
|
-
input: propInput,
|
|
41
|
-
metadata: next.value,
|
|
42
|
-
explore: {
|
|
43
|
-
tracable: props.config.path || props.config.trace,
|
|
44
|
-
source: "function",
|
|
45
|
-
from: props.from ?? "object",
|
|
46
|
-
postfix: props.config.trace
|
|
47
|
-
? sole !== null
|
|
48
|
-
? IdentifierFactory.postfix(sole)
|
|
49
|
-
: (() => {
|
|
50
|
-
props.context.importer.internal(ACCESSOR);
|
|
51
|
-
return `${props.context.importer.getInternalText(ACCESSOR)}(key)`;
|
|
52
|
-
})()
|
|
53
|
-
: "",
|
|
54
|
-
},
|
|
55
|
-
}),
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const ACCESSOR = "accessExpressionAsString";
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
6
|
+
|
|
7
|
+
import { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
8
|
+
|
|
9
|
+
import { Escaper } from "../../utils/Escaper";
|
|
10
|
+
|
|
11
|
+
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
export const feature_object_entries = <Output extends ts.ConciseBody>(props: {
|
|
15
|
+
config: Pick<FeatureProgrammer.IConfig<Output>, "decoder" | "path" | "trace">;
|
|
16
|
+
context: ITypiaContext;
|
|
17
|
+
object: MetadataObjectType;
|
|
18
|
+
input: ts.Expression;
|
|
19
|
+
from?: "object" | "top" | "array";
|
|
20
|
+
}) =>
|
|
21
|
+
props.object.properties.map((next) => {
|
|
22
|
+
const sole: string | null = next.key.getSoleLiteral();
|
|
23
|
+
const propInput =
|
|
24
|
+
sole === null
|
|
25
|
+
? ts.factory.createIdentifier("value")
|
|
26
|
+
: Escaper.variable(sole)
|
|
27
|
+
? ts.factory.createPropertyAccessExpression(
|
|
28
|
+
props.input,
|
|
29
|
+
ts.factory.createIdentifier(sole),
|
|
30
|
+
)
|
|
31
|
+
: ts.factory.createElementAccessExpression(
|
|
32
|
+
props.input,
|
|
33
|
+
ts.factory.createStringLiteral(sole),
|
|
34
|
+
);
|
|
35
|
+
return {
|
|
36
|
+
input: propInput,
|
|
37
|
+
key: next.key,
|
|
38
|
+
meta: next.value,
|
|
39
|
+
expression: props.config.decoder({
|
|
40
|
+
input: propInput,
|
|
41
|
+
metadata: next.value,
|
|
42
|
+
explore: {
|
|
43
|
+
tracable: props.config.path || props.config.trace,
|
|
44
|
+
source: "function",
|
|
45
|
+
from: props.from ?? "object",
|
|
46
|
+
postfix: props.config.trace
|
|
47
|
+
? sole !== null
|
|
48
|
+
? IdentifierFactory.postfix(sole)
|
|
49
|
+
: (() => {
|
|
50
|
+
props.context.importer.internal(ACCESSOR);
|
|
51
|
+
return `${props.context.importer.getInternalText(ACCESSOR)}(key)`;
|
|
52
|
+
})()
|
|
53
|
+
: "",
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const ACCESSOR = "accessExpressionAsString";
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { OpenApi, OpenApiTypeChecker } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
-
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
5
|
-
|
|
6
|
-
import { json_schema_station } from "./json_schema_station";
|
|
7
|
-
|
|
8
|
-
/** @internal */
|
|
9
|
-
export const json_schema_escaped = (props: {
|
|
10
|
-
components: OpenApi.IComponents;
|
|
11
|
-
escaped: MetadataEscaped;
|
|
12
|
-
}): OpenApi.IJsonSchema[] => {
|
|
13
|
-
const output: OpenApi.IJsonSchema | null = json_schema_station({
|
|
14
|
-
blockNever: false,
|
|
15
|
-
components: props.components,
|
|
16
|
-
metadata: props.escaped.returns,
|
|
17
|
-
attribute: {},
|
|
18
|
-
});
|
|
19
|
-
if (output === null) return [];
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
is_date({
|
|
23
|
-
visited: new Set(),
|
|
24
|
-
metadata: props.escaped.original,
|
|
25
|
-
})
|
|
26
|
-
) {
|
|
27
|
-
const string: OpenApi.IJsonSchema.IString | undefined =
|
|
28
|
-
OpenApiTypeChecker.isString(output)
|
|
29
|
-
? output
|
|
30
|
-
: OpenApiTypeChecker.isOneOf(output)
|
|
31
|
-
? (output.oneOf.find(
|
|
32
|
-
OpenApiTypeChecker.isString,
|
|
33
|
-
) as OpenApi.IJsonSchema.IString)
|
|
34
|
-
: undefined;
|
|
35
|
-
if (
|
|
36
|
-
string !== undefined &&
|
|
37
|
-
string.format !== "date" &&
|
|
38
|
-
string.format !== "date-time"
|
|
39
|
-
)
|
|
40
|
-
string.format = "date-time";
|
|
41
|
-
}
|
|
42
|
-
return OpenApiTypeChecker.isOneOf(output)
|
|
43
|
-
? (output.oneOf as OpenApi.IJsonSchema[])
|
|
44
|
-
: [output];
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/** @internal */
|
|
48
|
-
const is_date = (props: {
|
|
49
|
-
visited: Set<Metadata>;
|
|
50
|
-
metadata: Metadata;
|
|
51
|
-
}): boolean => {
|
|
52
|
-
if (props.visited.has(props.metadata)) return false;
|
|
53
|
-
props.visited.add(props.metadata);
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
props.metadata.natives.some((native) => native.name === "Date") ||
|
|
57
|
-
props.metadata.arrays.some((array) =>
|
|
58
|
-
is_date({
|
|
59
|
-
visited: props.visited,
|
|
60
|
-
metadata: array.type.value,
|
|
61
|
-
}),
|
|
62
|
-
) ||
|
|
63
|
-
props.metadata.tuples.some((tuple) =>
|
|
64
|
-
tuple.type.elements.some((e) =>
|
|
65
|
-
is_date({
|
|
66
|
-
visited: props.visited,
|
|
67
|
-
metadata: e,
|
|
68
|
-
}),
|
|
69
|
-
),
|
|
70
|
-
) ||
|
|
71
|
-
props.metadata.aliases.some((alias) =>
|
|
72
|
-
is_date({
|
|
73
|
-
visited: props.visited,
|
|
74
|
-
metadata: alias.type.value,
|
|
75
|
-
}),
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
};
|
|
1
|
+
import { OpenApi, OpenApiTypeChecker } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
5
|
+
|
|
6
|
+
import { json_schema_station } from "./json_schema_station";
|
|
7
|
+
|
|
8
|
+
/** @internal */
|
|
9
|
+
export const json_schema_escaped = (props: {
|
|
10
|
+
components: OpenApi.IComponents;
|
|
11
|
+
escaped: MetadataEscaped;
|
|
12
|
+
}): OpenApi.IJsonSchema[] => {
|
|
13
|
+
const output: OpenApi.IJsonSchema | null = json_schema_station({
|
|
14
|
+
blockNever: false,
|
|
15
|
+
components: props.components,
|
|
16
|
+
metadata: props.escaped.returns,
|
|
17
|
+
attribute: {},
|
|
18
|
+
});
|
|
19
|
+
if (output === null) return [];
|
|
20
|
+
|
|
21
|
+
if (
|
|
22
|
+
is_date({
|
|
23
|
+
visited: new Set(),
|
|
24
|
+
metadata: props.escaped.original,
|
|
25
|
+
})
|
|
26
|
+
) {
|
|
27
|
+
const string: OpenApi.IJsonSchema.IString | undefined =
|
|
28
|
+
OpenApiTypeChecker.isString(output)
|
|
29
|
+
? output
|
|
30
|
+
: OpenApiTypeChecker.isOneOf(output)
|
|
31
|
+
? (output.oneOf.find(
|
|
32
|
+
OpenApiTypeChecker.isString,
|
|
33
|
+
) as OpenApi.IJsonSchema.IString)
|
|
34
|
+
: undefined;
|
|
35
|
+
if (
|
|
36
|
+
string !== undefined &&
|
|
37
|
+
string.format !== "date" &&
|
|
38
|
+
string.format !== "date-time"
|
|
39
|
+
)
|
|
40
|
+
string.format = "date-time";
|
|
41
|
+
}
|
|
42
|
+
return OpenApiTypeChecker.isOneOf(output)
|
|
43
|
+
? (output.oneOf as OpenApi.IJsonSchema[])
|
|
44
|
+
: [output];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** @internal */
|
|
48
|
+
const is_date = (props: {
|
|
49
|
+
visited: Set<Metadata>;
|
|
50
|
+
metadata: Metadata;
|
|
51
|
+
}): boolean => {
|
|
52
|
+
if (props.visited.has(props.metadata)) return false;
|
|
53
|
+
props.visited.add(props.metadata);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
props.metadata.natives.some((native) => native.name === "Date") ||
|
|
57
|
+
props.metadata.arrays.some((array) =>
|
|
58
|
+
is_date({
|
|
59
|
+
visited: props.visited,
|
|
60
|
+
metadata: array.type.value,
|
|
61
|
+
}),
|
|
62
|
+
) ||
|
|
63
|
+
props.metadata.tuples.some((tuple) =>
|
|
64
|
+
tuple.type.elements.some((e) =>
|
|
65
|
+
is_date({
|
|
66
|
+
visited: props.visited,
|
|
67
|
+
metadata: e,
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
) ||
|
|
71
|
+
props.metadata.aliases.some((alias) =>
|
|
72
|
+
is_date({
|
|
73
|
+
visited: props.visited,
|
|
74
|
+
metadata: alias.type.value,
|
|
75
|
+
}),
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
};
|