typia 3.7.5-dev.20230413 → 3.7.6
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 +35 -228
- package/lib/executable/TypiaSetupWizard.d.ts +1 -0
- package/lib/executable/TypiaSetupWizard.js +62 -30
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/lib/executable/setup/PackageManager.d.ts +1 -1
- package/lib/executable/typia.d.ts +1 -1
- package/lib/executable/typia.js +1 -1
- package/lib/executable/typia.js.map +1 -1
- package/lib/factories/IdentifierFactory.d.ts +1 -1
- package/lib/factories/IdentifierFactory.js +1 -1
- package/lib/factories/IdentifierFactory.js.map +1 -1
- package/lib/factories/TypiaFileFactory.js +9 -4
- package/lib/factories/TypiaFileFactory.js.map +1 -1
- package/lib/programmers/internal/check_string_tags.js +2 -2
- package/lib/programmers/internal/check_string_tags.js.map +1 -1
- package/lib/programmers/internal/check_template.js +1 -1
- package/lib/programmers/internal/check_template.js.map +1 -1
- package/package.json +11 -12
- package/src/CustomValidatorMap.ts +126 -126
- package/src/IRandomGenerator.ts +33 -33
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +104 -104
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/TypiaGenerateWizard.ts +85 -85
- package/src/executable/TypiaSetupWizard.ts +47 -14
- 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 +1 -1
- package/src/executable/setup/PluginConfigurator.ts +59 -59
- package/src/executable/typia.ts +54 -53
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +77 -77
- package/src/factories/IdentifierFactory.ts +81 -59
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/MetadataCollection.ts +122 -122
- package/src/factories/MetadataFactory.ts +51 -51
- package/src/factories/MetadataTagFactory.ts +302 -302
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +129 -129
- package/src/factories/TypiaFileFactory.ts +12 -3
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
- package/src/factories/internal/metadata/explore_metadata.ts +92 -92
- package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
- package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
- 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_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +222 -222
- package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/functional/$any.ts +3 -3
- package/src/functional/$dictionary.ts +20 -20
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_between.ts +7 -7
- package/src/functional/$is_custom.ts +14 -14
- package/src/functional/$is_date.ts +4 -4
- package/src/functional/$is_datetime.ts +3 -3
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- 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 +37 -37
- package/src/functional/$tail.ts +6 -6
- 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 +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTag.ts +105 -105
- package/src/metadata/Metadata.ts +534 -534
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/module.ts +2043 -2043
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertCloneProgrammer.ts +70 -70
- package/src/programmers/AssertParseProgrammer.ts +65 -65
- package/src/programmers/AssertProgrammer.ts +284 -284
- package/src/programmers/AssertPruneProgrammer.ts +67 -67
- package/src/programmers/AssertStringifyProgrammer.ts +71 -71
- package/src/programmers/CheckerProgrammer.ts +922 -922
- package/src/programmers/CloneProgrammer.ts +388 -388
- package/src/programmers/FeatureProgrammer.ts +512 -512
- package/src/programmers/IsCloneProgrammer.ts +80 -80
- package/src/programmers/IsParseProgrammer.ts +74 -74
- package/src/programmers/IsProgrammer.ts +206 -206
- package/src/programmers/IsPruneProgrammer.ts +75 -75
- package/src/programmers/IsStringifyProgrammer.ts +81 -81
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/PruneProgrammer.ts +343 -343
- package/src/programmers/RandomProgrammer.ts +413 -413
- package/src/programmers/StringifyProgrammer.ts +801 -801
- package/src/programmers/ValidateCloneProgrammer.ts +90 -90
- package/src/programmers/ValidateParseProgrammer.ts +69 -69
- package/src/programmers/ValidateProgrammer.ts +317 -317
- package/src/programmers/ValidatePruneProgrammer.ts +83 -83
- package/src/programmers/ValidateStringifyProgrammer.ts +89 -89
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/CloneJoiner.ts +134 -134
- package/src/programmers/helpers/FunctionImporeter.ts +55 -55
- package/src/programmers/helpers/ICheckEntry.ts +12 -12
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- package/src/programmers/helpers/OptionPredicator.ts +19 -19
- package/src/programmers/helpers/PruneJoiner.ts +52 -52
- package/src/programmers/helpers/RandomJoiner.ts +161 -161
- package/src/programmers/helpers/RandomRanger.ts +216 -216
- package/src/programmers/helpers/StringifyJoinder.ts +114 -114
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +281 -281
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +37 -37
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +32 -32
- package/src/programmers/internal/application_number.ts +73 -73
- package/src/programmers/internal/application_object.ts +153 -153
- package/src/programmers/internal/application_schema.ts +184 -184
- package/src/programmers/internal/application_string.ts +45 -45
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -29
- 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 +82 -82
- package/src/programmers/internal/check_custom.ts +33 -33
- package/src/programmers/internal/check_dynamic_properties.ts +197 -197
- package/src/programmers/internal/check_everything.ts +28 -28
- package/src/programmers/internal/check_native.ts +21 -21
- package/src/programmers/internal/check_number.ts +177 -177
- 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 +9 -15
- package/src/programmers/internal/check_template.ts +6 -9
- package/src/programmers/internal/check_union_array_like.ts +272 -272
- package/src/programmers/internal/check_union_tuple.ts +35 -35
- 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 +30 -30
- package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +84 -84
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -26
- package/src/schemas/IJsonSchema.ts +121 -121
- package/src/transform.ts +21 -21
- package/src/transformers/CallExpressionTransformer.ts +174 -174
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- 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 +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +119 -119
- 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 +41 -41
- 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 +30 -30
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +54 -54
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
- 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 +9 -9
- 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 +11 -11
- 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 +12 -12
- package/src/transformers/features/validators/CreateIsTransformer.ts +10 -10
- package/src/transformers/features/validators/CreateValidateTransformer.ts +12 -12
- package/src/transformers/features/validators/IsTransformer.ts +10 -10
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +99 -99
- 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 +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/RandomGenerator.ts +96 -96
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,153 +1,153 @@
|
|
|
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 { application_schema } from "./application_schema";
|
|
13
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export const application_object =
|
|
19
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
20
|
-
(components: IJsonComponents) =>
|
|
21
|
-
(key: string, obj: MetadataObject, nullable: boolean): void => {
|
|
22
|
-
// TEMPORARY ASSIGNMENT
|
|
23
|
-
if (components.schemas[key] !== undefined) return;
|
|
24
|
-
components.schemas[key] = {} as any;
|
|
25
|
-
|
|
26
|
-
// ITERATE PROPERTIES
|
|
27
|
-
const properties: Record<string, any> = {};
|
|
28
|
-
const extraMeta: ISuperfluous = {
|
|
29
|
-
patternProperties: {},
|
|
30
|
-
additionalProperties: undefined,
|
|
31
|
-
};
|
|
32
|
-
const required: string[] = [];
|
|
33
|
-
|
|
34
|
-
for (const property of obj.properties) {
|
|
35
|
-
if (
|
|
36
|
-
property.value.functional === true &&
|
|
37
|
-
property.value.nullable === false &&
|
|
38
|
-
property.value.required === true &&
|
|
39
|
-
property.value.size() === 0
|
|
40
|
-
)
|
|
41
|
-
continue;
|
|
42
|
-
|
|
43
|
-
const key: string | null = property.key.getSoleLiteral();
|
|
44
|
-
const schema: IJsonSchema | null = application_schema(options)(
|
|
45
|
-
components,
|
|
46
|
-
)(true)(property.value, {
|
|
47
|
-
deprecated:
|
|
48
|
-
!!property.jsDocTags.find(
|
|
49
|
-
(tag) => tag.name === "deprecated",
|
|
50
|
-
) || undefined,
|
|
51
|
-
title: (() => {
|
|
52
|
-
const info: IJsDocTagInfo | undefined =
|
|
53
|
-
property.jsDocTags.find((tag) => tag.name === "title");
|
|
54
|
-
return info?.text?.length
|
|
55
|
-
? CommentFactory.generate(info.text)
|
|
56
|
-
: undefined;
|
|
57
|
-
})(),
|
|
58
|
-
description: property.description,
|
|
59
|
-
"x-typia-metaTags": property.tags.length
|
|
60
|
-
? property.tags
|
|
61
|
-
: undefined,
|
|
62
|
-
"x-typia-jsDocTags": property.jsDocTags.length
|
|
63
|
-
? property.jsDocTags
|
|
64
|
-
: undefined,
|
|
65
|
-
"x-typia-required": property.value.required,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (schema === null) continue;
|
|
69
|
-
else if (key !== null) {
|
|
70
|
-
properties[key] = schema;
|
|
71
|
-
if (property.value.required === true) required.push(key);
|
|
72
|
-
} else {
|
|
73
|
-
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
74
|
-
if (pattern === PatternUtil.STRING)
|
|
75
|
-
extraMeta.additionalProperties = [property.value, schema];
|
|
76
|
-
else
|
|
77
|
-
extraMeta.patternProperties[pattern] = [
|
|
78
|
-
property.value,
|
|
79
|
-
schema,
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const extraProps = {
|
|
85
|
-
additionalProperties: extraMeta.additionalProperties?.[1],
|
|
86
|
-
patternProperties: (() => {
|
|
87
|
-
if (Object.keys(extraMeta.patternProperties).length === 0)
|
|
88
|
-
return undefined;
|
|
89
|
-
const output: Record<string, IJsonSchema> = {};
|
|
90
|
-
for (const [key, value] of Object.entries(
|
|
91
|
-
extraMeta.patternProperties,
|
|
92
|
-
))
|
|
93
|
-
output[key] = value[1];
|
|
94
|
-
return output;
|
|
95
|
-
})(),
|
|
96
|
-
};
|
|
97
|
-
const schema: IJsonComponents.IObject = {
|
|
98
|
-
$id:
|
|
99
|
-
options.purpose === "ajv"
|
|
100
|
-
? options.prefix + "/" + key
|
|
101
|
-
: undefined,
|
|
102
|
-
$recursiveAnchor:
|
|
103
|
-
(options.purpose === "ajv" && obj.recursive) || undefined,
|
|
104
|
-
type: "object",
|
|
105
|
-
properties,
|
|
106
|
-
nullable,
|
|
107
|
-
required: required.length ? required : undefined,
|
|
108
|
-
description: obj.description,
|
|
109
|
-
"x-typia-jsDocTags": obj.jsDocTags,
|
|
110
|
-
...(options.purpose === "ajv"
|
|
111
|
-
? extraProps
|
|
112
|
-
: {
|
|
113
|
-
// swagger can't express patternProperties
|
|
114
|
-
"x-typia-additionalProperties":
|
|
115
|
-
extraProps.additionalProperties,
|
|
116
|
-
"x-typia-patternProperties": extraProps.patternProperties,
|
|
117
|
-
additionalProperties:
|
|
118
|
-
join(options)(components)(extraMeta),
|
|
119
|
-
}),
|
|
120
|
-
};
|
|
121
|
-
components.schemas[key] = schema;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const join =
|
|
125
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
126
|
-
(components: IJsonComponents) =>
|
|
127
|
-
(extra: ISuperfluous): IJsonSchema | undefined => {
|
|
128
|
-
// LIST UP METADATA
|
|
129
|
-
const elements: [Metadata, IJsonSchema][] = Object.values(
|
|
130
|
-
extra.patternProperties || {},
|
|
131
|
-
);
|
|
132
|
-
if (extra.additionalProperties)
|
|
133
|
-
elements.push(extra.additionalProperties);
|
|
134
|
-
|
|
135
|
-
// SHORT RETURN
|
|
136
|
-
if (elements.length === 0) return undefined;
|
|
137
|
-
else if (elements.length === 1) return elements[0]![1]!;
|
|
138
|
-
|
|
139
|
-
// MERGE METADATA AND GENERATE VULNERABLE SCHEMA
|
|
140
|
-
const meta: Metadata = elements
|
|
141
|
-
.map((tuple) => tuple[0])
|
|
142
|
-
.reduce((x, y) => Metadata.merge(x, y));
|
|
143
|
-
return (
|
|
144
|
-
application_schema(options)(components)(true)(meta, {
|
|
145
|
-
"x-typia-required": false,
|
|
146
|
-
}) ?? undefined
|
|
147
|
-
);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
interface ISuperfluous {
|
|
151
|
-
additionalProperties?: [Metadata, IJsonSchema];
|
|
152
|
-
patternProperties: Record<string, [Metadata, IJsonSchema]>;
|
|
153
|
-
}
|
|
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 { application_schema } from "./application_schema";
|
|
13
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export const application_object =
|
|
19
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
20
|
+
(components: IJsonComponents) =>
|
|
21
|
+
(key: string, obj: MetadataObject, nullable: boolean): void => {
|
|
22
|
+
// TEMPORARY ASSIGNMENT
|
|
23
|
+
if (components.schemas[key] !== undefined) return;
|
|
24
|
+
components.schemas[key] = {} as any;
|
|
25
|
+
|
|
26
|
+
// ITERATE PROPERTIES
|
|
27
|
+
const properties: Record<string, any> = {};
|
|
28
|
+
const extraMeta: ISuperfluous = {
|
|
29
|
+
patternProperties: {},
|
|
30
|
+
additionalProperties: undefined,
|
|
31
|
+
};
|
|
32
|
+
const required: string[] = [];
|
|
33
|
+
|
|
34
|
+
for (const property of obj.properties) {
|
|
35
|
+
if (
|
|
36
|
+
property.value.functional === true &&
|
|
37
|
+
property.value.nullable === false &&
|
|
38
|
+
property.value.required === true &&
|
|
39
|
+
property.value.size() === 0
|
|
40
|
+
)
|
|
41
|
+
continue;
|
|
42
|
+
|
|
43
|
+
const key: string | null = property.key.getSoleLiteral();
|
|
44
|
+
const schema: IJsonSchema | null = application_schema(options)(
|
|
45
|
+
components,
|
|
46
|
+
)(true)(property.value, {
|
|
47
|
+
deprecated:
|
|
48
|
+
!!property.jsDocTags.find(
|
|
49
|
+
(tag) => tag.name === "deprecated",
|
|
50
|
+
) || undefined,
|
|
51
|
+
title: (() => {
|
|
52
|
+
const info: IJsDocTagInfo | undefined =
|
|
53
|
+
property.jsDocTags.find((tag) => tag.name === "title");
|
|
54
|
+
return info?.text?.length
|
|
55
|
+
? CommentFactory.generate(info.text)
|
|
56
|
+
: undefined;
|
|
57
|
+
})(),
|
|
58
|
+
description: property.description,
|
|
59
|
+
"x-typia-metaTags": property.tags.length
|
|
60
|
+
? property.tags
|
|
61
|
+
: undefined,
|
|
62
|
+
"x-typia-jsDocTags": property.jsDocTags.length
|
|
63
|
+
? property.jsDocTags
|
|
64
|
+
: undefined,
|
|
65
|
+
"x-typia-required": property.value.required,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (schema === null) continue;
|
|
69
|
+
else if (key !== null) {
|
|
70
|
+
properties[key] = schema;
|
|
71
|
+
if (property.value.required === true) required.push(key);
|
|
72
|
+
} else {
|
|
73
|
+
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
74
|
+
if (pattern === PatternUtil.STRING)
|
|
75
|
+
extraMeta.additionalProperties = [property.value, schema];
|
|
76
|
+
else
|
|
77
|
+
extraMeta.patternProperties[pattern] = [
|
|
78
|
+
property.value,
|
|
79
|
+
schema,
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const extraProps = {
|
|
85
|
+
additionalProperties: extraMeta.additionalProperties?.[1],
|
|
86
|
+
patternProperties: (() => {
|
|
87
|
+
if (Object.keys(extraMeta.patternProperties).length === 0)
|
|
88
|
+
return undefined;
|
|
89
|
+
const output: Record<string, IJsonSchema> = {};
|
|
90
|
+
for (const [key, value] of Object.entries(
|
|
91
|
+
extraMeta.patternProperties,
|
|
92
|
+
))
|
|
93
|
+
output[key] = value[1];
|
|
94
|
+
return output;
|
|
95
|
+
})(),
|
|
96
|
+
};
|
|
97
|
+
const schema: IJsonComponents.IObject = {
|
|
98
|
+
$id:
|
|
99
|
+
options.purpose === "ajv"
|
|
100
|
+
? options.prefix + "/" + key
|
|
101
|
+
: undefined,
|
|
102
|
+
$recursiveAnchor:
|
|
103
|
+
(options.purpose === "ajv" && obj.recursive) || undefined,
|
|
104
|
+
type: "object",
|
|
105
|
+
properties,
|
|
106
|
+
nullable,
|
|
107
|
+
required: required.length ? required : undefined,
|
|
108
|
+
description: obj.description,
|
|
109
|
+
"x-typia-jsDocTags": obj.jsDocTags,
|
|
110
|
+
...(options.purpose === "ajv"
|
|
111
|
+
? extraProps
|
|
112
|
+
: {
|
|
113
|
+
// swagger can't express patternProperties
|
|
114
|
+
"x-typia-additionalProperties":
|
|
115
|
+
extraProps.additionalProperties,
|
|
116
|
+
"x-typia-patternProperties": extraProps.patternProperties,
|
|
117
|
+
additionalProperties:
|
|
118
|
+
join(options)(components)(extraMeta),
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
121
|
+
components.schemas[key] = schema;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const join =
|
|
125
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
126
|
+
(components: IJsonComponents) =>
|
|
127
|
+
(extra: ISuperfluous): IJsonSchema | undefined => {
|
|
128
|
+
// LIST UP METADATA
|
|
129
|
+
const elements: [Metadata, IJsonSchema][] = Object.values(
|
|
130
|
+
extra.patternProperties || {},
|
|
131
|
+
);
|
|
132
|
+
if (extra.additionalProperties)
|
|
133
|
+
elements.push(extra.additionalProperties);
|
|
134
|
+
|
|
135
|
+
// SHORT RETURN
|
|
136
|
+
if (elements.length === 0) return undefined;
|
|
137
|
+
else if (elements.length === 1) return elements[0]![1]!;
|
|
138
|
+
|
|
139
|
+
// MERGE METADATA AND GENERATE VULNERABLE SCHEMA
|
|
140
|
+
const meta: Metadata = elements
|
|
141
|
+
.map((tuple) => tuple[0])
|
|
142
|
+
.reduce((x, y) => Metadata.merge(x, y));
|
|
143
|
+
return (
|
|
144
|
+
application_schema(options)(components)(true)(meta, {
|
|
145
|
+
"x-typia-required": false,
|
|
146
|
+
}) ?? undefined
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
interface ISuperfluous {
|
|
151
|
+
additionalProperties?: [Metadata, IJsonSchema];
|
|
152
|
+
patternProperties: Record<string, [Metadata, IJsonSchema]>;
|
|
153
|
+
}
|