typia 5.0.0-dev.20230821 → 5.0.0-dev.20230823
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/README.md +1 -1
- package/lib/factories/MetadataFactory.js +9 -0
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/ProtobufFactory.js +8 -0
- package/lib/factories/ProtobufFactory.js.map +1 -1
- package/lib/functional/$ProtobufReader.d.ts +2 -0
- package/lib/functional/$ProtobufReader.js +14 -3
- package/lib/functional/$ProtobufReader.js.map +1 -1
- package/lib/functional/$ProtobufSizer.js +1 -1
- package/lib/functional/$ProtobufSizer.js.map +1 -1
- package/lib/functional/$ProtobufWriter.js +0 -1
- package/lib/functional/$ProtobufWriter.js.map +1 -1
- package/lib/programmers/helpers/ProtobufUtil.d.ts +3 -1
- package/lib/programmers/helpers/ProtobufUtil.js +5 -1
- package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
- package/lib/programmers/json/JsonValidateParseProgrammer.js +2 -3
- package/lib/programmers/json/JsonValidateParseProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js +2 -3
- package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +362 -6
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +21 -64
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufIsDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufIsDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufValidateDecodeProgrammer.js +3 -4
- package/lib/programmers/protobuf/ProtobufValidateDecodeProgrammer.js.map +1 -1
- package/lib/protobuf.d.ts +8 -9
- package/lib/protobuf.js +7 -0
- package/lib/protobuf.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/ExpressionFactory.ts +115 -115
- package/src/factories/MetadataCollection.ts +269 -269
- package/src/factories/MetadataFactory.ts +46 -34
- package/src/factories/MetadataTagFactory.ts +364 -364
- package/src/factories/ProtobufFactory.ts +266 -251
- package/src/factories/StatementFactory.ts +72 -72
- 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 +84 -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/$ProtobufReader.ts +201 -188
- package/src/functional/$ProtobufSizer.ts +147 -144
- package/src/functional/$ProtobufWriter.ts +151 -152
- package/src/functional/$number.ts +13 -13
- package/src/functional/$strlen.ts +7 -7
- package/src/functional/$varint.ts +130 -130
- package/src/functional/$zigzag.ts +39 -39
- package/src/functional/IProtobufWriter.ts +18 -18
- package/src/functional/Namespace.ts +149 -149
- package/src/json.ts +648 -648
- package/src/misc.ts +651 -651
- package/src/module.ts +708 -708
- package/src/programmers/CheckerProgrammer.ts +1173 -1173
- package/src/programmers/FeatureProgrammer.ts +497 -497
- package/src/programmers/IsProgrammer.ts +239 -239
- package/src/programmers/IsPruneProgrammer.ts +73 -73
- package/src/programmers/RandomProgrammer.ts +578 -578
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/CloneJoiner.ts +107 -107
- package/src/programmers/helpers/FunctionImporeter.ts +89 -89
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- package/src/programmers/helpers/ProtobufUtil.ts +29 -24
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- 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/StringifyPredicator.ts +13 -13
- package/src/programmers/helpers/UnionExplorer.ts +310 -310
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/helpers/disable_function_importer_declare.ts +27 -27
- package/src/programmers/internal/application_alias.ts +66 -66
- package/src/programmers/internal/application_array.ts +30 -30
- 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 +81 -81
- 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_number.ts +258 -258
- 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 +84 -84
- 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_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/programmers/json/JsonApplicationProgrammer.ts +47 -47
- package/src/programmers/json/JsonAssertParseProgrammer.ts +66 -66
- package/src/programmers/json/JsonAssertStringifyProgrammer.ts +66 -66
- package/src/programmers/json/JsonIsParseProgrammer.ts +72 -72
- package/src/programmers/json/JsonIsStringifyProgrammer.ts +76 -76
- package/src/programmers/json/JsonStringifyProgrammer.ts +987 -987
- package/src/programmers/json/JsonValidateParseProgrammer.ts +63 -70
- package/src/programmers/json/JsonValidateStringifyProgrammer.ts +84 -84
- package/src/programmers/misc/MiscAssertCloneProgrammer.ts +71 -71
- package/src/programmers/misc/MiscAssertPruneProgrammer.ts +68 -68
- package/src/programmers/misc/MiscCloneProgrammer.ts +587 -587
- package/src/programmers/misc/MiscIsCloneProgrammer.ts +78 -78
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +64 -64
- package/src/programmers/misc/MiscPruneProgrammer.ts +542 -542
- package/src/programmers/misc/MiscValidateCloneProgrammer.ts +85 -85
- package/src/programmers/misc/MiscValidatePruneProgrammer.ts +78 -78
- package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +66 -69
- package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +66 -66
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +669 -38
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +814 -920
- package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +75 -75
- package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +76 -76
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +178 -178
- package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -83
- package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +86 -86
- package/src/protobuf.ts +249 -239
- package/src/schemas/json/IJsonApplication.ts +8 -8
- package/src/schemas/json/IJsonComponents.ts +33 -33
- package/src/schemas/json/IJsonSchema.ts +133 -133
- package/src/schemas/metadata/ICommentTag.ts +4 -4
- package/src/schemas/metadata/IJsDocTagInfo.ts +10 -10
- package/src/schemas/metadata/IMetadata.ts +28 -28
- package/src/schemas/metadata/IMetadataAlias.ts +14 -14
- package/src/schemas/metadata/IMetadataApplication.ts +7 -7
- package/src/schemas/metadata/IMetadataArray.ts +10 -10
- package/src/schemas/metadata/IMetadataCollection.ts +11 -11
- package/src/schemas/metadata/IMetadataConstant.ts +16 -16
- package/src/schemas/metadata/IMetadataDictionary.ts +14 -14
- package/src/schemas/metadata/IMetadataEntry.ts +6 -6
- package/src/schemas/metadata/IMetadataObject.ts +18 -18
- package/src/schemas/metadata/IMetadataProperty.ts +11 -11
- package/src/schemas/metadata/IMetadataResolved.ts +6 -6
- package/src/schemas/metadata/IMetadataTag.ts +112 -112
- package/src/schemas/metadata/IMetadataTuple.ts +10 -10
- package/src/schemas/metadata/Metadata.ts +637 -637
- package/src/schemas/metadata/MetadataAlias.ts +66 -66
- package/src/schemas/metadata/MetadataArray.ts +55 -55
- package/src/schemas/metadata/MetadataConstant.ts +3 -3
- package/src/schemas/metadata/MetadataObject.ts +139 -139
- package/src/schemas/metadata/MetadataProperty.ts +64 -64
- package/src/schemas/metadata/MetadataResolved.ts +51 -51
- package/src/schemas/metadata/MetadataTuple.ts +58 -58
- package/src/transformers/CallExpressionTransformer.ts +240 -240
- package/src/transformers/features/AssertTransformer.ts +11 -11
- package/src/transformers/features/CreateAssertTransformer.ts +13 -13
- package/src/transformers/features/CreateIsTransformer.ts +11 -11
- package/src/transformers/features/CreateRandomTransformer.ts +39 -39
- package/src/transformers/features/CreateValidateTransformer.ts +13 -13
- package/src/transformers/features/IsTransformer.ts +11 -11
- package/src/transformers/features/RandomTransformer.ts +42 -42
- package/src/transformers/features/ValidateTransformer.ts +11 -11
- package/src/transformers/features/json/JsonApplicationTransformer.ts +111 -111
- package/src/transformers/features/json/JsonAssertParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonIsStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonValidateParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/misc/MetadataTransformer.ts +53 -53
- package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscLiteralsTransformer.ts +28 -28
- package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +10 -10
- package/src/transformers/features/protobuf/CreateProtobufAssertDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/CreateProtobufAssertEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/CreateProtobufDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/CreateProtobufEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/CreateProtobufIsDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/CreateProtobufIsEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/CreateProtobufValidateDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/CreateProtobufValidateEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufAssertDecodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufAssertEncodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufDecodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufEncodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufIsDecodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufIsEncodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +31 -31
- package/src/transformers/features/protobuf/ProtobufValidateDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufValidateEncodeTransformer.ts +12 -12
- package/src/utils/NameEncoder.ts +32 -32
|
@@ -1,81 +1,81 @@
|
|
|
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 (tag.kind === "type") {
|
|
17
|
-
if (
|
|
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
|
-
}
|
|
27
|
-
// RANGE TAG
|
|
28
|
-
else if (tag.kind === "minimum") output.minimum = tag.value;
|
|
29
|
-
else if (tag.kind === "maximum") output.maximum = tag.value;
|
|
30
|
-
else if (tag.kind === "exclusiveMinimum") {
|
|
31
|
-
output.minimum = tag.value;
|
|
32
|
-
output.exclusiveMinimum = true;
|
|
33
|
-
} else if (tag.kind === "exclusiveMaximum") {
|
|
34
|
-
output.maximum = tag.value;
|
|
35
|
-
output.exclusiveMaximum = true;
|
|
36
|
-
}
|
|
37
|
-
// MULTIPLE-OF
|
|
38
|
-
else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// WHEN UNSIGNED INT
|
|
42
|
-
if (
|
|
43
|
-
output.type === "integer" &&
|
|
44
|
-
(attribute["x-typia-metaTags"] ?? []).find(
|
|
45
|
-
(tag) =>
|
|
46
|
-
tag.kind === "type" &&
|
|
47
|
-
(tag.value === "uint" ||
|
|
48
|
-
tag.value === "uint32" ||
|
|
49
|
-
tag.value === "uint64"),
|
|
50
|
-
)
|
|
51
|
-
)
|
|
52
|
-
if (
|
|
53
|
-
output.minimum === undefined ||
|
|
54
|
-
(output.exclusiveMaximum !== true && output.minimum < 0)
|
|
55
|
-
)
|
|
56
|
-
output.minimum = 0;
|
|
57
|
-
else if (output.exclusiveMinimum === true && output.minimum < -1) {
|
|
58
|
-
output.maximum = 0;
|
|
59
|
-
delete output.exclusiveMinimum;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// DEFAULT CONFIGURATION
|
|
63
|
-
output.default = application_default(attribute)((str) => {
|
|
64
|
-
const value: number = Number(str);
|
|
65
|
-
const conditions: boolean[] = [!Number.isNaN(value)];
|
|
66
|
-
if (output.minimum !== undefined)
|
|
67
|
-
if (output.exclusiveMinimum === true)
|
|
68
|
-
conditions.push(value > output.minimum);
|
|
69
|
-
else conditions.push(value >= output.minimum);
|
|
70
|
-
if (output.maximum !== undefined)
|
|
71
|
-
if (output.exclusiveMaximum === true)
|
|
72
|
-
conditions.push(value < output.maximum);
|
|
73
|
-
else conditions.push(value <= output.maximum);
|
|
74
|
-
if (output.multipleOf !== undefined)
|
|
75
|
-
conditions.push(value % output.multipleOf === 0);
|
|
76
|
-
return conditions.every((cond) => cond);
|
|
77
|
-
})((str) => Number(str));
|
|
78
|
-
|
|
79
|
-
// RETURNS
|
|
80
|
-
return output;
|
|
81
|
-
};
|
|
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 (tag.kind === "type") {
|
|
17
|
+
if (
|
|
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
|
+
}
|
|
27
|
+
// RANGE TAG
|
|
28
|
+
else if (tag.kind === "minimum") output.minimum = tag.value;
|
|
29
|
+
else if (tag.kind === "maximum") output.maximum = tag.value;
|
|
30
|
+
else if (tag.kind === "exclusiveMinimum") {
|
|
31
|
+
output.minimum = tag.value;
|
|
32
|
+
output.exclusiveMinimum = true;
|
|
33
|
+
} else if (tag.kind === "exclusiveMaximum") {
|
|
34
|
+
output.maximum = tag.value;
|
|
35
|
+
output.exclusiveMaximum = true;
|
|
36
|
+
}
|
|
37
|
+
// MULTIPLE-OF
|
|
38
|
+
else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// WHEN UNSIGNED INT
|
|
42
|
+
if (
|
|
43
|
+
output.type === "integer" &&
|
|
44
|
+
(attribute["x-typia-metaTags"] ?? []).find(
|
|
45
|
+
(tag) =>
|
|
46
|
+
tag.kind === "type" &&
|
|
47
|
+
(tag.value === "uint" ||
|
|
48
|
+
tag.value === "uint32" ||
|
|
49
|
+
tag.value === "uint64"),
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
if (
|
|
53
|
+
output.minimum === undefined ||
|
|
54
|
+
(output.exclusiveMaximum !== true && output.minimum < 0)
|
|
55
|
+
)
|
|
56
|
+
output.minimum = 0;
|
|
57
|
+
else if (output.exclusiveMinimum === true && output.minimum < -1) {
|
|
58
|
+
output.maximum = 0;
|
|
59
|
+
delete output.exclusiveMinimum;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// DEFAULT CONFIGURATION
|
|
63
|
+
output.default = application_default(attribute)((str) => {
|
|
64
|
+
const value: number = Number(str);
|
|
65
|
+
const conditions: boolean[] = [!Number.isNaN(value)];
|
|
66
|
+
if (output.minimum !== undefined)
|
|
67
|
+
if (output.exclusiveMinimum === true)
|
|
68
|
+
conditions.push(value > output.minimum);
|
|
69
|
+
else conditions.push(value >= output.minimum);
|
|
70
|
+
if (output.maximum !== undefined)
|
|
71
|
+
if (output.exclusiveMaximum === true)
|
|
72
|
+
conditions.push(value < output.maximum);
|
|
73
|
+
else conditions.push(value <= output.maximum);
|
|
74
|
+
if (output.multipleOf !== undefined)
|
|
75
|
+
conditions.push(value % output.multipleOf === 0);
|
|
76
|
+
return conditions.every((cond) => cond);
|
|
77
|
+
})((str) => Number(str));
|
|
78
|
+
|
|
79
|
+
// RETURNS
|
|
80
|
+
return output;
|
|
81
|
+
};
|
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
-
|
|
3
|
-
import { IJsonComponents } from "../../schemas/json/IJsonComponents";
|
|
4
|
-
import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
|
|
5
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
6
|
-
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
7
|
-
|
|
8
|
-
import { PatternUtil } from "../../utils/PatternUtil";
|
|
9
|
-
|
|
10
|
-
import { IJsonSchema } from "../../module";
|
|
11
|
-
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
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: JsonApplicationProgrammer.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: JsonApplicationProgrammer.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 { IJsonComponents } from "../../schemas/json/IJsonComponents";
|
|
4
|
+
import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
|
|
5
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
6
|
+
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
7
|
+
|
|
8
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
9
|
+
|
|
10
|
+
import { IJsonSchema } from "../../module";
|
|
11
|
+
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
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: JsonApplicationProgrammer.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: JsonApplicationProgrammer.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,55 +1,55 @@
|
|
|
1
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
-
import { MetadataResolved } from "../../schemas/metadata/MetadataResolved";
|
|
3
|
-
|
|
4
|
-
import { IJsonComponents, IJsonSchema } from "../../module";
|
|
5
|
-
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
6
|
-
import { application_schema } from "./application_schema";
|
|
7
|
-
|
|
8
|
-
export const application_resolved =
|
|
9
|
-
(options: JsonApplicationProgrammer.IOptions) =>
|
|
10
|
-
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
11
|
-
(components: IJsonComponents) =>
|
|
12
|
-
(resolved: MetadataResolved) =>
|
|
13
|
-
(attribute: IJsonSchema.IAttribute): IJsonSchema[] => {
|
|
14
|
-
const output = application_schema(options)(blockNever)(components)(
|
|
15
|
-
resolved.returns,
|
|
16
|
-
)(attribute);
|
|
17
|
-
if (output === null) return [];
|
|
18
|
-
|
|
19
|
-
if (is_date(new Set())(resolved.original)) {
|
|
20
|
-
const string: IJsonSchema.IString | undefined = is_string(output)
|
|
21
|
-
? output
|
|
22
|
-
: is_one_of(output)
|
|
23
|
-
? output.oneOf.find(is_string)
|
|
24
|
-
: undefined;
|
|
25
|
-
if (
|
|
26
|
-
string !== undefined &&
|
|
27
|
-
string.format !== "date" &&
|
|
28
|
-
string.format !== "date-time"
|
|
29
|
-
)
|
|
30
|
-
string.format = "date-time";
|
|
31
|
-
}
|
|
32
|
-
return is_one_of(output) ? output.oneOf : [output];
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const is_string = (elem: IJsonSchema): elem is IJsonSchema.IString =>
|
|
36
|
-
(elem as IJsonSchema.IString).type === "string";
|
|
37
|
-
|
|
38
|
-
const is_one_of = (elem: IJsonSchema): elem is IJsonSchema.IOneOf =>
|
|
39
|
-
Array.isArray((elem as IJsonSchema.IOneOf).oneOf);
|
|
40
|
-
|
|
41
|
-
const is_date =
|
|
42
|
-
(visited: Set<Metadata>) =>
|
|
43
|
-
(meta: Metadata): boolean => {
|
|
44
|
-
if (visited.has(meta)) return false;
|
|
45
|
-
visited.add(meta);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
meta.natives.some((name) => name === "Date") ||
|
|
49
|
-
meta.arrays.some((array) => is_date(visited)(array.value)) ||
|
|
50
|
-
meta.tuples.some((tuple) =>
|
|
51
|
-
tuple.elements.some(is_date(visited)),
|
|
52
|
-
) ||
|
|
53
|
-
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
54
|
-
);
|
|
55
|
-
};
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
import { MetadataResolved } from "../../schemas/metadata/MetadataResolved";
|
|
3
|
+
|
|
4
|
+
import { IJsonComponents, IJsonSchema } from "../../module";
|
|
5
|
+
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
6
|
+
import { application_schema } from "./application_schema";
|
|
7
|
+
|
|
8
|
+
export const application_resolved =
|
|
9
|
+
(options: JsonApplicationProgrammer.IOptions) =>
|
|
10
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
11
|
+
(components: IJsonComponents) =>
|
|
12
|
+
(resolved: MetadataResolved) =>
|
|
13
|
+
(attribute: IJsonSchema.IAttribute): IJsonSchema[] => {
|
|
14
|
+
const output = application_schema(options)(blockNever)(components)(
|
|
15
|
+
resolved.returns,
|
|
16
|
+
)(attribute);
|
|
17
|
+
if (output === null) return [];
|
|
18
|
+
|
|
19
|
+
if (is_date(new Set())(resolved.original)) {
|
|
20
|
+
const string: IJsonSchema.IString | undefined = is_string(output)
|
|
21
|
+
? output
|
|
22
|
+
: is_one_of(output)
|
|
23
|
+
? output.oneOf.find(is_string)
|
|
24
|
+
: undefined;
|
|
25
|
+
if (
|
|
26
|
+
string !== undefined &&
|
|
27
|
+
string.format !== "date" &&
|
|
28
|
+
string.format !== "date-time"
|
|
29
|
+
)
|
|
30
|
+
string.format = "date-time";
|
|
31
|
+
}
|
|
32
|
+
return is_one_of(output) ? output.oneOf : [output];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const is_string = (elem: IJsonSchema): elem is IJsonSchema.IString =>
|
|
36
|
+
(elem as IJsonSchema.IString).type === "string";
|
|
37
|
+
|
|
38
|
+
const is_one_of = (elem: IJsonSchema): elem is IJsonSchema.IOneOf =>
|
|
39
|
+
Array.isArray((elem as IJsonSchema.IOneOf).oneOf);
|
|
40
|
+
|
|
41
|
+
const is_date =
|
|
42
|
+
(visited: Set<Metadata>) =>
|
|
43
|
+
(meta: Metadata): boolean => {
|
|
44
|
+
if (visited.has(meta)) return false;
|
|
45
|
+
visited.add(meta);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
meta.natives.some((name) => name === "Date") ||
|
|
49
|
+
meta.arrays.some((array) => is_date(visited)(array.value)) ||
|
|
50
|
+
meta.tuples.some((tuple) =>
|
|
51
|
+
tuple.elements.some(is_date(visited)),
|
|
52
|
+
) ||
|
|
53
|
+
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
54
|
+
);
|
|
55
|
+
};
|