@typia/utils 12.0.0-dev.20260309 → 12.0.0-dev.20260311
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/converters/LlmSchemaConverter.d.ts +0 -1
- package/lib/converters/LlmSchemaConverter.js +4 -31
- package/lib/converters/LlmSchemaConverter.js.map +1 -1
- package/lib/converters/LlmSchemaConverter.mjs +2 -32
- package/lib/converters/LlmSchemaConverter.mjs.map +1 -1
- package/lib/http/HttpLlm.js +4 -5
- package/lib/http/HttpLlm.js.map +1 -1
- package/lib/http/HttpLlm.mjs +0 -1
- package/lib/http/HttpLlm.mjs.map +1 -1
- package/lib/http/internal/HttpLlmApplicationComposer.js +3 -4
- package/lib/http/internal/HttpLlmApplicationComposer.js.map +1 -1
- package/lib/http/internal/HttpLlmApplicationComposer.mjs +5 -2
- 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 +617 -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 +166 -167
- package/src/http/HttpMigration.ts +92 -92
- package/src/http/index.ts +3 -3
- package/src/http/internal/HttpLlmApplicationComposer.ts +360 -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,70 +1,70 @@
|
|
|
1
|
-
import { OpenApiV3 } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Type checker for raw OpenAPI v3.0 JSON schemas.
|
|
5
|
-
*
|
|
6
|
-
* `OpenApiV3TypeChecker` provides type guard functions for
|
|
7
|
-
* {@link OpenApiV3.IJsonSchema} (raw, unemended format). For typia's normalized
|
|
8
|
-
* format, use {@link OpenApiTypeChecker} instead.
|
|
9
|
-
*
|
|
10
|
-
* Key differences from v3.1: v3.0 uses `nullable: true` property instead of
|
|
11
|
-
* union types, and has no `const` or tuple support.
|
|
12
|
-
*
|
|
13
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
-
*/
|
|
15
|
-
export namespace OpenApiV3TypeChecker {
|
|
16
|
-
export const isBoolean = (
|
|
17
|
-
schema: OpenApiV3.IJsonSchema,
|
|
18
|
-
): schema is OpenApiV3.IJsonSchema.IBoolean =>
|
|
19
|
-
(schema as OpenApiV3.IJsonSchema.IBoolean).type === "boolean";
|
|
20
|
-
|
|
21
|
-
export const isInteger = (
|
|
22
|
-
schema: OpenApiV3.IJsonSchema,
|
|
23
|
-
): schema is OpenApiV3.IJsonSchema.IInteger =>
|
|
24
|
-
(schema as OpenApiV3.IJsonSchema.IInteger).type === "integer";
|
|
25
|
-
|
|
26
|
-
export const isNumber = (
|
|
27
|
-
schema: OpenApiV3.IJsonSchema,
|
|
28
|
-
): schema is OpenApiV3.IJsonSchema.INumber =>
|
|
29
|
-
(schema as OpenApiV3.IJsonSchema.INumber).type === "number";
|
|
30
|
-
|
|
31
|
-
export const isString = (
|
|
32
|
-
schema: OpenApiV3.IJsonSchema,
|
|
33
|
-
): schema is OpenApiV3.IJsonSchema.IString =>
|
|
34
|
-
(schema as OpenApiV3.IJsonSchema.IString).type === "string";
|
|
35
|
-
|
|
36
|
-
export const isArray = (
|
|
37
|
-
schema: OpenApiV3.IJsonSchema,
|
|
38
|
-
): schema is OpenApiV3.IJsonSchema.IArray =>
|
|
39
|
-
(schema as OpenApiV3.IJsonSchema.IArray).type === "array";
|
|
40
|
-
|
|
41
|
-
export const isObject = (
|
|
42
|
-
schema: OpenApiV3.IJsonSchema,
|
|
43
|
-
): schema is OpenApiV3.IJsonSchema.IObject =>
|
|
44
|
-
(schema as OpenApiV3.IJsonSchema.IObject).type === "object";
|
|
45
|
-
|
|
46
|
-
export const isReference = (
|
|
47
|
-
schema: OpenApiV3.IJsonSchema,
|
|
48
|
-
): schema is OpenApiV3.IJsonSchema.IReference =>
|
|
49
|
-
(schema as OpenApiV3.IJsonSchema.IReference).$ref !== undefined;
|
|
50
|
-
|
|
51
|
-
export const isAllOf = (
|
|
52
|
-
schema: OpenApiV3.IJsonSchema,
|
|
53
|
-
): schema is OpenApiV3.IJsonSchema.IAllOf =>
|
|
54
|
-
(schema as OpenApiV3.IJsonSchema.IAllOf).allOf !== undefined;
|
|
55
|
-
|
|
56
|
-
export const isAnyOf = (
|
|
57
|
-
schema: OpenApiV3.IJsonSchema,
|
|
58
|
-
): schema is OpenApiV3.IJsonSchema.IAnyOf =>
|
|
59
|
-
(schema as OpenApiV3.IJsonSchema.IAnyOf).anyOf !== undefined;
|
|
60
|
-
|
|
61
|
-
export const isOneOf = (
|
|
62
|
-
schema: OpenApiV3.IJsonSchema,
|
|
63
|
-
): schema is OpenApiV3.IJsonSchema.IOneOf =>
|
|
64
|
-
(schema as OpenApiV3.IJsonSchema.IOneOf).oneOf !== undefined;
|
|
65
|
-
|
|
66
|
-
export const isNullOnly = (
|
|
67
|
-
schema: OpenApiV3.IJsonSchema,
|
|
68
|
-
): schema is OpenApiV3.IJsonSchema.INullOnly =>
|
|
69
|
-
(schema as OpenApiV3.IJsonSchema.INullOnly).type === "null";
|
|
70
|
-
}
|
|
1
|
+
import { OpenApiV3 } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type checker for raw OpenAPI v3.0 JSON schemas.
|
|
5
|
+
*
|
|
6
|
+
* `OpenApiV3TypeChecker` provides type guard functions for
|
|
7
|
+
* {@link OpenApiV3.IJsonSchema} (raw, unemended format). For typia's normalized
|
|
8
|
+
* format, use {@link OpenApiTypeChecker} instead.
|
|
9
|
+
*
|
|
10
|
+
* Key differences from v3.1: v3.0 uses `nullable: true` property instead of
|
|
11
|
+
* union types, and has no `const` or tuple support.
|
|
12
|
+
*
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
*/
|
|
15
|
+
export namespace OpenApiV3TypeChecker {
|
|
16
|
+
export const isBoolean = (
|
|
17
|
+
schema: OpenApiV3.IJsonSchema,
|
|
18
|
+
): schema is OpenApiV3.IJsonSchema.IBoolean =>
|
|
19
|
+
(schema as OpenApiV3.IJsonSchema.IBoolean).type === "boolean";
|
|
20
|
+
|
|
21
|
+
export const isInteger = (
|
|
22
|
+
schema: OpenApiV3.IJsonSchema,
|
|
23
|
+
): schema is OpenApiV3.IJsonSchema.IInteger =>
|
|
24
|
+
(schema as OpenApiV3.IJsonSchema.IInteger).type === "integer";
|
|
25
|
+
|
|
26
|
+
export const isNumber = (
|
|
27
|
+
schema: OpenApiV3.IJsonSchema,
|
|
28
|
+
): schema is OpenApiV3.IJsonSchema.INumber =>
|
|
29
|
+
(schema as OpenApiV3.IJsonSchema.INumber).type === "number";
|
|
30
|
+
|
|
31
|
+
export const isString = (
|
|
32
|
+
schema: OpenApiV3.IJsonSchema,
|
|
33
|
+
): schema is OpenApiV3.IJsonSchema.IString =>
|
|
34
|
+
(schema as OpenApiV3.IJsonSchema.IString).type === "string";
|
|
35
|
+
|
|
36
|
+
export const isArray = (
|
|
37
|
+
schema: OpenApiV3.IJsonSchema,
|
|
38
|
+
): schema is OpenApiV3.IJsonSchema.IArray =>
|
|
39
|
+
(schema as OpenApiV3.IJsonSchema.IArray).type === "array";
|
|
40
|
+
|
|
41
|
+
export const isObject = (
|
|
42
|
+
schema: OpenApiV3.IJsonSchema,
|
|
43
|
+
): schema is OpenApiV3.IJsonSchema.IObject =>
|
|
44
|
+
(schema as OpenApiV3.IJsonSchema.IObject).type === "object";
|
|
45
|
+
|
|
46
|
+
export const isReference = (
|
|
47
|
+
schema: OpenApiV3.IJsonSchema,
|
|
48
|
+
): schema is OpenApiV3.IJsonSchema.IReference =>
|
|
49
|
+
(schema as OpenApiV3.IJsonSchema.IReference).$ref !== undefined;
|
|
50
|
+
|
|
51
|
+
export const isAllOf = (
|
|
52
|
+
schema: OpenApiV3.IJsonSchema,
|
|
53
|
+
): schema is OpenApiV3.IJsonSchema.IAllOf =>
|
|
54
|
+
(schema as OpenApiV3.IJsonSchema.IAllOf).allOf !== undefined;
|
|
55
|
+
|
|
56
|
+
export const isAnyOf = (
|
|
57
|
+
schema: OpenApiV3.IJsonSchema,
|
|
58
|
+
): schema is OpenApiV3.IJsonSchema.IAnyOf =>
|
|
59
|
+
(schema as OpenApiV3.IJsonSchema.IAnyOf).anyOf !== undefined;
|
|
60
|
+
|
|
61
|
+
export const isOneOf = (
|
|
62
|
+
schema: OpenApiV3.IJsonSchema,
|
|
63
|
+
): schema is OpenApiV3.IJsonSchema.IOneOf =>
|
|
64
|
+
(schema as OpenApiV3.IJsonSchema.IOneOf).oneOf !== undefined;
|
|
65
|
+
|
|
66
|
+
export const isNullOnly = (
|
|
67
|
+
schema: OpenApiV3.IJsonSchema,
|
|
68
|
+
): schema is OpenApiV3.IJsonSchema.INullOnly =>
|
|
69
|
+
(schema as OpenApiV3.IJsonSchema.INullOnly).type === "null";
|
|
70
|
+
}
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { OpenApiV3_1 } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Type checker for raw OpenAPI v3.1 JSON schemas.
|
|
5
|
-
*
|
|
6
|
-
* `OpenApiV3_1TypeChecker` provides type guard functions for
|
|
7
|
-
* {@link OpenApiV3_1.IJsonSchema} (raw, unemended format). For typia's
|
|
8
|
-
* normalized format, use {@link OpenApiTypeChecker} instead.
|
|
9
|
-
*
|
|
10
|
-
* Key v3.1 features: `const` keyword, `type` arrays (`["string", "null"]`),
|
|
11
|
-
* `prefixItems` for tuples, JSON Schema draft 2020-12 compatibility.
|
|
12
|
-
*
|
|
13
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
-
*/
|
|
15
|
-
export namespace OpenApiV3_1TypeChecker {
|
|
16
|
-
export const isConstant = (
|
|
17
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
18
|
-
): schema is OpenApiV3_1.IJsonSchema.IConstant =>
|
|
19
|
-
(schema as OpenApiV3_1.IJsonSchema.IConstant).const !== undefined;
|
|
20
|
-
|
|
21
|
-
export const isBoolean = (
|
|
22
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
23
|
-
): schema is OpenApiV3_1.IJsonSchema.IBoolean =>
|
|
24
|
-
(schema as OpenApiV3_1.IJsonSchema.IBoolean).type === "boolean";
|
|
25
|
-
|
|
26
|
-
export const isInteger = (
|
|
27
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
28
|
-
): schema is OpenApiV3_1.IJsonSchema.IInteger =>
|
|
29
|
-
(schema as OpenApiV3_1.IJsonSchema.IInteger).type === "integer";
|
|
30
|
-
|
|
31
|
-
export const isNumber = (
|
|
32
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
33
|
-
): schema is OpenApiV3_1.IJsonSchema.INumber =>
|
|
34
|
-
(schema as OpenApiV3_1.IJsonSchema.INumber).type === "number";
|
|
35
|
-
|
|
36
|
-
export const isString = (
|
|
37
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
38
|
-
): schema is OpenApiV3_1.IJsonSchema.IString =>
|
|
39
|
-
(schema as OpenApiV3_1.IJsonSchema.IString).type === "string";
|
|
40
|
-
|
|
41
|
-
export const isArray = (
|
|
42
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
43
|
-
): schema is OpenApiV3_1.IJsonSchema.IArray =>
|
|
44
|
-
(schema as OpenApiV3_1.IJsonSchema.IArray).type === "array";
|
|
45
|
-
|
|
46
|
-
export const isObject = (
|
|
47
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
48
|
-
): schema is OpenApiV3_1.IJsonSchema.IObject =>
|
|
49
|
-
(schema as OpenApiV3_1.IJsonSchema.IObject).type === "object";
|
|
50
|
-
|
|
51
|
-
export const isReference = (
|
|
52
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
53
|
-
): schema is OpenApiV3_1.IJsonSchema.IReference =>
|
|
54
|
-
(schema as OpenApiV3_1.IJsonSchema.IReference).$ref !== undefined;
|
|
55
|
-
|
|
56
|
-
export const isRecursiveReference = (
|
|
57
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
58
|
-
): schema is OpenApiV3_1.IJsonSchema.IRecursiveReference =>
|
|
59
|
-
(schema as OpenApiV3_1.IJsonSchema.IRecursiveReference).$recursiveRef !==
|
|
60
|
-
undefined;
|
|
61
|
-
|
|
62
|
-
export const isAllOf = (
|
|
63
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
64
|
-
): schema is OpenApiV3_1.IJsonSchema.IAllOf =>
|
|
65
|
-
(schema as OpenApiV3_1.IJsonSchema.IAllOf).allOf !== undefined;
|
|
66
|
-
|
|
67
|
-
export const isAnyOf = (
|
|
68
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
69
|
-
): schema is OpenApiV3_1.IJsonSchema.IAnyOf =>
|
|
70
|
-
(schema as OpenApiV3_1.IJsonSchema.IAnyOf).anyOf !== undefined;
|
|
71
|
-
|
|
72
|
-
export const isOneOf = (
|
|
73
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
74
|
-
): schema is OpenApiV3_1.IJsonSchema.IOneOf =>
|
|
75
|
-
(schema as OpenApiV3_1.IJsonSchema.IOneOf).oneOf !== undefined;
|
|
76
|
-
|
|
77
|
-
export const isNullOnly = (
|
|
78
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
79
|
-
): schema is OpenApiV3_1.IJsonSchema.INull =>
|
|
80
|
-
(schema as OpenApiV3_1.IJsonSchema.INull).type === "null";
|
|
81
|
-
|
|
82
|
-
export const isMixed = (
|
|
83
|
-
schema: OpenApiV3_1.IJsonSchema,
|
|
84
|
-
): schema is OpenApiV3_1.IJsonSchema.IMixed =>
|
|
85
|
-
Array.isArray((schema as OpenApiV3_1.IJsonSchema.IMixed).type);
|
|
86
|
-
}
|
|
1
|
+
import { OpenApiV3_1 } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type checker for raw OpenAPI v3.1 JSON schemas.
|
|
5
|
+
*
|
|
6
|
+
* `OpenApiV3_1TypeChecker` provides type guard functions for
|
|
7
|
+
* {@link OpenApiV3_1.IJsonSchema} (raw, unemended format). For typia's
|
|
8
|
+
* normalized format, use {@link OpenApiTypeChecker} instead.
|
|
9
|
+
*
|
|
10
|
+
* Key v3.1 features: `const` keyword, `type` arrays (`["string", "null"]`),
|
|
11
|
+
* `prefixItems` for tuples, JSON Schema draft 2020-12 compatibility.
|
|
12
|
+
*
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
*/
|
|
15
|
+
export namespace OpenApiV3_1TypeChecker {
|
|
16
|
+
export const isConstant = (
|
|
17
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
18
|
+
): schema is OpenApiV3_1.IJsonSchema.IConstant =>
|
|
19
|
+
(schema as OpenApiV3_1.IJsonSchema.IConstant).const !== undefined;
|
|
20
|
+
|
|
21
|
+
export const isBoolean = (
|
|
22
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
23
|
+
): schema is OpenApiV3_1.IJsonSchema.IBoolean =>
|
|
24
|
+
(schema as OpenApiV3_1.IJsonSchema.IBoolean).type === "boolean";
|
|
25
|
+
|
|
26
|
+
export const isInteger = (
|
|
27
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
28
|
+
): schema is OpenApiV3_1.IJsonSchema.IInteger =>
|
|
29
|
+
(schema as OpenApiV3_1.IJsonSchema.IInteger).type === "integer";
|
|
30
|
+
|
|
31
|
+
export const isNumber = (
|
|
32
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
33
|
+
): schema is OpenApiV3_1.IJsonSchema.INumber =>
|
|
34
|
+
(schema as OpenApiV3_1.IJsonSchema.INumber).type === "number";
|
|
35
|
+
|
|
36
|
+
export const isString = (
|
|
37
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
38
|
+
): schema is OpenApiV3_1.IJsonSchema.IString =>
|
|
39
|
+
(schema as OpenApiV3_1.IJsonSchema.IString).type === "string";
|
|
40
|
+
|
|
41
|
+
export const isArray = (
|
|
42
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
43
|
+
): schema is OpenApiV3_1.IJsonSchema.IArray =>
|
|
44
|
+
(schema as OpenApiV3_1.IJsonSchema.IArray).type === "array";
|
|
45
|
+
|
|
46
|
+
export const isObject = (
|
|
47
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
48
|
+
): schema is OpenApiV3_1.IJsonSchema.IObject =>
|
|
49
|
+
(schema as OpenApiV3_1.IJsonSchema.IObject).type === "object";
|
|
50
|
+
|
|
51
|
+
export const isReference = (
|
|
52
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
53
|
+
): schema is OpenApiV3_1.IJsonSchema.IReference =>
|
|
54
|
+
(schema as OpenApiV3_1.IJsonSchema.IReference).$ref !== undefined;
|
|
55
|
+
|
|
56
|
+
export const isRecursiveReference = (
|
|
57
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
58
|
+
): schema is OpenApiV3_1.IJsonSchema.IRecursiveReference =>
|
|
59
|
+
(schema as OpenApiV3_1.IJsonSchema.IRecursiveReference).$recursiveRef !==
|
|
60
|
+
undefined;
|
|
61
|
+
|
|
62
|
+
export const isAllOf = (
|
|
63
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
64
|
+
): schema is OpenApiV3_1.IJsonSchema.IAllOf =>
|
|
65
|
+
(schema as OpenApiV3_1.IJsonSchema.IAllOf).allOf !== undefined;
|
|
66
|
+
|
|
67
|
+
export const isAnyOf = (
|
|
68
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
69
|
+
): schema is OpenApiV3_1.IJsonSchema.IAnyOf =>
|
|
70
|
+
(schema as OpenApiV3_1.IJsonSchema.IAnyOf).anyOf !== undefined;
|
|
71
|
+
|
|
72
|
+
export const isOneOf = (
|
|
73
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
74
|
+
): schema is OpenApiV3_1.IJsonSchema.IOneOf =>
|
|
75
|
+
(schema as OpenApiV3_1.IJsonSchema.IOneOf).oneOf !== undefined;
|
|
76
|
+
|
|
77
|
+
export const isNullOnly = (
|
|
78
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
79
|
+
): schema is OpenApiV3_1.IJsonSchema.INull =>
|
|
80
|
+
(schema as OpenApiV3_1.IJsonSchema.INull).type === "null";
|
|
81
|
+
|
|
82
|
+
export const isMixed = (
|
|
83
|
+
schema: OpenApiV3_1.IJsonSchema,
|
|
84
|
+
): schema is OpenApiV3_1.IJsonSchema.IMixed =>
|
|
85
|
+
Array.isArray((schema as OpenApiV3_1.IJsonSchema.IMixed).type);
|
|
86
|
+
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import { IValidation, OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { OpenApiStationValidator } from "./internal/OpenApiStationValidator";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* OpenAPI JSON Schema validator.
|
|
7
|
-
*
|
|
8
|
-
* `OpenApiValidator` validates runtime data against {@link OpenApi.IJsonSchema}
|
|
9
|
-
* definitions. Returns {@link IValidation} with detailed error paths and
|
|
10
|
-
* expected types.
|
|
11
|
-
*
|
|
12
|
-
* Primary use case: Validating LLM-generated function call arguments. LLMs
|
|
13
|
-
* frequently make type errors (e.g., `"123"` instead of `123`). Use the
|
|
14
|
-
* validation errors to provide feedback and retry.
|
|
15
|
-
*
|
|
16
|
-
* Functions:
|
|
17
|
-
*
|
|
18
|
-
* - {@link create}: Create reusable validator function from schema
|
|
19
|
-
* - {@link validate}: One-shot validation with inline schema
|
|
20
|
-
*
|
|
21
|
-
* Set `equals: true` to reject objects with extra properties (strict mode).
|
|
22
|
-
*
|
|
23
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
24
|
-
*/
|
|
25
|
-
export namespace OpenApiValidator {
|
|
26
|
-
export const create =
|
|
27
|
-
(props: {
|
|
28
|
-
components: OpenApi.IComponents;
|
|
29
|
-
schema: OpenApi.IJsonSchema;
|
|
30
|
-
required: boolean;
|
|
31
|
-
equals?: boolean;
|
|
32
|
-
}) =>
|
|
33
|
-
(value: unknown): IValidation<unknown> =>
|
|
34
|
-
validate({ ...props, value });
|
|
35
|
-
|
|
36
|
-
export const validate = (props: {
|
|
37
|
-
components: OpenApi.IComponents;
|
|
38
|
-
schema: OpenApi.IJsonSchema;
|
|
39
|
-
value: unknown;
|
|
40
|
-
required: boolean;
|
|
41
|
-
equals?: boolean;
|
|
42
|
-
}): IValidation<unknown> => {
|
|
43
|
-
const errors: IValidation.IError[] = [];
|
|
44
|
-
OpenApiStationValidator.validate({
|
|
45
|
-
...props,
|
|
46
|
-
path: "$input",
|
|
47
|
-
exceptionable: true,
|
|
48
|
-
report: createReporter(errors),
|
|
49
|
-
equals: props.equals ?? false,
|
|
50
|
-
});
|
|
51
|
-
return errors.length === 0
|
|
52
|
-
? {
|
|
53
|
-
success: true,
|
|
54
|
-
data: props.value,
|
|
55
|
-
}
|
|
56
|
-
: {
|
|
57
|
-
success: false,
|
|
58
|
-
data: props.value,
|
|
59
|
-
errors,
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const createReporter = (array: IValidation.IError[]) => {
|
|
64
|
-
const reportable = (path: string): boolean => {
|
|
65
|
-
if (array.length === 0) return true;
|
|
66
|
-
const last: string = array[array.length - 1]!.path;
|
|
67
|
-
return (
|
|
68
|
-
path.length > last.length || last.substring(0, path.length) !== path
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
return (
|
|
72
|
-
error: IValidation.IError & {
|
|
73
|
-
exceptionable: boolean;
|
|
74
|
-
},
|
|
75
|
-
): false => {
|
|
76
|
-
if (error.exceptionable && reportable(error.path)) {
|
|
77
|
-
const info: IValidation.IError = {
|
|
78
|
-
path: error.path,
|
|
79
|
-
expected: error.expected,
|
|
80
|
-
value: error.value,
|
|
81
|
-
description: error.description,
|
|
82
|
-
};
|
|
83
|
-
if (error.value === undefined)
|
|
84
|
-
info.description ??= [
|
|
85
|
-
"The value at this path is `undefined`.",
|
|
86
|
-
"",
|
|
87
|
-
`Please fill the \`${error.expected}\` typed value next time.`,
|
|
88
|
-
].join("\n");
|
|
89
|
-
array.push(info);
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
}
|
|
1
|
+
import { IValidation, OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { OpenApiStationValidator } from "./internal/OpenApiStationValidator";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* OpenAPI JSON Schema validator.
|
|
7
|
+
*
|
|
8
|
+
* `OpenApiValidator` validates runtime data against {@link OpenApi.IJsonSchema}
|
|
9
|
+
* definitions. Returns {@link IValidation} with detailed error paths and
|
|
10
|
+
* expected types.
|
|
11
|
+
*
|
|
12
|
+
* Primary use case: Validating LLM-generated function call arguments. LLMs
|
|
13
|
+
* frequently make type errors (e.g., `"123"` instead of `123`). Use the
|
|
14
|
+
* validation errors to provide feedback and retry.
|
|
15
|
+
*
|
|
16
|
+
* Functions:
|
|
17
|
+
*
|
|
18
|
+
* - {@link create}: Create reusable validator function from schema
|
|
19
|
+
* - {@link validate}: One-shot validation with inline schema
|
|
20
|
+
*
|
|
21
|
+
* Set `equals: true` to reject objects with extra properties (strict mode).
|
|
22
|
+
*
|
|
23
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
24
|
+
*/
|
|
25
|
+
export namespace OpenApiValidator {
|
|
26
|
+
export const create =
|
|
27
|
+
(props: {
|
|
28
|
+
components: OpenApi.IComponents;
|
|
29
|
+
schema: OpenApi.IJsonSchema;
|
|
30
|
+
required: boolean;
|
|
31
|
+
equals?: boolean;
|
|
32
|
+
}) =>
|
|
33
|
+
(value: unknown): IValidation<unknown> =>
|
|
34
|
+
validate({ ...props, value });
|
|
35
|
+
|
|
36
|
+
export const validate = (props: {
|
|
37
|
+
components: OpenApi.IComponents;
|
|
38
|
+
schema: OpenApi.IJsonSchema;
|
|
39
|
+
value: unknown;
|
|
40
|
+
required: boolean;
|
|
41
|
+
equals?: boolean;
|
|
42
|
+
}): IValidation<unknown> => {
|
|
43
|
+
const errors: IValidation.IError[] = [];
|
|
44
|
+
OpenApiStationValidator.validate({
|
|
45
|
+
...props,
|
|
46
|
+
path: "$input",
|
|
47
|
+
exceptionable: true,
|
|
48
|
+
report: createReporter(errors),
|
|
49
|
+
equals: props.equals ?? false,
|
|
50
|
+
});
|
|
51
|
+
return errors.length === 0
|
|
52
|
+
? {
|
|
53
|
+
success: true,
|
|
54
|
+
data: props.value,
|
|
55
|
+
}
|
|
56
|
+
: {
|
|
57
|
+
success: false,
|
|
58
|
+
data: props.value,
|
|
59
|
+
errors,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const createReporter = (array: IValidation.IError[]) => {
|
|
64
|
+
const reportable = (path: string): boolean => {
|
|
65
|
+
if (array.length === 0) return true;
|
|
66
|
+
const last: string = array[array.length - 1]!.path;
|
|
67
|
+
return (
|
|
68
|
+
path.length > last.length || last.substring(0, path.length) !== path
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
return (
|
|
72
|
+
error: IValidation.IError & {
|
|
73
|
+
exceptionable: boolean;
|
|
74
|
+
},
|
|
75
|
+
): false => {
|
|
76
|
+
if (error.exceptionable && reportable(error.path)) {
|
|
77
|
+
const info: IValidation.IError = {
|
|
78
|
+
path: error.path,
|
|
79
|
+
expected: error.expected,
|
|
80
|
+
value: error.value,
|
|
81
|
+
description: error.description,
|
|
82
|
+
};
|
|
83
|
+
if (error.value === undefined)
|
|
84
|
+
info.description ??= [
|
|
85
|
+
"The value at this path is `undefined`.",
|
|
86
|
+
"",
|
|
87
|
+
`Please fill the \`${error.expected}\` typed value next time.`,
|
|
88
|
+
].join("\n");
|
|
89
|
+
array.push(info);
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { SwaggerV2 } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Type checker for Swagger v2.0 (OpenAPI v2) JSON schemas.
|
|
5
|
-
*
|
|
6
|
-
* `SwaggerV2TypeChecker` provides type guard functions for
|
|
7
|
-
* {@link SwaggerV2.IJsonSchema}. For typia's normalized format, use
|
|
8
|
-
* {@link OpenApiTypeChecker} instead.
|
|
9
|
-
*
|
|
10
|
-
* Key limitations vs OpenAPI v3.x: No `oneOf`/`anyOf`, no `nullable`, uses
|
|
11
|
-
* `definitions` instead of `components.schemas`, body parameters use `in:
|
|
12
|
-
* "body"` with `schema` property.
|
|
13
|
-
*
|
|
14
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
-
*/
|
|
16
|
-
export namespace SwaggerV2TypeChecker {
|
|
17
|
-
export const isBoolean = (
|
|
18
|
-
schema: SwaggerV2.IJsonSchema,
|
|
19
|
-
): schema is SwaggerV2.IJsonSchema.IBoolean =>
|
|
20
|
-
(schema as SwaggerV2.IJsonSchema.IBoolean).type === "boolean";
|
|
21
|
-
|
|
22
|
-
export const isInteger = (
|
|
23
|
-
schema: SwaggerV2.IJsonSchema,
|
|
24
|
-
): schema is SwaggerV2.IJsonSchema.IInteger =>
|
|
25
|
-
(schema as SwaggerV2.IJsonSchema.IInteger).type === "integer";
|
|
26
|
-
|
|
27
|
-
export const isNumber = (
|
|
28
|
-
schema: SwaggerV2.IJsonSchema,
|
|
29
|
-
): schema is SwaggerV2.IJsonSchema.INumber =>
|
|
30
|
-
(schema as SwaggerV2.IJsonSchema.INumber).type === "number";
|
|
31
|
-
|
|
32
|
-
export const isString = (
|
|
33
|
-
schema: SwaggerV2.IJsonSchema,
|
|
34
|
-
): schema is SwaggerV2.IJsonSchema.IString =>
|
|
35
|
-
(schema as SwaggerV2.IJsonSchema.IString).type === "string";
|
|
36
|
-
|
|
37
|
-
export const isArray = (
|
|
38
|
-
schema: SwaggerV2.IJsonSchema,
|
|
39
|
-
): schema is SwaggerV2.IJsonSchema.IArray =>
|
|
40
|
-
(schema as SwaggerV2.IJsonSchema.IArray).type === "array";
|
|
41
|
-
|
|
42
|
-
export const isObject = (
|
|
43
|
-
schema: SwaggerV2.IJsonSchema,
|
|
44
|
-
): schema is SwaggerV2.IJsonSchema.IObject =>
|
|
45
|
-
(schema as SwaggerV2.IJsonSchema.IObject).type === "object";
|
|
46
|
-
|
|
47
|
-
export const isReference = (
|
|
48
|
-
schema: SwaggerV2.IJsonSchema,
|
|
49
|
-
): schema is SwaggerV2.IJsonSchema.IReference =>
|
|
50
|
-
(schema as SwaggerV2.IJsonSchema.IReference).$ref !== undefined;
|
|
51
|
-
|
|
52
|
-
export const isAllOf = (
|
|
53
|
-
schema: SwaggerV2.IJsonSchema,
|
|
54
|
-
): schema is SwaggerV2.IJsonSchema.IAllOf =>
|
|
55
|
-
(schema as SwaggerV2.IJsonSchema.IAllOf).allOf !== undefined;
|
|
56
|
-
|
|
57
|
-
export const isOneOf = (
|
|
58
|
-
schema: SwaggerV2.IJsonSchema,
|
|
59
|
-
): schema is SwaggerV2.IJsonSchema.IOneOf =>
|
|
60
|
-
(schema as SwaggerV2.IJsonSchema.IOneOf)["x-oneOf"] !== undefined;
|
|
61
|
-
|
|
62
|
-
export const isAnyOf = (
|
|
63
|
-
schema: SwaggerV2.IJsonSchema,
|
|
64
|
-
): schema is SwaggerV2.IJsonSchema.IAnyOf =>
|
|
65
|
-
(schema as SwaggerV2.IJsonSchema.IAnyOf)["x-anyOf"] !== undefined;
|
|
66
|
-
|
|
67
|
-
export const isNullOnly = (
|
|
68
|
-
schema: SwaggerV2.IJsonSchema,
|
|
69
|
-
): schema is SwaggerV2.IJsonSchema.INullOnly =>
|
|
70
|
-
(schema as SwaggerV2.IJsonSchema.INullOnly).type === "null";
|
|
71
|
-
}
|
|
1
|
+
import { SwaggerV2 } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type checker for Swagger v2.0 (OpenAPI v2) JSON schemas.
|
|
5
|
+
*
|
|
6
|
+
* `SwaggerV2TypeChecker` provides type guard functions for
|
|
7
|
+
* {@link SwaggerV2.IJsonSchema}. For typia's normalized format, use
|
|
8
|
+
* {@link OpenApiTypeChecker} instead.
|
|
9
|
+
*
|
|
10
|
+
* Key limitations vs OpenAPI v3.x: No `oneOf`/`anyOf`, no `nullable`, uses
|
|
11
|
+
* `definitions` instead of `components.schemas`, body parameters use `in:
|
|
12
|
+
* "body"` with `schema` property.
|
|
13
|
+
*
|
|
14
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
+
*/
|
|
16
|
+
export namespace SwaggerV2TypeChecker {
|
|
17
|
+
export const isBoolean = (
|
|
18
|
+
schema: SwaggerV2.IJsonSchema,
|
|
19
|
+
): schema is SwaggerV2.IJsonSchema.IBoolean =>
|
|
20
|
+
(schema as SwaggerV2.IJsonSchema.IBoolean).type === "boolean";
|
|
21
|
+
|
|
22
|
+
export const isInteger = (
|
|
23
|
+
schema: SwaggerV2.IJsonSchema,
|
|
24
|
+
): schema is SwaggerV2.IJsonSchema.IInteger =>
|
|
25
|
+
(schema as SwaggerV2.IJsonSchema.IInteger).type === "integer";
|
|
26
|
+
|
|
27
|
+
export const isNumber = (
|
|
28
|
+
schema: SwaggerV2.IJsonSchema,
|
|
29
|
+
): schema is SwaggerV2.IJsonSchema.INumber =>
|
|
30
|
+
(schema as SwaggerV2.IJsonSchema.INumber).type === "number";
|
|
31
|
+
|
|
32
|
+
export const isString = (
|
|
33
|
+
schema: SwaggerV2.IJsonSchema,
|
|
34
|
+
): schema is SwaggerV2.IJsonSchema.IString =>
|
|
35
|
+
(schema as SwaggerV2.IJsonSchema.IString).type === "string";
|
|
36
|
+
|
|
37
|
+
export const isArray = (
|
|
38
|
+
schema: SwaggerV2.IJsonSchema,
|
|
39
|
+
): schema is SwaggerV2.IJsonSchema.IArray =>
|
|
40
|
+
(schema as SwaggerV2.IJsonSchema.IArray).type === "array";
|
|
41
|
+
|
|
42
|
+
export const isObject = (
|
|
43
|
+
schema: SwaggerV2.IJsonSchema,
|
|
44
|
+
): schema is SwaggerV2.IJsonSchema.IObject =>
|
|
45
|
+
(schema as SwaggerV2.IJsonSchema.IObject).type === "object";
|
|
46
|
+
|
|
47
|
+
export const isReference = (
|
|
48
|
+
schema: SwaggerV2.IJsonSchema,
|
|
49
|
+
): schema is SwaggerV2.IJsonSchema.IReference =>
|
|
50
|
+
(schema as SwaggerV2.IJsonSchema.IReference).$ref !== undefined;
|
|
51
|
+
|
|
52
|
+
export const isAllOf = (
|
|
53
|
+
schema: SwaggerV2.IJsonSchema,
|
|
54
|
+
): schema is SwaggerV2.IJsonSchema.IAllOf =>
|
|
55
|
+
(schema as SwaggerV2.IJsonSchema.IAllOf).allOf !== undefined;
|
|
56
|
+
|
|
57
|
+
export const isOneOf = (
|
|
58
|
+
schema: SwaggerV2.IJsonSchema,
|
|
59
|
+
): schema is SwaggerV2.IJsonSchema.IOneOf =>
|
|
60
|
+
(schema as SwaggerV2.IJsonSchema.IOneOf)["x-oneOf"] !== undefined;
|
|
61
|
+
|
|
62
|
+
export const isAnyOf = (
|
|
63
|
+
schema: SwaggerV2.IJsonSchema,
|
|
64
|
+
): schema is SwaggerV2.IJsonSchema.IAnyOf =>
|
|
65
|
+
(schema as SwaggerV2.IJsonSchema.IAnyOf)["x-anyOf"] !== undefined;
|
|
66
|
+
|
|
67
|
+
export const isNullOnly = (
|
|
68
|
+
schema: SwaggerV2.IJsonSchema,
|
|
69
|
+
): schema is SwaggerV2.IJsonSchema.INullOnly =>
|
|
70
|
+
(schema as SwaggerV2.IJsonSchema.INullOnly).type === "null";
|
|
71
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export const _isBigintString = (str: string): boolean => {
|
|
2
|
-
try {
|
|
3
|
-
BigInt(str);
|
|
4
|
-
return true;
|
|
5
|
-
} catch {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
1
|
+
export const _isBigintString = (str: string): boolean => {
|
|
2
|
+
try {
|
|
3
|
+
BigInt(str);
|
|
4
|
+
return true;
|
|
5
|
+
} catch {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
};
|