@typia/utils 12.0.0-dev.20260309 → 12.0.0-dev.20260310
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/lib/http/internal/HttpLlmApplicationComposer.mjs +5 -1
- package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
- package/lib/index.mjs +9 -9
- package/lib/utils/LlmJson.mjs +9 -2
- package/lib/utils/LlmJson.mjs.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.js +17 -15
- package/lib/utils/internal/stringifyValidationFailure.js.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.mjs +17 -15
- package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs +5 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
- package/package.json +2 -2
- package/src/converters/LlmSchemaConverter.ts +647 -647
- package/src/converters/OpenApiConverter.ts +285 -285
- package/src/converters/index.ts +5 -5
- package/src/converters/internal/LlmDescriptionInverter.ts +178 -178
- package/src/converters/internal/LlmParametersComposer.ts +52 -52
- package/src/converters/internal/OpenApiConstraintShifter.ts +154 -154
- package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -46
- package/src/converters/internal/OpenApiV3Downgrader.ts +355 -355
- package/src/converters/internal/OpenApiV3Upgrader.ts +470 -470
- package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -685
- package/src/converters/internal/SwaggerV2Downgrader.ts +424 -424
- package/src/converters/internal/SwaggerV2Upgrader.ts +523 -523
- package/src/http/HttpError.ts +107 -107
- package/src/http/HttpLlm.ts +167 -167
- package/src/http/HttpMigration.ts +92 -92
- package/src/http/index.ts +3 -3
- package/src/http/internal/HttpLlmApplicationComposer.ts +361 -361
- package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -37
- package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -56
- package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -135
- package/src/http/internal/HttpMigrateRouteComposer.ts +505 -505
- package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -203
- package/src/index.ts +4 -4
- package/src/utils/ArrayUtil.ts +42 -42
- package/src/utils/LlmJson.ts +141 -141
- package/src/utils/MapUtil.ts +15 -15
- package/src/utils/NamingConvention.ts +205 -205
- package/src/utils/Singleton.ts +17 -17
- package/src/utils/StringUtil.ts +14 -14
- package/src/utils/dedent.ts +57 -57
- package/src/utils/index.ts +8 -8
- package/src/utils/internal/EndpointUtil.ts +44 -44
- package/src/utils/internal/JsonDescriptor.ts +70 -70
- package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -822
- package/src/utils/internal/coerceLlmArguments.ts +314 -314
- package/src/utils/internal/parseLenientJson.ts +894 -894
- package/src/utils/internal/stringifyValidationFailure.ts +415 -411
- package/src/validators/LlmTypeChecker.ts +402 -402
- package/src/validators/OpenApiTypeChecker.ts +297 -297
- package/src/validators/OpenApiV3TypeChecker.ts +70 -70
- package/src/validators/OpenApiV3_1TypeChecker.ts +86 -86
- package/src/validators/OpenApiValidator.ts +94 -94
- package/src/validators/SwaggerV2TypeChecker.ts +71 -71
- package/src/validators/functional/_isBigintString.ts +8 -8
- package/src/validators/functional/_isFormatByte.ts +7 -7
- package/src/validators/functional/_isFormatDate.ts +3 -3
- package/src/validators/functional/_isFormatDateTime.ts +4 -4
- package/src/validators/functional/_isFormatDuration.ts +4 -4
- package/src/validators/functional/_isFormatEmail.ts +4 -4
- package/src/validators/functional/_isFormatHostname.ts +4 -4
- package/src/validators/functional/_isFormatIdnEmail.ts +4 -4
- package/src/validators/functional/_isFormatIdnHostname.ts +4 -4
- package/src/validators/functional/_isFormatIpv4.ts +4 -4
- package/src/validators/functional/_isFormatIpv6.ts +4 -4
- package/src/validators/functional/_isFormatIri.ts +3 -3
- package/src/validators/functional/_isFormatIriReference.ts +4 -4
- package/src/validators/functional/_isFormatJsonPointer.ts +3 -3
- package/src/validators/functional/_isFormatPassword.ts +1 -1
- package/src/validators/functional/_isFormatRegex.ts +8 -8
- package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -4
- package/src/validators/functional/_isFormatTime.ts +4 -4
- package/src/validators/functional/_isFormatUri.ts +6 -6
- package/src/validators/functional/_isFormatUriReference.ts +5 -5
- package/src/validators/functional/_isFormatUriTemplate.ts +4 -4
- package/src/validators/functional/_isFormatUrl.ts +4 -4
- package/src/validators/functional/_isFormatUuid.ts +3 -3
- package/src/validators/functional/_isUniqueItems.ts +159 -159
- package/src/validators/index.ts +14 -14
- package/src/validators/internal/IOpenApiValidatorContext.ts +17 -17
- package/src/validators/internal/OpenApiArrayValidator.ts +49 -49
- package/src/validators/internal/OpenApiBooleanValidator.ts +11 -11
- package/src/validators/internal/OpenApiConstantValidator.ts +11 -11
- package/src/validators/internal/OpenApiIntegerValidator.ts +49 -49
- package/src/validators/internal/OpenApiNumberValidator.ts +48 -48
- package/src/validators/internal/OpenApiObjectValidator.ts +83 -83
- package/src/validators/internal/OpenApiOneOfValidator.ts +309 -309
- package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -124
- package/src/validators/internal/OpenApiStationValidator.ts +115 -115
- package/src/validators/internal/OpenApiStringValidator.ts +88 -88
- package/src/validators/internal/OpenApiTupleValidator.ts +55 -55
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { OpenApiTypeChecker } from "../OpenApiTypeChecker";
|
|
4
|
-
|
|
5
|
-
export namespace OpenApiSchemaNamingRule {
|
|
6
|
-
export const getName = (
|
|
7
|
-
schema: OpenApi.IJsonSchema,
|
|
8
|
-
union: boolean = false,
|
|
9
|
-
): string => {
|
|
10
|
-
// COALESCE
|
|
11
|
-
if (OpenApiTypeChecker.isUnknown(schema)) return "unknown";
|
|
12
|
-
else if (OpenApiTypeChecker.isNull(schema)) return "null";
|
|
13
|
-
else if (OpenApiTypeChecker.isOneOf(schema))
|
|
14
|
-
return schema.oneOf.map((child) => getName(child, true)).join(" | ");
|
|
15
|
-
// ATOMICS
|
|
16
|
-
else if (OpenApiTypeChecker.isConstant(schema))
|
|
17
|
-
return JSON.stringify(schema.const);
|
|
18
|
-
else if (OpenApiTypeChecker.isBoolean(schema)) return "boolean";
|
|
19
|
-
else if (OpenApiTypeChecker.isInteger(schema))
|
|
20
|
-
return joinIntersection(getNameOfInteger(schema), union);
|
|
21
|
-
else if (OpenApiTypeChecker.isNumber(schema))
|
|
22
|
-
return joinIntersection(getNameOfNumber(schema), union);
|
|
23
|
-
else if (OpenApiTypeChecker.isString(schema))
|
|
24
|
-
return joinIntersection(getNameOfString(schema), union);
|
|
25
|
-
// INSTANCES
|
|
26
|
-
else if (OpenApiTypeChecker.isReference(schema))
|
|
27
|
-
return schema.$ref.split("/").pop() ?? "unknown";
|
|
28
|
-
else if (OpenApiTypeChecker.isObject(schema)) return "__object";
|
|
29
|
-
else if (OpenApiTypeChecker.isArray(schema))
|
|
30
|
-
return joinIntersection(getNameOfArray(schema), union);
|
|
31
|
-
else if (OpenApiTypeChecker.isTuple(schema)) return getNameOfTuple(schema);
|
|
32
|
-
return "unknown";
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const getNameOfInteger = (schema: OpenApi.IJsonSchema.IInteger): string[] => [
|
|
36
|
-
"number",
|
|
37
|
-
...(schema.minimum !== undefined
|
|
38
|
-
? [
|
|
39
|
-
schema.exclusiveMinimum
|
|
40
|
-
? `tags.ExclusiveMinimum<${schema.minimum}>`
|
|
41
|
-
: `tags.Minimum<${schema.minimum}>`,
|
|
42
|
-
]
|
|
43
|
-
: []),
|
|
44
|
-
...(schema.maximum !== undefined
|
|
45
|
-
? [
|
|
46
|
-
schema.exclusiveMaximum
|
|
47
|
-
? `tags.ExclusiveMaximum<${schema.maximum}>`
|
|
48
|
-
: `tags.Maximum<${schema.maximum}>`,
|
|
49
|
-
]
|
|
50
|
-
: []),
|
|
51
|
-
...(schema.multipleOf !== undefined
|
|
52
|
-
? [`tags.MultipleOf<${schema.multipleOf}>`]
|
|
53
|
-
: []),
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
const getNameOfNumber = (schema: OpenApi.IJsonSchema.INumber): string[] => [
|
|
57
|
-
"number",
|
|
58
|
-
...(schema.minimum !== undefined
|
|
59
|
-
? [
|
|
60
|
-
schema.exclusiveMinimum
|
|
61
|
-
? `tags.ExclusiveMinimum<${schema.minimum}>`
|
|
62
|
-
: `tags.Minimum<${schema.minimum}>`,
|
|
63
|
-
]
|
|
64
|
-
: []),
|
|
65
|
-
...(schema.maximum !== undefined
|
|
66
|
-
? [
|
|
67
|
-
schema.exclusiveMaximum
|
|
68
|
-
? `tags.ExclusiveMaximum<${schema.maximum}>`
|
|
69
|
-
: `tags.Maximum<${schema.maximum}>`,
|
|
70
|
-
]
|
|
71
|
-
: []),
|
|
72
|
-
...(schema.multipleOf !== undefined
|
|
73
|
-
? [`tags.MultipleOf<${schema.multipleOf}>`]
|
|
74
|
-
: []),
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
const getNameOfString = (schema: OpenApi.IJsonSchema.IString): string[] => [
|
|
78
|
-
"string",
|
|
79
|
-
...(schema.format !== undefined
|
|
80
|
-
? [`tags.Format<${JSON.stringify(schema.format)}>`]
|
|
81
|
-
: []),
|
|
82
|
-
...(schema.pattern !== undefined && schema.format === undefined
|
|
83
|
-
? [`tags.Pattern<${JSON.stringify(schema.pattern)}>`]
|
|
84
|
-
: []),
|
|
85
|
-
...(schema.contentMediaType !== undefined
|
|
86
|
-
? [`tags.ContentMediaType<${JSON.stringify(schema.contentMediaType)}>`]
|
|
87
|
-
: []),
|
|
88
|
-
...(schema.minLength !== undefined
|
|
89
|
-
? [`tags.MinLength<${schema.minLength}>`]
|
|
90
|
-
: []),
|
|
91
|
-
...(schema.maxLength !== undefined
|
|
92
|
-
? [`tags.MaxLength<${schema.maxLength}>`]
|
|
93
|
-
: []),
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
const getNameOfArray = (schema: OpenApi.IJsonSchema.IArray): string[] => [
|
|
97
|
-
`Array<${getName(schema.items)}>`,
|
|
98
|
-
...(schema.minItems !== undefined
|
|
99
|
-
? [`tags.MinItems<${schema.minItems}>`]
|
|
100
|
-
: []),
|
|
101
|
-
...(schema.maxItems !== undefined
|
|
102
|
-
? [`tags.MaxItems<${schema.maxItems}>`]
|
|
103
|
-
: []),
|
|
104
|
-
...(schema.uniqueItems !== undefined ? [`tags.UniqueItems`] : []),
|
|
105
|
-
];
|
|
106
|
-
|
|
107
|
-
const getNameOfTuple = (schema: OpenApi.IJsonSchema.ITuple): string =>
|
|
108
|
-
"[" +
|
|
109
|
-
[
|
|
110
|
-
...schema.prefixItems.map((child) => getName(child)),
|
|
111
|
-
...(schema.additionalItems === true
|
|
112
|
-
? ["...Array<unknown>"]
|
|
113
|
-
: typeof schema.additionalItems === "object" &&
|
|
114
|
-
schema.additionalItems !== null
|
|
115
|
-
? [`...Array<${getName(schema.additionalItems)}>`]
|
|
116
|
-
: []),
|
|
117
|
-
].join(", ") +
|
|
118
|
-
"]";
|
|
119
|
-
|
|
120
|
-
const joinIntersection = (elements: string[], union: boolean): string => {
|
|
121
|
-
const str: string = elements.join(" & ");
|
|
122
|
-
return union ? `(${str})` : str;
|
|
123
|
-
};
|
|
124
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { OpenApiTypeChecker } from "../OpenApiTypeChecker";
|
|
4
|
+
|
|
5
|
+
export namespace OpenApiSchemaNamingRule {
|
|
6
|
+
export const getName = (
|
|
7
|
+
schema: OpenApi.IJsonSchema,
|
|
8
|
+
union: boolean = false,
|
|
9
|
+
): string => {
|
|
10
|
+
// COALESCE
|
|
11
|
+
if (OpenApiTypeChecker.isUnknown(schema)) return "unknown";
|
|
12
|
+
else if (OpenApiTypeChecker.isNull(schema)) return "null";
|
|
13
|
+
else if (OpenApiTypeChecker.isOneOf(schema))
|
|
14
|
+
return schema.oneOf.map((child) => getName(child, true)).join(" | ");
|
|
15
|
+
// ATOMICS
|
|
16
|
+
else if (OpenApiTypeChecker.isConstant(schema))
|
|
17
|
+
return JSON.stringify(schema.const);
|
|
18
|
+
else if (OpenApiTypeChecker.isBoolean(schema)) return "boolean";
|
|
19
|
+
else if (OpenApiTypeChecker.isInteger(schema))
|
|
20
|
+
return joinIntersection(getNameOfInteger(schema), union);
|
|
21
|
+
else if (OpenApiTypeChecker.isNumber(schema))
|
|
22
|
+
return joinIntersection(getNameOfNumber(schema), union);
|
|
23
|
+
else if (OpenApiTypeChecker.isString(schema))
|
|
24
|
+
return joinIntersection(getNameOfString(schema), union);
|
|
25
|
+
// INSTANCES
|
|
26
|
+
else if (OpenApiTypeChecker.isReference(schema))
|
|
27
|
+
return schema.$ref.split("/").pop() ?? "unknown";
|
|
28
|
+
else if (OpenApiTypeChecker.isObject(schema)) return "__object";
|
|
29
|
+
else if (OpenApiTypeChecker.isArray(schema))
|
|
30
|
+
return joinIntersection(getNameOfArray(schema), union);
|
|
31
|
+
else if (OpenApiTypeChecker.isTuple(schema)) return getNameOfTuple(schema);
|
|
32
|
+
return "unknown";
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const getNameOfInteger = (schema: OpenApi.IJsonSchema.IInteger): string[] => [
|
|
36
|
+
"number",
|
|
37
|
+
...(schema.minimum !== undefined
|
|
38
|
+
? [
|
|
39
|
+
schema.exclusiveMinimum
|
|
40
|
+
? `tags.ExclusiveMinimum<${schema.minimum}>`
|
|
41
|
+
: `tags.Minimum<${schema.minimum}>`,
|
|
42
|
+
]
|
|
43
|
+
: []),
|
|
44
|
+
...(schema.maximum !== undefined
|
|
45
|
+
? [
|
|
46
|
+
schema.exclusiveMaximum
|
|
47
|
+
? `tags.ExclusiveMaximum<${schema.maximum}>`
|
|
48
|
+
: `tags.Maximum<${schema.maximum}>`,
|
|
49
|
+
]
|
|
50
|
+
: []),
|
|
51
|
+
...(schema.multipleOf !== undefined
|
|
52
|
+
? [`tags.MultipleOf<${schema.multipleOf}>`]
|
|
53
|
+
: []),
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const getNameOfNumber = (schema: OpenApi.IJsonSchema.INumber): string[] => [
|
|
57
|
+
"number",
|
|
58
|
+
...(schema.minimum !== undefined
|
|
59
|
+
? [
|
|
60
|
+
schema.exclusiveMinimum
|
|
61
|
+
? `tags.ExclusiveMinimum<${schema.minimum}>`
|
|
62
|
+
: `tags.Minimum<${schema.minimum}>`,
|
|
63
|
+
]
|
|
64
|
+
: []),
|
|
65
|
+
...(schema.maximum !== undefined
|
|
66
|
+
? [
|
|
67
|
+
schema.exclusiveMaximum
|
|
68
|
+
? `tags.ExclusiveMaximum<${schema.maximum}>`
|
|
69
|
+
: `tags.Maximum<${schema.maximum}>`,
|
|
70
|
+
]
|
|
71
|
+
: []),
|
|
72
|
+
...(schema.multipleOf !== undefined
|
|
73
|
+
? [`tags.MultipleOf<${schema.multipleOf}>`]
|
|
74
|
+
: []),
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const getNameOfString = (schema: OpenApi.IJsonSchema.IString): string[] => [
|
|
78
|
+
"string",
|
|
79
|
+
...(schema.format !== undefined
|
|
80
|
+
? [`tags.Format<${JSON.stringify(schema.format)}>`]
|
|
81
|
+
: []),
|
|
82
|
+
...(schema.pattern !== undefined && schema.format === undefined
|
|
83
|
+
? [`tags.Pattern<${JSON.stringify(schema.pattern)}>`]
|
|
84
|
+
: []),
|
|
85
|
+
...(schema.contentMediaType !== undefined
|
|
86
|
+
? [`tags.ContentMediaType<${JSON.stringify(schema.contentMediaType)}>`]
|
|
87
|
+
: []),
|
|
88
|
+
...(schema.minLength !== undefined
|
|
89
|
+
? [`tags.MinLength<${schema.minLength}>`]
|
|
90
|
+
: []),
|
|
91
|
+
...(schema.maxLength !== undefined
|
|
92
|
+
? [`tags.MaxLength<${schema.maxLength}>`]
|
|
93
|
+
: []),
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
const getNameOfArray = (schema: OpenApi.IJsonSchema.IArray): string[] => [
|
|
97
|
+
`Array<${getName(schema.items)}>`,
|
|
98
|
+
...(schema.minItems !== undefined
|
|
99
|
+
? [`tags.MinItems<${schema.minItems}>`]
|
|
100
|
+
: []),
|
|
101
|
+
...(schema.maxItems !== undefined
|
|
102
|
+
? [`tags.MaxItems<${schema.maxItems}>`]
|
|
103
|
+
: []),
|
|
104
|
+
...(schema.uniqueItems !== undefined ? [`tags.UniqueItems`] : []),
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const getNameOfTuple = (schema: OpenApi.IJsonSchema.ITuple): string =>
|
|
108
|
+
"[" +
|
|
109
|
+
[
|
|
110
|
+
...schema.prefixItems.map((child) => getName(child)),
|
|
111
|
+
...(schema.additionalItems === true
|
|
112
|
+
? ["...Array<unknown>"]
|
|
113
|
+
: typeof schema.additionalItems === "object" &&
|
|
114
|
+
schema.additionalItems !== null
|
|
115
|
+
? [`...Array<${getName(schema.additionalItems)}>`]
|
|
116
|
+
: []),
|
|
117
|
+
].join(", ") +
|
|
118
|
+
"]";
|
|
119
|
+
|
|
120
|
+
const joinIntersection = (elements: string[], union: boolean): string => {
|
|
121
|
+
const str: string = elements.join(" & ");
|
|
122
|
+
return union ? `(${str})` : str;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { OpenApiTypeChecker } from "../OpenApiTypeChecker";
|
|
4
|
-
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
5
|
-
import { OpenApiArrayValidator } from "./OpenApiArrayValidator";
|
|
6
|
-
import { OpenApiBooleanValidator } from "./OpenApiBooleanValidator";
|
|
7
|
-
import { OpenApiConstantValidator } from "./OpenApiConstantValidator";
|
|
8
|
-
import { OpenApiIntegerValidator } from "./OpenApiIntegerValidator";
|
|
9
|
-
import { OpenApiNumberValidator } from "./OpenApiNumberValidator";
|
|
10
|
-
import { OpenApiObjectValidator } from "./OpenApiObjectValidator";
|
|
11
|
-
import { OpenApiOneOfValidator } from "./OpenApiOneOfValidator";
|
|
12
|
-
import { OpenApiSchemaNamingRule } from "./OpenApiSchemaNamingRule";
|
|
13
|
-
import { OpenApiStringValidator } from "./OpenApiStringValidator";
|
|
14
|
-
import { OpenApiTupleValidator } from "./OpenApiTupleValidator";
|
|
15
|
-
|
|
16
|
-
export namespace OpenApiStationValidator {
|
|
17
|
-
export const validate = (
|
|
18
|
-
ctx: Omit<IOpenApiValidatorContext<OpenApi.IJsonSchema>, "expected">,
|
|
19
|
-
expected?: string,
|
|
20
|
-
): boolean => {
|
|
21
|
-
// THE TYPE NAME
|
|
22
|
-
expected ??= (() => {
|
|
23
|
-
const name = OpenApiSchemaNamingRule.getName(ctx.schema);
|
|
24
|
-
return ctx.required ? name : `${name} | undefined`;
|
|
25
|
-
})();
|
|
26
|
-
|
|
27
|
-
// COALESCE
|
|
28
|
-
if (OpenApiTypeChecker.isUnknown(ctx.schema)) return true;
|
|
29
|
-
else if (ctx.value === undefined)
|
|
30
|
-
return (
|
|
31
|
-
ctx.required === false ||
|
|
32
|
-
ctx.report({
|
|
33
|
-
...ctx,
|
|
34
|
-
expected,
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
else if (OpenApiTypeChecker.isNull(ctx.schema))
|
|
38
|
-
return (
|
|
39
|
-
ctx.value === null ||
|
|
40
|
-
ctx.report({
|
|
41
|
-
...ctx,
|
|
42
|
-
expected,
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
// NESTED
|
|
46
|
-
else if (OpenApiTypeChecker.isReference(ctx.schema)) {
|
|
47
|
-
const schema: OpenApi.IJsonSchema | undefined =
|
|
48
|
-
ctx.components.schemas?.[ctx.schema.$ref.split("/").pop() ?? ""];
|
|
49
|
-
if (schema === undefined) return true;
|
|
50
|
-
return OpenApiStationValidator.validate(
|
|
51
|
-
{
|
|
52
|
-
...ctx,
|
|
53
|
-
schema,
|
|
54
|
-
},
|
|
55
|
-
expected,
|
|
56
|
-
);
|
|
57
|
-
} else if (OpenApiTypeChecker.isOneOf(ctx.schema))
|
|
58
|
-
return OpenApiOneOfValidator.validate({
|
|
59
|
-
...ctx,
|
|
60
|
-
schema: ctx.schema,
|
|
61
|
-
expected,
|
|
62
|
-
});
|
|
63
|
-
// ATOMICS
|
|
64
|
-
else if (OpenApiTypeChecker.isConstant(ctx.schema))
|
|
65
|
-
return OpenApiConstantValidator.validate({
|
|
66
|
-
...ctx,
|
|
67
|
-
schema: ctx.schema,
|
|
68
|
-
expected,
|
|
69
|
-
});
|
|
70
|
-
else if (OpenApiTypeChecker.isBoolean(ctx.schema))
|
|
71
|
-
return OpenApiBooleanValidator.validate({
|
|
72
|
-
...ctx,
|
|
73
|
-
schema: ctx.schema,
|
|
74
|
-
expected,
|
|
75
|
-
});
|
|
76
|
-
else if (OpenApiTypeChecker.isInteger(ctx.schema))
|
|
77
|
-
return OpenApiIntegerValidator.validate({
|
|
78
|
-
...ctx,
|
|
79
|
-
schema: ctx.schema,
|
|
80
|
-
expected,
|
|
81
|
-
});
|
|
82
|
-
else if (OpenApiTypeChecker.isNumber(ctx.schema))
|
|
83
|
-
return OpenApiNumberValidator.validate({
|
|
84
|
-
...ctx,
|
|
85
|
-
schema: ctx.schema,
|
|
86
|
-
expected,
|
|
87
|
-
});
|
|
88
|
-
else if (OpenApiTypeChecker.isString(ctx.schema))
|
|
89
|
-
return OpenApiStringValidator.validate({
|
|
90
|
-
...ctx,
|
|
91
|
-
schema: ctx.schema,
|
|
92
|
-
expected,
|
|
93
|
-
});
|
|
94
|
-
// INSTANCES
|
|
95
|
-
else if (OpenApiTypeChecker.isArray(ctx.schema))
|
|
96
|
-
return OpenApiArrayValidator.validate({
|
|
97
|
-
...ctx,
|
|
98
|
-
schema: ctx.schema,
|
|
99
|
-
expected,
|
|
100
|
-
});
|
|
101
|
-
else if (OpenApiTypeChecker.isTuple(ctx.schema))
|
|
102
|
-
return OpenApiTupleValidator.validate({
|
|
103
|
-
...ctx,
|
|
104
|
-
schema: ctx.schema,
|
|
105
|
-
expected,
|
|
106
|
-
});
|
|
107
|
-
else if (OpenApiTypeChecker.isObject(ctx.schema))
|
|
108
|
-
return OpenApiObjectValidator.validate({
|
|
109
|
-
...ctx,
|
|
110
|
-
schema: ctx.schema,
|
|
111
|
-
expected,
|
|
112
|
-
});
|
|
113
|
-
return true;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { OpenApiTypeChecker } from "../OpenApiTypeChecker";
|
|
4
|
+
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
5
|
+
import { OpenApiArrayValidator } from "./OpenApiArrayValidator";
|
|
6
|
+
import { OpenApiBooleanValidator } from "./OpenApiBooleanValidator";
|
|
7
|
+
import { OpenApiConstantValidator } from "./OpenApiConstantValidator";
|
|
8
|
+
import { OpenApiIntegerValidator } from "./OpenApiIntegerValidator";
|
|
9
|
+
import { OpenApiNumberValidator } from "./OpenApiNumberValidator";
|
|
10
|
+
import { OpenApiObjectValidator } from "./OpenApiObjectValidator";
|
|
11
|
+
import { OpenApiOneOfValidator } from "./OpenApiOneOfValidator";
|
|
12
|
+
import { OpenApiSchemaNamingRule } from "./OpenApiSchemaNamingRule";
|
|
13
|
+
import { OpenApiStringValidator } from "./OpenApiStringValidator";
|
|
14
|
+
import { OpenApiTupleValidator } from "./OpenApiTupleValidator";
|
|
15
|
+
|
|
16
|
+
export namespace OpenApiStationValidator {
|
|
17
|
+
export const validate = (
|
|
18
|
+
ctx: Omit<IOpenApiValidatorContext<OpenApi.IJsonSchema>, "expected">,
|
|
19
|
+
expected?: string,
|
|
20
|
+
): boolean => {
|
|
21
|
+
// THE TYPE NAME
|
|
22
|
+
expected ??= (() => {
|
|
23
|
+
const name = OpenApiSchemaNamingRule.getName(ctx.schema);
|
|
24
|
+
return ctx.required ? name : `${name} | undefined`;
|
|
25
|
+
})();
|
|
26
|
+
|
|
27
|
+
// COALESCE
|
|
28
|
+
if (OpenApiTypeChecker.isUnknown(ctx.schema)) return true;
|
|
29
|
+
else if (ctx.value === undefined)
|
|
30
|
+
return (
|
|
31
|
+
ctx.required === false ||
|
|
32
|
+
ctx.report({
|
|
33
|
+
...ctx,
|
|
34
|
+
expected,
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
else if (OpenApiTypeChecker.isNull(ctx.schema))
|
|
38
|
+
return (
|
|
39
|
+
ctx.value === null ||
|
|
40
|
+
ctx.report({
|
|
41
|
+
...ctx,
|
|
42
|
+
expected,
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
// NESTED
|
|
46
|
+
else if (OpenApiTypeChecker.isReference(ctx.schema)) {
|
|
47
|
+
const schema: OpenApi.IJsonSchema | undefined =
|
|
48
|
+
ctx.components.schemas?.[ctx.schema.$ref.split("/").pop() ?? ""];
|
|
49
|
+
if (schema === undefined) return true;
|
|
50
|
+
return OpenApiStationValidator.validate(
|
|
51
|
+
{
|
|
52
|
+
...ctx,
|
|
53
|
+
schema,
|
|
54
|
+
},
|
|
55
|
+
expected,
|
|
56
|
+
);
|
|
57
|
+
} else if (OpenApiTypeChecker.isOneOf(ctx.schema))
|
|
58
|
+
return OpenApiOneOfValidator.validate({
|
|
59
|
+
...ctx,
|
|
60
|
+
schema: ctx.schema,
|
|
61
|
+
expected,
|
|
62
|
+
});
|
|
63
|
+
// ATOMICS
|
|
64
|
+
else if (OpenApiTypeChecker.isConstant(ctx.schema))
|
|
65
|
+
return OpenApiConstantValidator.validate({
|
|
66
|
+
...ctx,
|
|
67
|
+
schema: ctx.schema,
|
|
68
|
+
expected,
|
|
69
|
+
});
|
|
70
|
+
else if (OpenApiTypeChecker.isBoolean(ctx.schema))
|
|
71
|
+
return OpenApiBooleanValidator.validate({
|
|
72
|
+
...ctx,
|
|
73
|
+
schema: ctx.schema,
|
|
74
|
+
expected,
|
|
75
|
+
});
|
|
76
|
+
else if (OpenApiTypeChecker.isInteger(ctx.schema))
|
|
77
|
+
return OpenApiIntegerValidator.validate({
|
|
78
|
+
...ctx,
|
|
79
|
+
schema: ctx.schema,
|
|
80
|
+
expected,
|
|
81
|
+
});
|
|
82
|
+
else if (OpenApiTypeChecker.isNumber(ctx.schema))
|
|
83
|
+
return OpenApiNumberValidator.validate({
|
|
84
|
+
...ctx,
|
|
85
|
+
schema: ctx.schema,
|
|
86
|
+
expected,
|
|
87
|
+
});
|
|
88
|
+
else if (OpenApiTypeChecker.isString(ctx.schema))
|
|
89
|
+
return OpenApiStringValidator.validate({
|
|
90
|
+
...ctx,
|
|
91
|
+
schema: ctx.schema,
|
|
92
|
+
expected,
|
|
93
|
+
});
|
|
94
|
+
// INSTANCES
|
|
95
|
+
else if (OpenApiTypeChecker.isArray(ctx.schema))
|
|
96
|
+
return OpenApiArrayValidator.validate({
|
|
97
|
+
...ctx,
|
|
98
|
+
schema: ctx.schema,
|
|
99
|
+
expected,
|
|
100
|
+
});
|
|
101
|
+
else if (OpenApiTypeChecker.isTuple(ctx.schema))
|
|
102
|
+
return OpenApiTupleValidator.validate({
|
|
103
|
+
...ctx,
|
|
104
|
+
schema: ctx.schema,
|
|
105
|
+
expected,
|
|
106
|
+
});
|
|
107
|
+
else if (OpenApiTypeChecker.isObject(ctx.schema))
|
|
108
|
+
return OpenApiObjectValidator.validate({
|
|
109
|
+
...ctx,
|
|
110
|
+
schema: ctx.schema,
|
|
111
|
+
expected,
|
|
112
|
+
});
|
|
113
|
+
return true;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { _isFormatByte } from "../functional/_isFormatByte";
|
|
4
|
-
import { _isFormatDate } from "../functional/_isFormatDate";
|
|
5
|
-
import { _isFormatDateTime } from "../functional/_isFormatDateTime";
|
|
6
|
-
import { _isFormatDuration } from "../functional/_isFormatDuration";
|
|
7
|
-
import { _isFormatEmail } from "../functional/_isFormatEmail";
|
|
8
|
-
import { _isFormatHostname } from "../functional/_isFormatHostname";
|
|
9
|
-
import { _isFormatIdnEmail } from "../functional/_isFormatIdnEmail";
|
|
10
|
-
import { _isFormatIdnHostname } from "../functional/_isFormatIdnHostname";
|
|
11
|
-
import { _isFormatIpv4 } from "../functional/_isFormatIpv4";
|
|
12
|
-
import { _isFormatIpv6 } from "../functional/_isFormatIpv6";
|
|
13
|
-
import { _isFormatIri } from "../functional/_isFormatIri";
|
|
14
|
-
import { _isFormatIriReference } from "../functional/_isFormatIriReference";
|
|
15
|
-
import { _isFormatJsonPointer } from "../functional/_isFormatJsonPointer";
|
|
16
|
-
import { _isFormatRegex } from "../functional/_isFormatRegex";
|
|
17
|
-
import { _isFormatRelativeJsonPointer } from "../functional/_isFormatRelativeJsonPointer";
|
|
18
|
-
import { _isFormatTime } from "../functional/_isFormatTime";
|
|
19
|
-
import { _isFormatUri } from "../functional/_isFormatUri";
|
|
20
|
-
import { _isFormatUriReference } from "../functional/_isFormatUriReference";
|
|
21
|
-
import { _isFormatUriTemplate } from "../functional/_isFormatUriTemplate";
|
|
22
|
-
import { _isFormatUrl } from "../functional/_isFormatUrl";
|
|
23
|
-
import { _isFormatUuid } from "../functional/_isFormatUuid";
|
|
24
|
-
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
25
|
-
|
|
26
|
-
export namespace OpenApiStringValidator {
|
|
27
|
-
export const validate = (
|
|
28
|
-
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IString>,
|
|
29
|
-
): boolean => {
|
|
30
|
-
if (typeof ctx.value !== "string") return ctx.report(ctx);
|
|
31
|
-
return (
|
|
32
|
-
[
|
|
33
|
-
ctx.schema.minLength !== undefined
|
|
34
|
-
? ctx.value.length >= ctx.schema.minLength ||
|
|
35
|
-
ctx.report({
|
|
36
|
-
...ctx,
|
|
37
|
-
expected: `string & MinLength<${ctx.schema.minLength}>`,
|
|
38
|
-
})
|
|
39
|
-
: true,
|
|
40
|
-
ctx.schema.maxLength !== undefined
|
|
41
|
-
? ctx.value.length <= ctx.schema.maxLength ||
|
|
42
|
-
ctx.report({
|
|
43
|
-
...ctx,
|
|
44
|
-
expected: `string & MaxLength<${ctx.schema.maxLength}>`,
|
|
45
|
-
})
|
|
46
|
-
: true,
|
|
47
|
-
ctx.schema.pattern !== undefined
|
|
48
|
-
? new RegExp(ctx.schema.pattern).test(ctx.value) ||
|
|
49
|
-
ctx.report({
|
|
50
|
-
...ctx,
|
|
51
|
-
expected: `string & Pattern<${JSON.stringify(ctx.schema.pattern)}>`,
|
|
52
|
-
})
|
|
53
|
-
: true,
|
|
54
|
-
ctx.schema.format && FORMAT[ctx.schema.format as "uuid"]
|
|
55
|
-
? FORMAT[ctx.schema.format as "uuid"](ctx.value) ||
|
|
56
|
-
ctx.report({
|
|
57
|
-
...ctx,
|
|
58
|
-
expected: `string & Format<${JSON.stringify(ctx.schema.format)}>`,
|
|
59
|
-
})
|
|
60
|
-
: true,
|
|
61
|
-
].every((v) => v) || ctx.report(ctx)
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const FORMAT = {
|
|
67
|
-
byte: _isFormatByte,
|
|
68
|
-
regex: _isFormatRegex,
|
|
69
|
-
uuid: _isFormatUuid,
|
|
70
|
-
email: _isFormatEmail,
|
|
71
|
-
hostname: _isFormatHostname,
|
|
72
|
-
"idn-email": _isFormatIdnEmail,
|
|
73
|
-
"idn-hostname": _isFormatIdnHostname,
|
|
74
|
-
iri: _isFormatIri,
|
|
75
|
-
"iri-reference": _isFormatIriReference,
|
|
76
|
-
ipv4: _isFormatIpv4,
|
|
77
|
-
ipv6: _isFormatIpv6,
|
|
78
|
-
uri: _isFormatUri,
|
|
79
|
-
"uri-reference": _isFormatUriReference,
|
|
80
|
-
"uri-template": _isFormatUriTemplate,
|
|
81
|
-
url: _isFormatUrl,
|
|
82
|
-
"date-time": _isFormatDateTime,
|
|
83
|
-
date: _isFormatDate,
|
|
84
|
-
time: _isFormatTime,
|
|
85
|
-
duration: _isFormatDuration,
|
|
86
|
-
"json-pointer": _isFormatJsonPointer,
|
|
87
|
-
"relative-json-pointer": _isFormatRelativeJsonPointer,
|
|
88
|
-
};
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { _isFormatByte } from "../functional/_isFormatByte";
|
|
4
|
+
import { _isFormatDate } from "../functional/_isFormatDate";
|
|
5
|
+
import { _isFormatDateTime } from "../functional/_isFormatDateTime";
|
|
6
|
+
import { _isFormatDuration } from "../functional/_isFormatDuration";
|
|
7
|
+
import { _isFormatEmail } from "../functional/_isFormatEmail";
|
|
8
|
+
import { _isFormatHostname } from "../functional/_isFormatHostname";
|
|
9
|
+
import { _isFormatIdnEmail } from "../functional/_isFormatIdnEmail";
|
|
10
|
+
import { _isFormatIdnHostname } from "../functional/_isFormatIdnHostname";
|
|
11
|
+
import { _isFormatIpv4 } from "../functional/_isFormatIpv4";
|
|
12
|
+
import { _isFormatIpv6 } from "../functional/_isFormatIpv6";
|
|
13
|
+
import { _isFormatIri } from "../functional/_isFormatIri";
|
|
14
|
+
import { _isFormatIriReference } from "../functional/_isFormatIriReference";
|
|
15
|
+
import { _isFormatJsonPointer } from "../functional/_isFormatJsonPointer";
|
|
16
|
+
import { _isFormatRegex } from "../functional/_isFormatRegex";
|
|
17
|
+
import { _isFormatRelativeJsonPointer } from "../functional/_isFormatRelativeJsonPointer";
|
|
18
|
+
import { _isFormatTime } from "../functional/_isFormatTime";
|
|
19
|
+
import { _isFormatUri } from "../functional/_isFormatUri";
|
|
20
|
+
import { _isFormatUriReference } from "../functional/_isFormatUriReference";
|
|
21
|
+
import { _isFormatUriTemplate } from "../functional/_isFormatUriTemplate";
|
|
22
|
+
import { _isFormatUrl } from "../functional/_isFormatUrl";
|
|
23
|
+
import { _isFormatUuid } from "../functional/_isFormatUuid";
|
|
24
|
+
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
25
|
+
|
|
26
|
+
export namespace OpenApiStringValidator {
|
|
27
|
+
export const validate = (
|
|
28
|
+
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IString>,
|
|
29
|
+
): boolean => {
|
|
30
|
+
if (typeof ctx.value !== "string") return ctx.report(ctx);
|
|
31
|
+
return (
|
|
32
|
+
[
|
|
33
|
+
ctx.schema.minLength !== undefined
|
|
34
|
+
? ctx.value.length >= ctx.schema.minLength ||
|
|
35
|
+
ctx.report({
|
|
36
|
+
...ctx,
|
|
37
|
+
expected: `string & MinLength<${ctx.schema.minLength}>`,
|
|
38
|
+
})
|
|
39
|
+
: true,
|
|
40
|
+
ctx.schema.maxLength !== undefined
|
|
41
|
+
? ctx.value.length <= ctx.schema.maxLength ||
|
|
42
|
+
ctx.report({
|
|
43
|
+
...ctx,
|
|
44
|
+
expected: `string & MaxLength<${ctx.schema.maxLength}>`,
|
|
45
|
+
})
|
|
46
|
+
: true,
|
|
47
|
+
ctx.schema.pattern !== undefined
|
|
48
|
+
? new RegExp(ctx.schema.pattern).test(ctx.value) ||
|
|
49
|
+
ctx.report({
|
|
50
|
+
...ctx,
|
|
51
|
+
expected: `string & Pattern<${JSON.stringify(ctx.schema.pattern)}>`,
|
|
52
|
+
})
|
|
53
|
+
: true,
|
|
54
|
+
ctx.schema.format && FORMAT[ctx.schema.format as "uuid"]
|
|
55
|
+
? FORMAT[ctx.schema.format as "uuid"](ctx.value) ||
|
|
56
|
+
ctx.report({
|
|
57
|
+
...ctx,
|
|
58
|
+
expected: `string & Format<${JSON.stringify(ctx.schema.format)}>`,
|
|
59
|
+
})
|
|
60
|
+
: true,
|
|
61
|
+
].every((v) => v) || ctx.report(ctx)
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const FORMAT = {
|
|
67
|
+
byte: _isFormatByte,
|
|
68
|
+
regex: _isFormatRegex,
|
|
69
|
+
uuid: _isFormatUuid,
|
|
70
|
+
email: _isFormatEmail,
|
|
71
|
+
hostname: _isFormatHostname,
|
|
72
|
+
"idn-email": _isFormatIdnEmail,
|
|
73
|
+
"idn-hostname": _isFormatIdnHostname,
|
|
74
|
+
iri: _isFormatIri,
|
|
75
|
+
"iri-reference": _isFormatIriReference,
|
|
76
|
+
ipv4: _isFormatIpv4,
|
|
77
|
+
ipv6: _isFormatIpv6,
|
|
78
|
+
uri: _isFormatUri,
|
|
79
|
+
"uri-reference": _isFormatUriReference,
|
|
80
|
+
"uri-template": _isFormatUriTemplate,
|
|
81
|
+
url: _isFormatUrl,
|
|
82
|
+
"date-time": _isFormatDateTime,
|
|
83
|
+
date: _isFormatDate,
|
|
84
|
+
time: _isFormatTime,
|
|
85
|
+
duration: _isFormatDuration,
|
|
86
|
+
"json-pointer": _isFormatJsonPointer,
|
|
87
|
+
"relative-json-pointer": _isFormatRelativeJsonPointer,
|
|
88
|
+
};
|