@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,49 +1,49 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { _isUniqueItems } from "../functional/_isUniqueItems";
|
|
4
|
-
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
5
|
-
import { OpenApiStationValidator } from "./OpenApiStationValidator";
|
|
6
|
-
|
|
7
|
-
export namespace OpenApiArrayValidator {
|
|
8
|
-
export const validate = (
|
|
9
|
-
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IArray>,
|
|
10
|
-
): boolean => {
|
|
11
|
-
if (Array.isArray(ctx.value) === false) return ctx.report(ctx);
|
|
12
|
-
return [
|
|
13
|
-
ctx.value
|
|
14
|
-
.map((value, i) =>
|
|
15
|
-
OpenApiStationValidator.validate({
|
|
16
|
-
...ctx,
|
|
17
|
-
schema: ctx.schema.items,
|
|
18
|
-
value,
|
|
19
|
-
path: `${ctx.path}[${i}]`,
|
|
20
|
-
required: true,
|
|
21
|
-
}),
|
|
22
|
-
)
|
|
23
|
-
.every((v) => v),
|
|
24
|
-
ctx.schema.minItems !== undefined
|
|
25
|
-
? ctx.value.length >= ctx.schema.minItems ||
|
|
26
|
-
ctx.report({
|
|
27
|
-
...ctx,
|
|
28
|
-
expected: `Array<> & MinItems<${ctx.schema.minItems}>`,
|
|
29
|
-
})
|
|
30
|
-
: true,
|
|
31
|
-
ctx.schema.maxItems !== undefined
|
|
32
|
-
? ctx.value.length <= ctx.schema.maxItems ||
|
|
33
|
-
ctx.report({
|
|
34
|
-
...ctx,
|
|
35
|
-
expected: `Array<> & MaxItems<${ctx.schema.maxItems}>`,
|
|
36
|
-
})
|
|
37
|
-
: true,
|
|
38
|
-
ctx.schema.uniqueItems !== undefined
|
|
39
|
-
? ctx.schema.uniqueItems
|
|
40
|
-
? _isUniqueItems(ctx.value) ||
|
|
41
|
-
ctx.report({
|
|
42
|
-
...ctx,
|
|
43
|
-
expected: `Array<> & UniqueItems`,
|
|
44
|
-
})
|
|
45
|
-
: true
|
|
46
|
-
: true,
|
|
47
|
-
].every((v) => v);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { _isUniqueItems } from "../functional/_isUniqueItems";
|
|
4
|
+
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
5
|
+
import { OpenApiStationValidator } from "./OpenApiStationValidator";
|
|
6
|
+
|
|
7
|
+
export namespace OpenApiArrayValidator {
|
|
8
|
+
export const validate = (
|
|
9
|
+
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IArray>,
|
|
10
|
+
): boolean => {
|
|
11
|
+
if (Array.isArray(ctx.value) === false) return ctx.report(ctx);
|
|
12
|
+
return [
|
|
13
|
+
ctx.value
|
|
14
|
+
.map((value, i) =>
|
|
15
|
+
OpenApiStationValidator.validate({
|
|
16
|
+
...ctx,
|
|
17
|
+
schema: ctx.schema.items,
|
|
18
|
+
value,
|
|
19
|
+
path: `${ctx.path}[${i}]`,
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
)
|
|
23
|
+
.every((v) => v),
|
|
24
|
+
ctx.schema.minItems !== undefined
|
|
25
|
+
? ctx.value.length >= ctx.schema.minItems ||
|
|
26
|
+
ctx.report({
|
|
27
|
+
...ctx,
|
|
28
|
+
expected: `Array<> & MinItems<${ctx.schema.minItems}>`,
|
|
29
|
+
})
|
|
30
|
+
: true,
|
|
31
|
+
ctx.schema.maxItems !== undefined
|
|
32
|
+
? ctx.value.length <= ctx.schema.maxItems ||
|
|
33
|
+
ctx.report({
|
|
34
|
+
...ctx,
|
|
35
|
+
expected: `Array<> & MaxItems<${ctx.schema.maxItems}>`,
|
|
36
|
+
})
|
|
37
|
+
: true,
|
|
38
|
+
ctx.schema.uniqueItems !== undefined
|
|
39
|
+
? ctx.schema.uniqueItems
|
|
40
|
+
? _isUniqueItems(ctx.value) ||
|
|
41
|
+
ctx.report({
|
|
42
|
+
...ctx,
|
|
43
|
+
expected: `Array<> & UniqueItems`,
|
|
44
|
+
})
|
|
45
|
+
: true
|
|
46
|
+
: true,
|
|
47
|
+
].every((v) => v);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
4
|
-
|
|
5
|
-
export namespace OpenApiBooleanValidator {
|
|
6
|
-
export const validate = (
|
|
7
|
-
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IBoolean>,
|
|
8
|
-
): boolean => {
|
|
9
|
-
return typeof ctx.value === "boolean" || ctx.report(ctx);
|
|
10
|
-
};
|
|
11
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
4
|
+
|
|
5
|
+
export namespace OpenApiBooleanValidator {
|
|
6
|
+
export const validate = (
|
|
7
|
+
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IBoolean>,
|
|
8
|
+
): boolean => {
|
|
9
|
+
return typeof ctx.value === "boolean" || ctx.report(ctx);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
4
|
-
|
|
5
|
-
export namespace OpenApiConstantValidator {
|
|
6
|
-
export const validate = (
|
|
7
|
-
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IConstant>,
|
|
8
|
-
): boolean => {
|
|
9
|
-
return ctx.value === ctx.schema.const || ctx.report(ctx);
|
|
10
|
-
};
|
|
11
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
4
|
+
|
|
5
|
+
export namespace OpenApiConstantValidator {
|
|
6
|
+
export const validate = (
|
|
7
|
+
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IConstant>,
|
|
8
|
+
): boolean => {
|
|
9
|
+
return ctx.value === ctx.schema.const || ctx.report(ctx);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
4
|
-
|
|
5
|
-
export namespace OpenApiIntegerValidator {
|
|
6
|
-
export const validate = (
|
|
7
|
-
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IInteger>,
|
|
8
|
-
): boolean => {
|
|
9
|
-
if (typeof ctx.value !== "number" || Math.floor(ctx.value) !== ctx.value)
|
|
10
|
-
return ctx.report(ctx);
|
|
11
|
-
return [
|
|
12
|
-
ctx.schema.minimum !== undefined
|
|
13
|
-
? ctx.value >= ctx.schema.minimum ||
|
|
14
|
-
ctx.report({
|
|
15
|
-
...ctx,
|
|
16
|
-
expected: `number & Type<"int32"> & Minimum<${ctx.schema.minimum}>`,
|
|
17
|
-
})
|
|
18
|
-
: true,
|
|
19
|
-
ctx.schema.maximum !== undefined
|
|
20
|
-
? ctx.value <= ctx.schema.maximum ||
|
|
21
|
-
ctx.report({
|
|
22
|
-
...ctx,
|
|
23
|
-
expected: `number & Type<"int32"> & Maximum<${ctx.schema.maximum}>`,
|
|
24
|
-
})
|
|
25
|
-
: true,
|
|
26
|
-
ctx.schema.exclusiveMinimum !== undefined
|
|
27
|
-
? ctx.value > ctx.schema.exclusiveMinimum ||
|
|
28
|
-
ctx.report({
|
|
29
|
-
...ctx,
|
|
30
|
-
expected: `number & Type<"int32"> & ExclusiveMinimum<${ctx.schema.exclusiveMinimum}>`,
|
|
31
|
-
})
|
|
32
|
-
: true,
|
|
33
|
-
ctx.schema.exclusiveMaximum !== undefined
|
|
34
|
-
? ctx.value < ctx.schema.exclusiveMaximum ||
|
|
35
|
-
ctx.report({
|
|
36
|
-
...ctx,
|
|
37
|
-
expected: `number & Type<"int32"> & ExclusiveMaximum<${ctx.schema.exclusiveMaximum}>`,
|
|
38
|
-
})
|
|
39
|
-
: true,
|
|
40
|
-
ctx.schema.multipleOf !== undefined
|
|
41
|
-
? ctx.value % ctx.schema.multipleOf === 0 ||
|
|
42
|
-
ctx.report({
|
|
43
|
-
...ctx,
|
|
44
|
-
expected: `number & Type<"int32"> & MultipleOf<${ctx.schema.multipleOf}>`,
|
|
45
|
-
})
|
|
46
|
-
: true,
|
|
47
|
-
].every((v) => v);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
4
|
+
|
|
5
|
+
export namespace OpenApiIntegerValidator {
|
|
6
|
+
export const validate = (
|
|
7
|
+
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IInteger>,
|
|
8
|
+
): boolean => {
|
|
9
|
+
if (typeof ctx.value !== "number" || Math.floor(ctx.value) !== ctx.value)
|
|
10
|
+
return ctx.report(ctx);
|
|
11
|
+
return [
|
|
12
|
+
ctx.schema.minimum !== undefined
|
|
13
|
+
? ctx.value >= ctx.schema.minimum ||
|
|
14
|
+
ctx.report({
|
|
15
|
+
...ctx,
|
|
16
|
+
expected: `number & Type<"int32"> & Minimum<${ctx.schema.minimum}>`,
|
|
17
|
+
})
|
|
18
|
+
: true,
|
|
19
|
+
ctx.schema.maximum !== undefined
|
|
20
|
+
? ctx.value <= ctx.schema.maximum ||
|
|
21
|
+
ctx.report({
|
|
22
|
+
...ctx,
|
|
23
|
+
expected: `number & Type<"int32"> & Maximum<${ctx.schema.maximum}>`,
|
|
24
|
+
})
|
|
25
|
+
: true,
|
|
26
|
+
ctx.schema.exclusiveMinimum !== undefined
|
|
27
|
+
? ctx.value > ctx.schema.exclusiveMinimum ||
|
|
28
|
+
ctx.report({
|
|
29
|
+
...ctx,
|
|
30
|
+
expected: `number & Type<"int32"> & ExclusiveMinimum<${ctx.schema.exclusiveMinimum}>`,
|
|
31
|
+
})
|
|
32
|
+
: true,
|
|
33
|
+
ctx.schema.exclusiveMaximum !== undefined
|
|
34
|
+
? ctx.value < ctx.schema.exclusiveMaximum ||
|
|
35
|
+
ctx.report({
|
|
36
|
+
...ctx,
|
|
37
|
+
expected: `number & Type<"int32"> & ExclusiveMaximum<${ctx.schema.exclusiveMaximum}>`,
|
|
38
|
+
})
|
|
39
|
+
: true,
|
|
40
|
+
ctx.schema.multipleOf !== undefined
|
|
41
|
+
? ctx.value % ctx.schema.multipleOf === 0 ||
|
|
42
|
+
ctx.report({
|
|
43
|
+
...ctx,
|
|
44
|
+
expected: `number & Type<"int32"> & MultipleOf<${ctx.schema.multipleOf}>`,
|
|
45
|
+
})
|
|
46
|
+
: true,
|
|
47
|
+
].every((v) => v);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
4
|
-
|
|
5
|
-
export namespace OpenApiNumberValidator {
|
|
6
|
-
export const validate = (
|
|
7
|
-
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.INumber>,
|
|
8
|
-
): boolean => {
|
|
9
|
-
if (typeof ctx.value !== "number") return ctx.report(ctx);
|
|
10
|
-
return [
|
|
11
|
-
ctx.schema.minimum !== undefined
|
|
12
|
-
? ctx.value >= ctx.schema.minimum ||
|
|
13
|
-
ctx.report({
|
|
14
|
-
...ctx,
|
|
15
|
-
expected: `number & Minimum<${ctx.schema.minimum}>`,
|
|
16
|
-
})
|
|
17
|
-
: true,
|
|
18
|
-
ctx.schema.maximum !== undefined
|
|
19
|
-
? ctx.value <= ctx.schema.maximum ||
|
|
20
|
-
ctx.report({
|
|
21
|
-
...ctx,
|
|
22
|
-
expected: `number & Maximum<${ctx.schema.maximum}>`,
|
|
23
|
-
})
|
|
24
|
-
: true,
|
|
25
|
-
ctx.schema.exclusiveMinimum !== undefined
|
|
26
|
-
? ctx.value > ctx.schema.exclusiveMinimum ||
|
|
27
|
-
ctx.report({
|
|
28
|
-
...ctx,
|
|
29
|
-
expected: `number & ExclusiveMinimum<${ctx.schema.exclusiveMinimum}>`,
|
|
30
|
-
})
|
|
31
|
-
: true,
|
|
32
|
-
ctx.schema.exclusiveMaximum !== undefined
|
|
33
|
-
? ctx.value < ctx.schema.exclusiveMaximum ||
|
|
34
|
-
ctx.report({
|
|
35
|
-
...ctx,
|
|
36
|
-
expected: `number & ExclusiveMaximum<${ctx.schema.exclusiveMaximum}>`,
|
|
37
|
-
})
|
|
38
|
-
: true,
|
|
39
|
-
ctx.schema.multipleOf !== undefined
|
|
40
|
-
? ctx.value % ctx.schema.multipleOf === 0 ||
|
|
41
|
-
ctx.report({
|
|
42
|
-
...ctx,
|
|
43
|
-
expected: `number & MultipleOf<${ctx.schema.multipleOf}>`,
|
|
44
|
-
})
|
|
45
|
-
: true,
|
|
46
|
-
].every((v) => v);
|
|
47
|
-
};
|
|
48
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
4
|
+
|
|
5
|
+
export namespace OpenApiNumberValidator {
|
|
6
|
+
export const validate = (
|
|
7
|
+
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.INumber>,
|
|
8
|
+
): boolean => {
|
|
9
|
+
if (typeof ctx.value !== "number") return ctx.report(ctx);
|
|
10
|
+
return [
|
|
11
|
+
ctx.schema.minimum !== undefined
|
|
12
|
+
? ctx.value >= ctx.schema.minimum ||
|
|
13
|
+
ctx.report({
|
|
14
|
+
...ctx,
|
|
15
|
+
expected: `number & Minimum<${ctx.schema.minimum}>`,
|
|
16
|
+
})
|
|
17
|
+
: true,
|
|
18
|
+
ctx.schema.maximum !== undefined
|
|
19
|
+
? ctx.value <= ctx.schema.maximum ||
|
|
20
|
+
ctx.report({
|
|
21
|
+
...ctx,
|
|
22
|
+
expected: `number & Maximum<${ctx.schema.maximum}>`,
|
|
23
|
+
})
|
|
24
|
+
: true,
|
|
25
|
+
ctx.schema.exclusiveMinimum !== undefined
|
|
26
|
+
? ctx.value > ctx.schema.exclusiveMinimum ||
|
|
27
|
+
ctx.report({
|
|
28
|
+
...ctx,
|
|
29
|
+
expected: `number & ExclusiveMinimum<${ctx.schema.exclusiveMinimum}>`,
|
|
30
|
+
})
|
|
31
|
+
: true,
|
|
32
|
+
ctx.schema.exclusiveMaximum !== undefined
|
|
33
|
+
? ctx.value < ctx.schema.exclusiveMaximum ||
|
|
34
|
+
ctx.report({
|
|
35
|
+
...ctx,
|
|
36
|
+
expected: `number & ExclusiveMaximum<${ctx.schema.exclusiveMaximum}>`,
|
|
37
|
+
})
|
|
38
|
+
: true,
|
|
39
|
+
ctx.schema.multipleOf !== undefined
|
|
40
|
+
? ctx.value % ctx.schema.multipleOf === 0 ||
|
|
41
|
+
ctx.report({
|
|
42
|
+
...ctx,
|
|
43
|
+
expected: `number & MultipleOf<${ctx.schema.multipleOf}>`,
|
|
44
|
+
})
|
|
45
|
+
: true,
|
|
46
|
+
].every((v) => v);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { NamingConvention } from "../../utils/NamingConvention";
|
|
4
|
-
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
5
|
-
import { OpenApiStationValidator } from "./OpenApiStationValidator";
|
|
6
|
-
|
|
7
|
-
export namespace OpenApiObjectValidator {
|
|
8
|
-
export const validate = (
|
|
9
|
-
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IObject>,
|
|
10
|
-
): boolean => {
|
|
11
|
-
if (typeof ctx.value !== "object" || ctx.value === null)
|
|
12
|
-
return ctx.report(ctx);
|
|
13
|
-
return [
|
|
14
|
-
...Object.entries(ctx.schema.properties ?? {}).map(([key, value]) =>
|
|
15
|
-
OpenApiStationValidator.validate({
|
|
16
|
-
...ctx,
|
|
17
|
-
schema: value,
|
|
18
|
-
value: (ctx.value as Record<string, any>)[key],
|
|
19
|
-
path:
|
|
20
|
-
ctx.path +
|
|
21
|
-
(NamingConvention.variable(key)
|
|
22
|
-
? `.${key}`
|
|
23
|
-
: `[${JSON.stringify(key)}]`),
|
|
24
|
-
required: ctx.schema.required?.includes(key) ?? false,
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
27
|
-
...(typeof ctx.schema.additionalProperties === "object" &&
|
|
28
|
-
ctx.schema.additionalProperties !== null
|
|
29
|
-
? Object.entries(ctx.value)
|
|
30
|
-
.filter(
|
|
31
|
-
([key]) =>
|
|
32
|
-
Object.keys(ctx.schema.properties ?? {}).includes(key) ===
|
|
33
|
-
false,
|
|
34
|
-
)
|
|
35
|
-
.map(([key, value]) =>
|
|
36
|
-
OpenApiStationValidator.validate({
|
|
37
|
-
...ctx,
|
|
38
|
-
schema: ctx.schema.additionalProperties as OpenApi.IJsonSchema,
|
|
39
|
-
value,
|
|
40
|
-
path:
|
|
41
|
-
ctx.path +
|
|
42
|
-
(NamingConvention.variable(key)
|
|
43
|
-
? `.${key}`
|
|
44
|
-
: `[${JSON.stringify(key)}]`),
|
|
45
|
-
required: true,
|
|
46
|
-
}),
|
|
47
|
-
)
|
|
48
|
-
: []),
|
|
49
|
-
...(ctx.equals === true &&
|
|
50
|
-
(ctx.schema.additionalProperties ?? false) === false
|
|
51
|
-
? [validateEquals(ctx)]
|
|
52
|
-
: []),
|
|
53
|
-
].every((v) => v);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const validateEquals = (
|
|
57
|
-
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IObject>,
|
|
58
|
-
): boolean => {
|
|
59
|
-
const regular: Set<string> = new Set(
|
|
60
|
-
Object.keys(ctx.schema.properties ?? {}),
|
|
61
|
-
);
|
|
62
|
-
return Object.entries(ctx.value as object)
|
|
63
|
-
.map(([key, value]) => {
|
|
64
|
-
if (regular.has(key) === true) return true;
|
|
65
|
-
return ctx.report({
|
|
66
|
-
...ctx,
|
|
67
|
-
path:
|
|
68
|
-
ctx.path +
|
|
69
|
-
(NamingConvention.variable(key)
|
|
70
|
-
? `.${key}`
|
|
71
|
-
: `[${JSON.stringify(key)}]`),
|
|
72
|
-
value,
|
|
73
|
-
expected: "undefined",
|
|
74
|
-
description: [
|
|
75
|
-
`The property \`${key}\` is not defined in the object type.`,
|
|
76
|
-
"",
|
|
77
|
-
"Please remove the property next time.",
|
|
78
|
-
].join("\n"),
|
|
79
|
-
});
|
|
80
|
-
})
|
|
81
|
-
.every((v) => v);
|
|
82
|
-
};
|
|
83
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { NamingConvention } from "../../utils/NamingConvention";
|
|
4
|
+
import { IOpenApiValidatorContext } from "./IOpenApiValidatorContext";
|
|
5
|
+
import { OpenApiStationValidator } from "./OpenApiStationValidator";
|
|
6
|
+
|
|
7
|
+
export namespace OpenApiObjectValidator {
|
|
8
|
+
export const validate = (
|
|
9
|
+
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IObject>,
|
|
10
|
+
): boolean => {
|
|
11
|
+
if (typeof ctx.value !== "object" || ctx.value === null)
|
|
12
|
+
return ctx.report(ctx);
|
|
13
|
+
return [
|
|
14
|
+
...Object.entries(ctx.schema.properties ?? {}).map(([key, value]) =>
|
|
15
|
+
OpenApiStationValidator.validate({
|
|
16
|
+
...ctx,
|
|
17
|
+
schema: value,
|
|
18
|
+
value: (ctx.value as Record<string, any>)[key],
|
|
19
|
+
path:
|
|
20
|
+
ctx.path +
|
|
21
|
+
(NamingConvention.variable(key)
|
|
22
|
+
? `.${key}`
|
|
23
|
+
: `[${JSON.stringify(key)}]`),
|
|
24
|
+
required: ctx.schema.required?.includes(key) ?? false,
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
...(typeof ctx.schema.additionalProperties === "object" &&
|
|
28
|
+
ctx.schema.additionalProperties !== null
|
|
29
|
+
? Object.entries(ctx.value)
|
|
30
|
+
.filter(
|
|
31
|
+
([key]) =>
|
|
32
|
+
Object.keys(ctx.schema.properties ?? {}).includes(key) ===
|
|
33
|
+
false,
|
|
34
|
+
)
|
|
35
|
+
.map(([key, value]) =>
|
|
36
|
+
OpenApiStationValidator.validate({
|
|
37
|
+
...ctx,
|
|
38
|
+
schema: ctx.schema.additionalProperties as OpenApi.IJsonSchema,
|
|
39
|
+
value,
|
|
40
|
+
path:
|
|
41
|
+
ctx.path +
|
|
42
|
+
(NamingConvention.variable(key)
|
|
43
|
+
? `.${key}`
|
|
44
|
+
: `[${JSON.stringify(key)}]`),
|
|
45
|
+
required: true,
|
|
46
|
+
}),
|
|
47
|
+
)
|
|
48
|
+
: []),
|
|
49
|
+
...(ctx.equals === true &&
|
|
50
|
+
(ctx.schema.additionalProperties ?? false) === false
|
|
51
|
+
? [validateEquals(ctx)]
|
|
52
|
+
: []),
|
|
53
|
+
].every((v) => v);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const validateEquals = (
|
|
57
|
+
ctx: IOpenApiValidatorContext<OpenApi.IJsonSchema.IObject>,
|
|
58
|
+
): boolean => {
|
|
59
|
+
const regular: Set<string> = new Set(
|
|
60
|
+
Object.keys(ctx.schema.properties ?? {}),
|
|
61
|
+
);
|
|
62
|
+
return Object.entries(ctx.value as object)
|
|
63
|
+
.map(([key, value]) => {
|
|
64
|
+
if (regular.has(key) === true) return true;
|
|
65
|
+
return ctx.report({
|
|
66
|
+
...ctx,
|
|
67
|
+
path:
|
|
68
|
+
ctx.path +
|
|
69
|
+
(NamingConvention.variable(key)
|
|
70
|
+
? `.${key}`
|
|
71
|
+
: `[${JSON.stringify(key)}]`),
|
|
72
|
+
value,
|
|
73
|
+
expected: "undefined",
|
|
74
|
+
description: [
|
|
75
|
+
`The property \`${key}\` is not defined in the object type.`,
|
|
76
|
+
"",
|
|
77
|
+
"Please remove the property next time.",
|
|
78
|
+
].join("\n"),
|
|
79
|
+
});
|
|
80
|
+
})
|
|
81
|
+
.every((v) => v);
|
|
82
|
+
};
|
|
83
|
+
}
|