@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.
Files changed (92) hide show
  1. package/lib/http/internal/HttpLlmApplicationComposer.mjs +5 -1
  2. package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
  3. package/lib/index.mjs +9 -9
  4. package/lib/utils/LlmJson.mjs +9 -2
  5. package/lib/utils/LlmJson.mjs.map +1 -1
  6. package/lib/utils/internal/stringifyValidationFailure.js +17 -15
  7. package/lib/utils/internal/stringifyValidationFailure.js.map +1 -1
  8. package/lib/utils/internal/stringifyValidationFailure.mjs +17 -15
  9. package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
  10. package/lib/validators/internal/OpenApiOneOfValidator.mjs +5 -1
  11. package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
  12. package/package.json +2 -2
  13. package/src/converters/LlmSchemaConverter.ts +647 -647
  14. package/src/converters/OpenApiConverter.ts +285 -285
  15. package/src/converters/index.ts +5 -5
  16. package/src/converters/internal/LlmDescriptionInverter.ts +178 -178
  17. package/src/converters/internal/LlmParametersComposer.ts +52 -52
  18. package/src/converters/internal/OpenApiConstraintShifter.ts +154 -154
  19. package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -46
  20. package/src/converters/internal/OpenApiV3Downgrader.ts +355 -355
  21. package/src/converters/internal/OpenApiV3Upgrader.ts +470 -470
  22. package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -685
  23. package/src/converters/internal/SwaggerV2Downgrader.ts +424 -424
  24. package/src/converters/internal/SwaggerV2Upgrader.ts +523 -523
  25. package/src/http/HttpError.ts +107 -107
  26. package/src/http/HttpLlm.ts +167 -167
  27. package/src/http/HttpMigration.ts +92 -92
  28. package/src/http/index.ts +3 -3
  29. package/src/http/internal/HttpLlmApplicationComposer.ts +361 -361
  30. package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -37
  31. package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -56
  32. package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -135
  33. package/src/http/internal/HttpMigrateRouteComposer.ts +505 -505
  34. package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -203
  35. package/src/index.ts +4 -4
  36. package/src/utils/ArrayUtil.ts +42 -42
  37. package/src/utils/LlmJson.ts +141 -141
  38. package/src/utils/MapUtil.ts +15 -15
  39. package/src/utils/NamingConvention.ts +205 -205
  40. package/src/utils/Singleton.ts +17 -17
  41. package/src/utils/StringUtil.ts +14 -14
  42. package/src/utils/dedent.ts +57 -57
  43. package/src/utils/index.ts +8 -8
  44. package/src/utils/internal/EndpointUtil.ts +44 -44
  45. package/src/utils/internal/JsonDescriptor.ts +70 -70
  46. package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -822
  47. package/src/utils/internal/coerceLlmArguments.ts +314 -314
  48. package/src/utils/internal/parseLenientJson.ts +894 -894
  49. package/src/utils/internal/stringifyValidationFailure.ts +415 -411
  50. package/src/validators/LlmTypeChecker.ts +402 -402
  51. package/src/validators/OpenApiTypeChecker.ts +297 -297
  52. package/src/validators/OpenApiV3TypeChecker.ts +70 -70
  53. package/src/validators/OpenApiV3_1TypeChecker.ts +86 -86
  54. package/src/validators/OpenApiValidator.ts +94 -94
  55. package/src/validators/SwaggerV2TypeChecker.ts +71 -71
  56. package/src/validators/functional/_isBigintString.ts +8 -8
  57. package/src/validators/functional/_isFormatByte.ts +7 -7
  58. package/src/validators/functional/_isFormatDate.ts +3 -3
  59. package/src/validators/functional/_isFormatDateTime.ts +4 -4
  60. package/src/validators/functional/_isFormatDuration.ts +4 -4
  61. package/src/validators/functional/_isFormatEmail.ts +4 -4
  62. package/src/validators/functional/_isFormatHostname.ts +4 -4
  63. package/src/validators/functional/_isFormatIdnEmail.ts +4 -4
  64. package/src/validators/functional/_isFormatIdnHostname.ts +4 -4
  65. package/src/validators/functional/_isFormatIpv4.ts +4 -4
  66. package/src/validators/functional/_isFormatIpv6.ts +4 -4
  67. package/src/validators/functional/_isFormatIri.ts +3 -3
  68. package/src/validators/functional/_isFormatIriReference.ts +4 -4
  69. package/src/validators/functional/_isFormatJsonPointer.ts +3 -3
  70. package/src/validators/functional/_isFormatPassword.ts +1 -1
  71. package/src/validators/functional/_isFormatRegex.ts +8 -8
  72. package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -4
  73. package/src/validators/functional/_isFormatTime.ts +4 -4
  74. package/src/validators/functional/_isFormatUri.ts +6 -6
  75. package/src/validators/functional/_isFormatUriReference.ts +5 -5
  76. package/src/validators/functional/_isFormatUriTemplate.ts +4 -4
  77. package/src/validators/functional/_isFormatUrl.ts +4 -4
  78. package/src/validators/functional/_isFormatUuid.ts +3 -3
  79. package/src/validators/functional/_isUniqueItems.ts +159 -159
  80. package/src/validators/index.ts +14 -14
  81. package/src/validators/internal/IOpenApiValidatorContext.ts +17 -17
  82. package/src/validators/internal/OpenApiArrayValidator.ts +49 -49
  83. package/src/validators/internal/OpenApiBooleanValidator.ts +11 -11
  84. package/src/validators/internal/OpenApiConstantValidator.ts +11 -11
  85. package/src/validators/internal/OpenApiIntegerValidator.ts +49 -49
  86. package/src/validators/internal/OpenApiNumberValidator.ts +48 -48
  87. package/src/validators/internal/OpenApiObjectValidator.ts +83 -83
  88. package/src/validators/internal/OpenApiOneOfValidator.ts +309 -309
  89. package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -124
  90. package/src/validators/internal/OpenApiStationValidator.ts +115 -115
  91. package/src/validators/internal/OpenApiStringValidator.ts +88 -88
  92. 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
+ };