typia 4.3.2-dev.20230821 → 4.3.3-dev.20230825
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/factories/internal/metadata/iterate_metadata_intersection.js +2 -0
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
- package/lib/programmers/helpers/CloneJoiner.js +10 -2
- package/lib/programmers/helpers/CloneJoiner.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/package.json +2 -2
- package/src/CustomValidatorMap.ts +126 -126
- package/src/IRandomGenerator.ts +34 -34
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +131 -131
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/TypiaGenerateWizard.ts +85 -85
- package/src/executable/TypiaSetupWizard.ts +153 -153
- package/src/executable/setup/ArgumentParser.ts +45 -45
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/FileRetriever.ts +22 -22
- package/src/executable/setup/PackageManager.ts +71 -71
- package/src/executable/setup/PluginConfigurator.ts +70 -70
- package/src/executable/typia.ts +52 -52
- package/src/factories/CommentFactory.ts +84 -84
- package/src/factories/ExpressionFactory.ts +77 -77
- package/src/factories/IdentifierFactory.ts +59 -59
- package/src/factories/LiteralFactory.ts +39 -39
- package/src/factories/MetadataCollection.ts +269 -269
- package/src/factories/MetadataFactory.ts +34 -34
- package/src/factories/MetadataTagFactory.ts +361 -361
- package/src/factories/StatementFactory.ts +24 -24
- package/src/factories/TemplateFactory.ts +58 -58
- package/src/factories/TypeFactory.ts +124 -124
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emend_metadata_atomics.ts +33 -33
- package/src/factories/internal/metadata/emplace_metadata_alias.ts +40 -40
- package/src/factories/internal/metadata/emplace_metadata_array.ts +34 -34
- package/src/factories/internal/metadata/emplace_metadata_object.ts +136 -136
- package/src/factories/internal/metadata/emplace_metadata_tuple.ts +50 -50
- package/src/factories/internal/metadata/explore_metadata.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata.ts +81 -81
- package/src/factories/internal/metadata/iterate_metadata_alias.ts +30 -30
- package/src/factories/internal/metadata/iterate_metadata_array.ts +24 -24
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +88 -84
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +219 -219
- package/src/factories/internal/metadata/iterate_metadata_object.ts +43 -43
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
- package/src/factories/internal/metadata/iterate_metadata_tag.ts +31 -31
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +24 -24
- package/src/factories/internal/metadata/iterate_metadata_union.ts +24 -24
- package/src/functional/$any.ts +2 -2
- package/src/functional/$dictionary.ts +25 -25
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_between.ts +2 -2
- package/src/functional/$is_custom.ts +14 -14
- package/src/functional/$is_date.ts +3 -3
- package/src/functional/$is_datetime.ts +2 -2
- package/src/functional/$is_email.ts +4 -4
- package/src/functional/$is_ipv4.ts +4 -4
- package/src/functional/$is_ipv6.ts +4 -4
- package/src/functional/$is_url.ts +4 -4
- package/src/functional/$is_uuid.ts +4 -4
- package/src/functional/$join.ts +46 -46
- package/src/functional/$number.ts +12 -12
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +50 -50
- package/src/functional/$tail.ts +5 -5
- package/src/functional/Namespace.ts +127 -127
- package/src/index.ts +4 -4
- package/src/metadata/ICommentTag.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +28 -28
- package/src/metadata/IMetadataAlias.ts +14 -14
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataArray.ts +10 -10
- package/src/metadata/IMetadataCollection.ts +11 -11
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataDictionary.ts +14 -14
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +18 -18
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataResolved.ts +6 -6
- package/src/metadata/IMetadataTag.ts +112 -112
- package/src/metadata/IMetadataTuple.ts +10 -10
- package/src/metadata/Metadata.ts +607 -607
- package/src/metadata/MetadataAlias.ts +66 -66
- package/src/metadata/MetadataArray.ts +55 -55
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +129 -129
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/metadata/MetadataResolved.ts +51 -51
- package/src/metadata/MetadataTuple.ts +58 -58
- package/src/module.ts +2038 -2038
- package/src/programmers/ApplicationProgrammer.ts +47 -47
- package/src/programmers/AssertCloneProgrammer.ts +71 -71
- package/src/programmers/AssertParseProgrammer.ts +66 -66
- package/src/programmers/AssertProgrammer.ts +279 -279
- package/src/programmers/AssertPruneProgrammer.ts +68 -68
- package/src/programmers/AssertStringifyProgrammer.ts +66 -66
- package/src/programmers/CheckerProgrammer.ts +1173 -1173
- package/src/programmers/CloneProgrammer.ts +587 -587
- package/src/programmers/FeatureProgrammer.ts +495 -495
- package/src/programmers/IsCloneProgrammer.ts +78 -78
- package/src/programmers/IsParseProgrammer.ts +72 -72
- package/src/programmers/IsProgrammer.ts +239 -239
- package/src/programmers/IsPruneProgrammer.ts +73 -73
- package/src/programmers/IsStringifyProgrammer.ts +76 -76
- package/src/programmers/LiteralsProgrammer.ts +64 -64
- package/src/programmers/PruneProgrammer.ts +542 -542
- package/src/programmers/RandomProgrammer.ts +578 -578
- package/src/programmers/StringifyProgrammer.ts +986 -986
- package/src/programmers/TypiaProgrammer.ts +129 -129
- package/src/programmers/ValidateCloneProgrammer.ts +85 -85
- package/src/programmers/ValidateParseProgrammer.ts +70 -70
- package/src/programmers/ValidateProgrammer.ts +305 -305
- package/src/programmers/ValidatePruneProgrammer.ts +78 -78
- package/src/programmers/ValidateStringifyProgrammer.ts +84 -84
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/CloneJoiner.ts +168 -131
- package/src/programmers/helpers/FunctionImporeter.ts +78 -78
- package/src/programmers/helpers/ICheckEntry.ts +12 -12
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/helpers/PruneJoiner.ts +143 -143
- package/src/programmers/helpers/RandomJoiner.ts +173 -173
- package/src/programmers/helpers/RandomRanger.ts +208 -208
- package/src/programmers/helpers/StringifyJoinder.ts +113 -113
- package/src/programmers/helpers/StringifyPredicator.ts +13 -13
- package/src/programmers/helpers/UnionExplorer.ts +305 -305
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/helpers/disable_function_importer_declare.ts +26 -26
- package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
- package/src/programmers/internal/application_alias.ts +66 -66
- package/src/programmers/internal/application_array.ts +30 -30
- package/src/programmers/internal/application_boolean.ts +15 -15
- package/src/programmers/internal/application_constant.ts +26 -26
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +33 -33
- package/src/programmers/internal/application_native.ts +39 -39
- package/src/programmers/internal/application_number.ts +80 -80
- package/src/programmers/internal/application_object.ts +165 -165
- package/src/programmers/internal/application_resolved.ts +55 -55
- package/src/programmers/internal/application_schema.ts +157 -157
- package/src/programmers/internal/application_string.ts +44 -44
- package/src/programmers/internal/application_templates.ts +25 -25
- package/src/programmers/internal/application_tuple.ts +57 -57
- package/src/programmers/internal/check_array.ts +30 -30
- package/src/programmers/internal/check_array_length.ts +35 -35
- package/src/programmers/internal/check_bigint.ts +110 -110
- package/src/programmers/internal/check_custom.ts +31 -31
- package/src/programmers/internal/check_dynamic_properties.ts +194 -195
- package/src/programmers/internal/check_everything.ts +28 -28
- package/src/programmers/internal/check_native.ts +21 -21
- package/src/programmers/internal/check_object.ts +55 -55
- package/src/programmers/internal/check_string.ts +25 -25
- package/src/programmers/internal/check_string_tags.ts +67 -67
- package/src/programmers/internal/check_template.ts +56 -56
- package/src/programmers/internal/check_union_array_like.ts +329 -329
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/programmers/internal/get_comment_tags.ts +23 -23
- package/src/programmers/internal/metadata_to_pattern.ts +34 -34
- package/src/programmers/internal/prune_object_properties.ts +60 -60
- package/src/programmers/internal/random_custom.ts +29 -29
- package/src/programmers/internal/stringify_dynamic_properties.ts +171 -171
- package/src/programmers/internal/stringify_native.ts +7 -7
- package/src/programmers/internal/stringify_regular_properties.ts +83 -83
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +16 -16
- package/src/schemas/IJsonApplication.ts +8 -8
- package/src/schemas/IJsonComponents.ts +33 -33
- package/src/schemas/IJsonSchema.ts +133 -133
- package/src/transform.ts +27 -27
- package/src/transformers/CallExpressionTransformer.ts +179 -179
- package/src/transformers/FileTransformer.ts +47 -47
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/ImportTransformer.ts +66 -66
- package/src/transformers/NodeTransformer.ts +13 -13
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +112 -112
- package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +39 -39
- package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +28 -28
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +53 -53
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +42 -42
- package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/validators/AssertTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateAssertTransformer.ts +13 -13
- package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
- package/src/transformers/features/validators/IsTransformer.ts +11 -11
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +97 -97
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/Customizable.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +45 -45
- package/src/utils/Escaper.ts +46 -46
- package/src/utils/MapUtil.ts +12 -12
- package/src/utils/PatternUtil.ts +33 -33
- package/src/utils/RandomGenerator.ts +81 -81
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
2
|
-
|
|
3
|
-
import { IJsonSchema } from "../../module";
|
|
4
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
5
|
-
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const application_native =
|
|
11
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
12
|
-
(components: IJsonComponents) =>
|
|
13
|
-
(name: string) =>
|
|
14
|
-
(props: {
|
|
15
|
-
nullable: boolean;
|
|
16
|
-
attribute: IJsonSchema.IAttribute;
|
|
17
|
-
}): IJsonSchema.IReference => {
|
|
18
|
-
const key: string =
|
|
19
|
-
options.purpose === "ajv"
|
|
20
|
-
? name
|
|
21
|
-
: `${name}${props.nullable ? ".Nullable" : ""}`;
|
|
22
|
-
if (components.schemas?.[key] === undefined) {
|
|
23
|
-
components.schemas ??= {};
|
|
24
|
-
components.schemas[key] ??= {
|
|
25
|
-
type: "object",
|
|
26
|
-
$id:
|
|
27
|
-
options.purpose === "ajv"
|
|
28
|
-
? `${JSON_COMPONENTS_PREFIX}/objects/${key}`
|
|
29
|
-
: undefined,
|
|
30
|
-
properties: {},
|
|
31
|
-
nullable:
|
|
32
|
-
options.purpose === "swagger" ? props.nullable : undefined,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
...props.attribute,
|
|
37
|
-
$ref: `${JSON_COMPONENTS_PREFIX}/objects/${key}`,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
1
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
2
|
+
|
|
3
|
+
import { IJsonSchema } from "../../module";
|
|
4
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
5
|
+
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const application_native =
|
|
11
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
12
|
+
(components: IJsonComponents) =>
|
|
13
|
+
(name: string) =>
|
|
14
|
+
(props: {
|
|
15
|
+
nullable: boolean;
|
|
16
|
+
attribute: IJsonSchema.IAttribute;
|
|
17
|
+
}): IJsonSchema.IReference => {
|
|
18
|
+
const key: string =
|
|
19
|
+
options.purpose === "ajv"
|
|
20
|
+
? name
|
|
21
|
+
: `${name}${props.nullable ? ".Nullable" : ""}`;
|
|
22
|
+
if (components.schemas?.[key] === undefined) {
|
|
23
|
+
components.schemas ??= {};
|
|
24
|
+
components.schemas[key] ??= {
|
|
25
|
+
type: "object",
|
|
26
|
+
$id:
|
|
27
|
+
options.purpose === "ajv"
|
|
28
|
+
? `${JSON_COMPONENTS_PREFIX}/objects/${key}`
|
|
29
|
+
: undefined,
|
|
30
|
+
properties: {},
|
|
31
|
+
nullable:
|
|
32
|
+
options.purpose === "swagger" ? props.nullable : undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...props.attribute,
|
|
37
|
+
$ref: `${JSON_COMPONENTS_PREFIX}/objects/${key}`,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import { IJsonSchema } from "../../module";
|
|
2
|
-
import { application_default } from "./application_default";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export const application_number = (
|
|
8
|
-
attribute: IJsonSchema.IAttribute,
|
|
9
|
-
): IJsonSchema.INumber | IJsonSchema.IInteger => {
|
|
10
|
-
const output: IJsonSchema.INumber | IJsonSchema.IInteger = {
|
|
11
|
-
...attribute,
|
|
12
|
-
type: "number" as "number" | "integer",
|
|
13
|
-
};
|
|
14
|
-
for (const tag of attribute["x-typia-metaTags"] ?? []) {
|
|
15
|
-
// CHECK TYPE
|
|
16
|
-
if (
|
|
17
|
-
tag.kind === "type" &&
|
|
18
|
-
(tag.value === "int" ||
|
|
19
|
-
tag.value === "uint" ||
|
|
20
|
-
tag.value === "int32" ||
|
|
21
|
-
tag.value === "uint32" ||
|
|
22
|
-
tag.value === "int64" ||
|
|
23
|
-
tag.value === "uint64")
|
|
24
|
-
)
|
|
25
|
-
output.type = "integer";
|
|
26
|
-
// RANGE TAG
|
|
27
|
-
else if (tag.kind === "minimum") output.minimum = tag.value;
|
|
28
|
-
else if (tag.kind === "maximum") output.maximum = tag.value;
|
|
29
|
-
else if (tag.kind === "exclusiveMinimum") {
|
|
30
|
-
output.minimum = tag.value;
|
|
31
|
-
output.exclusiveMinimum = true;
|
|
32
|
-
} else if (tag.kind === "exclusiveMaximum") {
|
|
33
|
-
output.maximum = tag.value;
|
|
34
|
-
output.exclusiveMaximum = true;
|
|
35
|
-
}
|
|
36
|
-
// MULTIPLE-OF
|
|
37
|
-
else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// WHEN UNSIGNED INT
|
|
41
|
-
if (
|
|
42
|
-
output.type === "integer" &&
|
|
43
|
-
(attribute["x-typia-metaTags"] ?? []).find(
|
|
44
|
-
(tag) =>
|
|
45
|
-
tag.kind === "type" &&
|
|
46
|
-
(tag.value === "uint" ||
|
|
47
|
-
tag.value === "uint32" ||
|
|
48
|
-
tag.value === "uint64"),
|
|
49
|
-
)
|
|
50
|
-
)
|
|
51
|
-
if (
|
|
52
|
-
output.minimum === undefined ||
|
|
53
|
-
(output.exclusiveMaximum !== true && output.minimum < 0)
|
|
54
|
-
)
|
|
55
|
-
output.minimum = 0;
|
|
56
|
-
else if (output.exclusiveMinimum === true && output.minimum < -1) {
|
|
57
|
-
output.maximum = 0;
|
|
58
|
-
delete output.exclusiveMinimum;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// DEFAULT CONFIGURATION
|
|
62
|
-
output.default = application_default(attribute)((str) => {
|
|
63
|
-
const value: number = Number(str);
|
|
64
|
-
const conditions: boolean[] = [!Number.isNaN(value)];
|
|
65
|
-
if (output.minimum !== undefined)
|
|
66
|
-
if (output.exclusiveMinimum === true)
|
|
67
|
-
conditions.push(value > output.minimum);
|
|
68
|
-
else conditions.push(value >= output.minimum);
|
|
69
|
-
if (output.maximum !== undefined)
|
|
70
|
-
if (output.exclusiveMaximum === true)
|
|
71
|
-
conditions.push(value < output.maximum);
|
|
72
|
-
else conditions.push(value <= output.maximum);
|
|
73
|
-
if (output.multipleOf !== undefined)
|
|
74
|
-
conditions.push(value % output.multipleOf === 0);
|
|
75
|
-
return conditions.every((cond) => cond);
|
|
76
|
-
})((str) => Number(str));
|
|
77
|
-
|
|
78
|
-
// RETURNS
|
|
79
|
-
return output;
|
|
80
|
-
};
|
|
1
|
+
import { IJsonSchema } from "../../module";
|
|
2
|
+
import { application_default } from "./application_default";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export const application_number = (
|
|
8
|
+
attribute: IJsonSchema.IAttribute,
|
|
9
|
+
): IJsonSchema.INumber | IJsonSchema.IInteger => {
|
|
10
|
+
const output: IJsonSchema.INumber | IJsonSchema.IInteger = {
|
|
11
|
+
...attribute,
|
|
12
|
+
type: "number" as "number" | "integer",
|
|
13
|
+
};
|
|
14
|
+
for (const tag of attribute["x-typia-metaTags"] ?? []) {
|
|
15
|
+
// CHECK TYPE
|
|
16
|
+
if (
|
|
17
|
+
tag.kind === "type" &&
|
|
18
|
+
(tag.value === "int" ||
|
|
19
|
+
tag.value === "uint" ||
|
|
20
|
+
tag.value === "int32" ||
|
|
21
|
+
tag.value === "uint32" ||
|
|
22
|
+
tag.value === "int64" ||
|
|
23
|
+
tag.value === "uint64")
|
|
24
|
+
)
|
|
25
|
+
output.type = "integer";
|
|
26
|
+
// RANGE TAG
|
|
27
|
+
else if (tag.kind === "minimum") output.minimum = tag.value;
|
|
28
|
+
else if (tag.kind === "maximum") output.maximum = tag.value;
|
|
29
|
+
else if (tag.kind === "exclusiveMinimum") {
|
|
30
|
+
output.minimum = tag.value;
|
|
31
|
+
output.exclusiveMinimum = true;
|
|
32
|
+
} else if (tag.kind === "exclusiveMaximum") {
|
|
33
|
+
output.maximum = tag.value;
|
|
34
|
+
output.exclusiveMaximum = true;
|
|
35
|
+
}
|
|
36
|
+
// MULTIPLE-OF
|
|
37
|
+
else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// WHEN UNSIGNED INT
|
|
41
|
+
if (
|
|
42
|
+
output.type === "integer" &&
|
|
43
|
+
(attribute["x-typia-metaTags"] ?? []).find(
|
|
44
|
+
(tag) =>
|
|
45
|
+
tag.kind === "type" &&
|
|
46
|
+
(tag.value === "uint" ||
|
|
47
|
+
tag.value === "uint32" ||
|
|
48
|
+
tag.value === "uint64"),
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
if (
|
|
52
|
+
output.minimum === undefined ||
|
|
53
|
+
(output.exclusiveMaximum !== true && output.minimum < 0)
|
|
54
|
+
)
|
|
55
|
+
output.minimum = 0;
|
|
56
|
+
else if (output.exclusiveMinimum === true && output.minimum < -1) {
|
|
57
|
+
output.maximum = 0;
|
|
58
|
+
delete output.exclusiveMinimum;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// DEFAULT CONFIGURATION
|
|
62
|
+
output.default = application_default(attribute)((str) => {
|
|
63
|
+
const value: number = Number(str);
|
|
64
|
+
const conditions: boolean[] = [!Number.isNaN(value)];
|
|
65
|
+
if (output.minimum !== undefined)
|
|
66
|
+
if (output.exclusiveMinimum === true)
|
|
67
|
+
conditions.push(value > output.minimum);
|
|
68
|
+
else conditions.push(value >= output.minimum);
|
|
69
|
+
if (output.maximum !== undefined)
|
|
70
|
+
if (output.exclusiveMaximum === true)
|
|
71
|
+
conditions.push(value < output.maximum);
|
|
72
|
+
else conditions.push(value <= output.maximum);
|
|
73
|
+
if (output.multipleOf !== undefined)
|
|
74
|
+
conditions.push(value % output.multipleOf === 0);
|
|
75
|
+
return conditions.every((cond) => cond);
|
|
76
|
+
})((str) => Number(str));
|
|
77
|
+
|
|
78
|
+
// RETURNS
|
|
79
|
+
return output;
|
|
80
|
+
};
|
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
5
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
7
|
-
|
|
8
|
-
import { PatternUtil } from "../../utils/PatternUtil";
|
|
9
|
-
|
|
10
|
-
import { IJsonSchema } from "../../module";
|
|
11
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
12
|
-
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
13
|
-
import { application_schema } from "./application_schema";
|
|
14
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export const application_object =
|
|
20
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
21
|
-
(components: IJsonComponents) =>
|
|
22
|
-
(obj: MetadataObject) =>
|
|
23
|
-
(nullable: boolean): IJsonSchema.IReference => {
|
|
24
|
-
const key: string =
|
|
25
|
-
options.purpose === "ajv"
|
|
26
|
-
? obj.name
|
|
27
|
-
: `${obj.name}${nullable ? ".Nullable" : ""}`;
|
|
28
|
-
const $id: string = `${JSON_COMPONENTS_PREFIX}/schemas/${key}`;
|
|
29
|
-
const output = { $ref: $id };
|
|
30
|
-
|
|
31
|
-
// TEMPORARY ASSIGNMENT
|
|
32
|
-
if (components.schemas?.[key] !== undefined) return output;
|
|
33
|
-
components.schemas ??= {};
|
|
34
|
-
components.schemas[key] = {} as any;
|
|
35
|
-
|
|
36
|
-
// ITERATE PROPERTIES
|
|
37
|
-
const properties: Record<string, any> = {};
|
|
38
|
-
const extraMeta: ISuperfluous = {
|
|
39
|
-
patternProperties: {},
|
|
40
|
-
additionalProperties: undefined,
|
|
41
|
-
};
|
|
42
|
-
const required: string[] = [];
|
|
43
|
-
|
|
44
|
-
for (const property of obj.properties) {
|
|
45
|
-
if (
|
|
46
|
-
// FUNCTIONAL TYPE
|
|
47
|
-
property.value.functional === true &&
|
|
48
|
-
property.value.nullable === false &&
|
|
49
|
-
property.value.isRequired() === true &&
|
|
50
|
-
property.value.size() === 0
|
|
51
|
-
)
|
|
52
|
-
continue;
|
|
53
|
-
else if (property.jsDocTags.find((tag) => tag.name === "hidden"))
|
|
54
|
-
continue; // THE HIDDEN TAG
|
|
55
|
-
|
|
56
|
-
const key: string | null = property.key.getSoleLiteral();
|
|
57
|
-
const schema: IJsonSchema | null = application_schema(options)(
|
|
58
|
-
true,
|
|
59
|
-
)(components)(property.value)({
|
|
60
|
-
deprecated:
|
|
61
|
-
property.jsDocTags.some(
|
|
62
|
-
(tag) => tag.name === "deprecated",
|
|
63
|
-
) || undefined,
|
|
64
|
-
title: (() => {
|
|
65
|
-
const info: IJsDocTagInfo | undefined =
|
|
66
|
-
property.jsDocTags.find((tag) => tag.name === "title");
|
|
67
|
-
return info?.text?.length
|
|
68
|
-
? CommentFactory.merge(info.text)
|
|
69
|
-
: undefined;
|
|
70
|
-
})(),
|
|
71
|
-
description: property.description ?? undefined,
|
|
72
|
-
"x-typia-metaTags": property.tags.length
|
|
73
|
-
? property.tags
|
|
74
|
-
: undefined,
|
|
75
|
-
"x-typia-jsDocTags": property.jsDocTags.length
|
|
76
|
-
? property.jsDocTags
|
|
77
|
-
: undefined,
|
|
78
|
-
"x-typia-required": property.value.required,
|
|
79
|
-
"x-typia-optional": property.value.optional,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (schema === null) continue;
|
|
83
|
-
else if (key !== null) {
|
|
84
|
-
properties[key] = schema;
|
|
85
|
-
if (property.value.isRequired() === true) required.push(key);
|
|
86
|
-
} else {
|
|
87
|
-
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
88
|
-
if (pattern === PatternUtil.STRING)
|
|
89
|
-
extraMeta.additionalProperties = [property.value, schema];
|
|
90
|
-
else
|
|
91
|
-
extraMeta.patternProperties[pattern] = [
|
|
92
|
-
property.value,
|
|
93
|
-
schema,
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const extraProps = {
|
|
99
|
-
additionalProperties: extraMeta.additionalProperties?.[1],
|
|
100
|
-
patternProperties: (() => {
|
|
101
|
-
if (Object.keys(extraMeta.patternProperties).length === 0)
|
|
102
|
-
return undefined;
|
|
103
|
-
const output: Record<string, IJsonSchema> = {};
|
|
104
|
-
for (const [key, value] of Object.entries(
|
|
105
|
-
extraMeta.patternProperties,
|
|
106
|
-
))
|
|
107
|
-
output[key] = value[1];
|
|
108
|
-
return output;
|
|
109
|
-
})(),
|
|
110
|
-
};
|
|
111
|
-
const schema: IJsonComponents.IObject = {
|
|
112
|
-
$id: options.purpose === "ajv" ? $id : undefined,
|
|
113
|
-
// $recursiveAnchor:
|
|
114
|
-
// (options.purpose === "ajv" && obj.recursive) || undefined,
|
|
115
|
-
type: "object",
|
|
116
|
-
properties,
|
|
117
|
-
nullable: options.purpose === "swagger" ? nullable : undefined,
|
|
118
|
-
required: required.length ? required : undefined,
|
|
119
|
-
description: obj.description,
|
|
120
|
-
"x-typia-jsDocTags": obj.jsDocTags,
|
|
121
|
-
...(options.purpose === "ajv"
|
|
122
|
-
? extraProps
|
|
123
|
-
: {
|
|
124
|
-
// swagger can't express patternProperties
|
|
125
|
-
"x-typia-additionalProperties":
|
|
126
|
-
extraProps.additionalProperties,
|
|
127
|
-
"x-typia-patternProperties": extraProps.patternProperties,
|
|
128
|
-
additionalProperties:
|
|
129
|
-
join(options)(components)(extraMeta),
|
|
130
|
-
}),
|
|
131
|
-
};
|
|
132
|
-
components.schemas[key] = schema;
|
|
133
|
-
return output;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const join =
|
|
137
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
138
|
-
(components: IJsonComponents) =>
|
|
139
|
-
(extra: ISuperfluous): IJsonSchema | undefined => {
|
|
140
|
-
// LIST UP METADATA
|
|
141
|
-
const elements: [Metadata, IJsonSchema][] = Object.values(
|
|
142
|
-
extra.patternProperties || {},
|
|
143
|
-
);
|
|
144
|
-
if (extra.additionalProperties)
|
|
145
|
-
elements.push(extra.additionalProperties);
|
|
146
|
-
|
|
147
|
-
// SHORT RETURN
|
|
148
|
-
if (elements.length === 0) return undefined;
|
|
149
|
-
else if (elements.length === 1) return elements[0]![1]!;
|
|
150
|
-
|
|
151
|
-
// MERGE METADATA AND GENERATE VULNERABLE SCHEMA
|
|
152
|
-
const meta: Metadata = elements
|
|
153
|
-
.map((tuple) => tuple[0])
|
|
154
|
-
.reduce((x, y) => Metadata.merge(x, y));
|
|
155
|
-
return (
|
|
156
|
-
application_schema(options)(true)(components)(meta)({
|
|
157
|
-
"x-typia-required": false,
|
|
158
|
-
}) ?? undefined
|
|
159
|
-
);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
interface ISuperfluous {
|
|
163
|
-
additionalProperties?: [Metadata, IJsonSchema];
|
|
164
|
-
patternProperties: Record<string, [Metadata, IJsonSchema]>;
|
|
165
|
-
}
|
|
1
|
+
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
5
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
7
|
+
|
|
8
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
9
|
+
|
|
10
|
+
import { IJsonSchema } from "../../module";
|
|
11
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
12
|
+
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
13
|
+
import { application_schema } from "./application_schema";
|
|
14
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export const application_object =
|
|
20
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
21
|
+
(components: IJsonComponents) =>
|
|
22
|
+
(obj: MetadataObject) =>
|
|
23
|
+
(nullable: boolean): IJsonSchema.IReference => {
|
|
24
|
+
const key: string =
|
|
25
|
+
options.purpose === "ajv"
|
|
26
|
+
? obj.name
|
|
27
|
+
: `${obj.name}${nullable ? ".Nullable" : ""}`;
|
|
28
|
+
const $id: string = `${JSON_COMPONENTS_PREFIX}/schemas/${key}`;
|
|
29
|
+
const output = { $ref: $id };
|
|
30
|
+
|
|
31
|
+
// TEMPORARY ASSIGNMENT
|
|
32
|
+
if (components.schemas?.[key] !== undefined) return output;
|
|
33
|
+
components.schemas ??= {};
|
|
34
|
+
components.schemas[key] = {} as any;
|
|
35
|
+
|
|
36
|
+
// ITERATE PROPERTIES
|
|
37
|
+
const properties: Record<string, any> = {};
|
|
38
|
+
const extraMeta: ISuperfluous = {
|
|
39
|
+
patternProperties: {},
|
|
40
|
+
additionalProperties: undefined,
|
|
41
|
+
};
|
|
42
|
+
const required: string[] = [];
|
|
43
|
+
|
|
44
|
+
for (const property of obj.properties) {
|
|
45
|
+
if (
|
|
46
|
+
// FUNCTIONAL TYPE
|
|
47
|
+
property.value.functional === true &&
|
|
48
|
+
property.value.nullable === false &&
|
|
49
|
+
property.value.isRequired() === true &&
|
|
50
|
+
property.value.size() === 0
|
|
51
|
+
)
|
|
52
|
+
continue;
|
|
53
|
+
else if (property.jsDocTags.find((tag) => tag.name === "hidden"))
|
|
54
|
+
continue; // THE HIDDEN TAG
|
|
55
|
+
|
|
56
|
+
const key: string | null = property.key.getSoleLiteral();
|
|
57
|
+
const schema: IJsonSchema | null = application_schema(options)(
|
|
58
|
+
true,
|
|
59
|
+
)(components)(property.value)({
|
|
60
|
+
deprecated:
|
|
61
|
+
property.jsDocTags.some(
|
|
62
|
+
(tag) => tag.name === "deprecated",
|
|
63
|
+
) || undefined,
|
|
64
|
+
title: (() => {
|
|
65
|
+
const info: IJsDocTagInfo | undefined =
|
|
66
|
+
property.jsDocTags.find((tag) => tag.name === "title");
|
|
67
|
+
return info?.text?.length
|
|
68
|
+
? CommentFactory.merge(info.text)
|
|
69
|
+
: undefined;
|
|
70
|
+
})(),
|
|
71
|
+
description: property.description ?? undefined,
|
|
72
|
+
"x-typia-metaTags": property.tags.length
|
|
73
|
+
? property.tags
|
|
74
|
+
: undefined,
|
|
75
|
+
"x-typia-jsDocTags": property.jsDocTags.length
|
|
76
|
+
? property.jsDocTags
|
|
77
|
+
: undefined,
|
|
78
|
+
"x-typia-required": property.value.required,
|
|
79
|
+
"x-typia-optional": property.value.optional,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (schema === null) continue;
|
|
83
|
+
else if (key !== null) {
|
|
84
|
+
properties[key] = schema;
|
|
85
|
+
if (property.value.isRequired() === true) required.push(key);
|
|
86
|
+
} else {
|
|
87
|
+
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
88
|
+
if (pattern === PatternUtil.STRING)
|
|
89
|
+
extraMeta.additionalProperties = [property.value, schema];
|
|
90
|
+
else
|
|
91
|
+
extraMeta.patternProperties[pattern] = [
|
|
92
|
+
property.value,
|
|
93
|
+
schema,
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const extraProps = {
|
|
99
|
+
additionalProperties: extraMeta.additionalProperties?.[1],
|
|
100
|
+
patternProperties: (() => {
|
|
101
|
+
if (Object.keys(extraMeta.patternProperties).length === 0)
|
|
102
|
+
return undefined;
|
|
103
|
+
const output: Record<string, IJsonSchema> = {};
|
|
104
|
+
for (const [key, value] of Object.entries(
|
|
105
|
+
extraMeta.patternProperties,
|
|
106
|
+
))
|
|
107
|
+
output[key] = value[1];
|
|
108
|
+
return output;
|
|
109
|
+
})(),
|
|
110
|
+
};
|
|
111
|
+
const schema: IJsonComponents.IObject = {
|
|
112
|
+
$id: options.purpose === "ajv" ? $id : undefined,
|
|
113
|
+
// $recursiveAnchor:
|
|
114
|
+
// (options.purpose === "ajv" && obj.recursive) || undefined,
|
|
115
|
+
type: "object",
|
|
116
|
+
properties,
|
|
117
|
+
nullable: options.purpose === "swagger" ? nullable : undefined,
|
|
118
|
+
required: required.length ? required : undefined,
|
|
119
|
+
description: obj.description,
|
|
120
|
+
"x-typia-jsDocTags": obj.jsDocTags,
|
|
121
|
+
...(options.purpose === "ajv"
|
|
122
|
+
? extraProps
|
|
123
|
+
: {
|
|
124
|
+
// swagger can't express patternProperties
|
|
125
|
+
"x-typia-additionalProperties":
|
|
126
|
+
extraProps.additionalProperties,
|
|
127
|
+
"x-typia-patternProperties": extraProps.patternProperties,
|
|
128
|
+
additionalProperties:
|
|
129
|
+
join(options)(components)(extraMeta),
|
|
130
|
+
}),
|
|
131
|
+
};
|
|
132
|
+
components.schemas[key] = schema;
|
|
133
|
+
return output;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const join =
|
|
137
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
138
|
+
(components: IJsonComponents) =>
|
|
139
|
+
(extra: ISuperfluous): IJsonSchema | undefined => {
|
|
140
|
+
// LIST UP METADATA
|
|
141
|
+
const elements: [Metadata, IJsonSchema][] = Object.values(
|
|
142
|
+
extra.patternProperties || {},
|
|
143
|
+
);
|
|
144
|
+
if (extra.additionalProperties)
|
|
145
|
+
elements.push(extra.additionalProperties);
|
|
146
|
+
|
|
147
|
+
// SHORT RETURN
|
|
148
|
+
if (elements.length === 0) return undefined;
|
|
149
|
+
else if (elements.length === 1) return elements[0]![1]!;
|
|
150
|
+
|
|
151
|
+
// MERGE METADATA AND GENERATE VULNERABLE SCHEMA
|
|
152
|
+
const meta: Metadata = elements
|
|
153
|
+
.map((tuple) => tuple[0])
|
|
154
|
+
.reduce((x, y) => Metadata.merge(x, y));
|
|
155
|
+
return (
|
|
156
|
+
application_schema(options)(true)(components)(meta)({
|
|
157
|
+
"x-typia-required": false,
|
|
158
|
+
}) ?? undefined
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
interface ISuperfluous {
|
|
163
|
+
additionalProperties?: [Metadata, IJsonSchema];
|
|
164
|
+
patternProperties: Record<string, [Metadata, IJsonSchema]>;
|
|
165
|
+
}
|