typia 3.4.4 → 3.4.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 +5 -47
- package/lib/executable/internal/TypiaSetupWizard.js +8 -6
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/package.json +1 -1
- package/src/executable/internal/TypiaSetupWizard.ts +148 -149
- package/src/executable/typia.ts +35 -35
- package/src/factories/MetadataTagFactory.ts +347 -347
- package/src/factories/internal/iterate_metadata.ts +81 -81
- package/src/factories/internal/iterate_metadata_native.ts +227 -227
- package/src/functional/$number.ts +19 -19
- package/src/index.ts +4 -4
- package/src/module.ts +1535 -1535
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/StringifyProgrammer.ts +746 -746
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +103 -103
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/schemas/IJsonComponents.ts +24 -24
- package/src/schemas/IJsonSchema.ts +92 -92
- package/src/transformers/CallExpressionTransformer.ts +124 -124
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
-
|
|
5
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
-
import { application_schema } from "./application_schema";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export const application_array =
|
|
12
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
-
(components: IJsonComponents) =>
|
|
14
|
-
(
|
|
15
|
-
metadata: Metadata,
|
|
16
|
-
nullable: boolean,
|
|
17
|
-
attribute: IJsonSchema.IAttribute,
|
|
18
|
-
): IJsonSchema.IArray => {
|
|
19
|
-
// SCHEMA
|
|
20
|
-
const output: IJsonSchema.IArray = {
|
|
21
|
-
type: "array",
|
|
22
|
-
items: application_schema(options)(components)(false)(
|
|
23
|
-
metadata,
|
|
24
|
-
attribute,
|
|
25
|
-
),
|
|
26
|
-
nullable,
|
|
27
|
-
...attribute,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// RANGE
|
|
31
|
-
for (const tag of attribute["x-typia-metaTags"] || [])
|
|
32
|
-
if (tag.kind === "minItems") output.minItems = tag.value;
|
|
33
|
-
else if (tag.kind === "maxItems") output.maxItems = tag.value;
|
|
34
|
-
else if (tag.kind === "items") {
|
|
35
|
-
if (tag.minimum !== undefined)
|
|
36
|
-
output.minItems =
|
|
37
|
-
tag.minimum.value +
|
|
38
|
-
(tag.minimum.include === true ? 0 : 1);
|
|
39
|
-
if (tag.maximum !== undefined)
|
|
40
|
-
output.maxItems =
|
|
41
|
-
tag.maximum.value -
|
|
42
|
-
(tag.maximum.include === true ? 0 : 1);
|
|
43
|
-
}
|
|
44
|
-
return output;
|
|
45
|
-
};
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
+
|
|
5
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
+
import { application_schema } from "./application_schema";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const application_array =
|
|
12
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
+
(components: IJsonComponents) =>
|
|
14
|
+
(
|
|
15
|
+
metadata: Metadata,
|
|
16
|
+
nullable: boolean,
|
|
17
|
+
attribute: IJsonSchema.IAttribute,
|
|
18
|
+
): IJsonSchema.IArray => {
|
|
19
|
+
// SCHEMA
|
|
20
|
+
const output: IJsonSchema.IArray = {
|
|
21
|
+
type: "array",
|
|
22
|
+
items: application_schema(options)(components)(false)(
|
|
23
|
+
metadata,
|
|
24
|
+
attribute,
|
|
25
|
+
),
|
|
26
|
+
nullable,
|
|
27
|
+
...attribute,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// RANGE
|
|
31
|
+
for (const tag of attribute["x-typia-metaTags"] || [])
|
|
32
|
+
if (tag.kind === "minItems") output.minItems = tag.value;
|
|
33
|
+
else if (tag.kind === "maxItems") output.maxItems = tag.value;
|
|
34
|
+
else if (tag.kind === "items") {
|
|
35
|
+
if (tag.minimum !== undefined)
|
|
36
|
+
output.minItems =
|
|
37
|
+
tag.minimum.value +
|
|
38
|
+
(tag.minimum.include === true ? 0 : 1);
|
|
39
|
+
if (tag.maximum !== undefined)
|
|
40
|
+
output.maxItems =
|
|
41
|
+
tag.maximum.value -
|
|
42
|
+
(tag.maximum.include === true ? 0 : 1);
|
|
43
|
+
}
|
|
44
|
+
return output;
|
|
45
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { IJsonSchema } from "../../module";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export const application_default =
|
|
7
|
-
(attribute: IJsonSchema.IAttribute) =>
|
|
8
|
-
(pred: (value: string) => boolean) =>
|
|
9
|
-
<T>(caster: (str: string) => T): T | undefined => {
|
|
10
|
-
const defaults = (attribute["x-typia-jsDocTags"] || []).filter(
|
|
11
|
-
(tag) => tag.name === "default",
|
|
12
|
-
);
|
|
13
|
-
for (const def of defaults)
|
|
14
|
-
if (def.text?.length && pred(def.text[0]!.text))
|
|
15
|
-
return caster(def.text[0]!.text);
|
|
16
|
-
return undefined;
|
|
17
|
-
};
|
|
1
|
+
import { IJsonSchema } from "../../module";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export const application_default =
|
|
7
|
+
(attribute: IJsonSchema.IAttribute) =>
|
|
8
|
+
(pred: (value: string) => boolean) =>
|
|
9
|
+
<T>(caster: (str: string) => T): T | undefined => {
|
|
10
|
+
const defaults = (attribute["x-typia-jsDocTags"] || []).filter(
|
|
11
|
+
(tag) => tag.name === "default",
|
|
12
|
+
);
|
|
13
|
+
for (const def of defaults)
|
|
14
|
+
if (def.text?.length && pred(def.text[0]!.text))
|
|
15
|
+
return caster(def.text[0]!.text);
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { IJsonSchema } from "../../module";
|
|
2
|
-
import { application_default } from "./application_default";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export const application_number = (
|
|
8
|
-
nullable: boolean,
|
|
9
|
-
attribute: IJsonSchema.IAttribute,
|
|
10
|
-
): IJsonSchema.INumber => {
|
|
11
|
-
const output: IJsonSchema.INumber = {
|
|
12
|
-
type: "number",
|
|
13
|
-
nullable,
|
|
14
|
-
...attribute,
|
|
15
|
-
};
|
|
16
|
-
for (const tag of attribute["x-typia-metaTags"] || []) {
|
|
17
|
-
// CHECK TYPE
|
|
18
|
-
if (
|
|
19
|
-
tag.kind === "type" &&
|
|
20
|
-
(tag.value === "int" || tag.value === "uint")
|
|
21
|
-
)
|
|
22
|
-
output.type = "integer";
|
|
23
|
-
// RANGE TAG
|
|
24
|
-
else if (tag.kind === "minimum") output.minimum = tag.value;
|
|
25
|
-
else if (tag.kind === "maximum") output.maximum = tag.value;
|
|
26
|
-
else if (tag.kind === "range") {
|
|
27
|
-
if (tag.minimum !== undefined)
|
|
28
|
-
if (tag.minimum.include === true)
|
|
29
|
-
output.minimum = tag.minimum.value;
|
|
30
|
-
else output.exclusiveMinimum = tag.minimum.value;
|
|
31
|
-
if (tag.maximum !== undefined)
|
|
32
|
-
if (tag.maximum.include === true)
|
|
33
|
-
output.maximum = tag.maximum.value;
|
|
34
|
-
else output.exclusiveMaximum = tag.maximum.value;
|
|
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) => tag.kind === "type" && tag.value === "uint",
|
|
45
|
-
)
|
|
46
|
-
)
|
|
47
|
-
if (output.minimum === undefined || output.minimum < 0)
|
|
48
|
-
output.minimum = 0;
|
|
49
|
-
else if (
|
|
50
|
-
output.exclusiveMinimum === undefined ||
|
|
51
|
-
output.exclusiveMinimum < 0
|
|
52
|
-
) {
|
|
53
|
-
delete output.exclusiveMinimum;
|
|
54
|
-
output.maximum = 0;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// DEFAULT CONFIGURATION
|
|
58
|
-
output.default = application_default(attribute)((str) => {
|
|
59
|
-
const value: number = Number(str);
|
|
60
|
-
const conditions: boolean[] = [!Number.isNaN(value)];
|
|
61
|
-
if (output.minimum !== undefined)
|
|
62
|
-
conditions.push(value >= output.minimum);
|
|
63
|
-
if (output.maximum !== undefined)
|
|
64
|
-
conditions.push(value <= output.maximum);
|
|
65
|
-
if (output.exclusiveMinimum !== undefined)
|
|
66
|
-
conditions.push(value > output.exclusiveMinimum);
|
|
67
|
-
if (output.exclusiveMaximum !== undefined)
|
|
68
|
-
conditions.push(value < output.exclusiveMaximum);
|
|
69
|
-
if (output.multipleOf !== undefined)
|
|
70
|
-
conditions.push(value % output.multipleOf === 0);
|
|
71
|
-
return conditions.every((cond) => cond);
|
|
72
|
-
})((str) => Number(str));
|
|
73
|
-
|
|
74
|
-
// RETURNS
|
|
75
|
-
return output;
|
|
76
|
-
};
|
|
1
|
+
import { IJsonSchema } from "../../module";
|
|
2
|
+
import { application_default } from "./application_default";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export const application_number = (
|
|
8
|
+
nullable: boolean,
|
|
9
|
+
attribute: IJsonSchema.IAttribute,
|
|
10
|
+
): IJsonSchema.INumber => {
|
|
11
|
+
const output: IJsonSchema.INumber = {
|
|
12
|
+
type: "number",
|
|
13
|
+
nullable,
|
|
14
|
+
...attribute,
|
|
15
|
+
};
|
|
16
|
+
for (const tag of attribute["x-typia-metaTags"] || []) {
|
|
17
|
+
// CHECK TYPE
|
|
18
|
+
if (
|
|
19
|
+
tag.kind === "type" &&
|
|
20
|
+
(tag.value === "int" || tag.value === "uint")
|
|
21
|
+
)
|
|
22
|
+
output.type = "integer";
|
|
23
|
+
// RANGE TAG
|
|
24
|
+
else if (tag.kind === "minimum") output.minimum = tag.value;
|
|
25
|
+
else if (tag.kind === "maximum") output.maximum = tag.value;
|
|
26
|
+
else if (tag.kind === "range") {
|
|
27
|
+
if (tag.minimum !== undefined)
|
|
28
|
+
if (tag.minimum.include === true)
|
|
29
|
+
output.minimum = tag.minimum.value;
|
|
30
|
+
else output.exclusiveMinimum = tag.minimum.value;
|
|
31
|
+
if (tag.maximum !== undefined)
|
|
32
|
+
if (tag.maximum.include === true)
|
|
33
|
+
output.maximum = tag.maximum.value;
|
|
34
|
+
else output.exclusiveMaximum = tag.maximum.value;
|
|
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) => tag.kind === "type" && tag.value === "uint",
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
if (output.minimum === undefined || output.minimum < 0)
|
|
48
|
+
output.minimum = 0;
|
|
49
|
+
else if (
|
|
50
|
+
output.exclusiveMinimum === undefined ||
|
|
51
|
+
output.exclusiveMinimum < 0
|
|
52
|
+
) {
|
|
53
|
+
delete output.exclusiveMinimum;
|
|
54
|
+
output.maximum = 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// DEFAULT CONFIGURATION
|
|
58
|
+
output.default = application_default(attribute)((str) => {
|
|
59
|
+
const value: number = Number(str);
|
|
60
|
+
const conditions: boolean[] = [!Number.isNaN(value)];
|
|
61
|
+
if (output.minimum !== undefined)
|
|
62
|
+
conditions.push(value >= output.minimum);
|
|
63
|
+
if (output.maximum !== undefined)
|
|
64
|
+
conditions.push(value <= output.maximum);
|
|
65
|
+
if (output.exclusiveMinimum !== undefined)
|
|
66
|
+
conditions.push(value > output.exclusiveMinimum);
|
|
67
|
+
if (output.exclusiveMaximum !== undefined)
|
|
68
|
+
conditions.push(value < output.exclusiveMaximum);
|
|
69
|
+
if (output.multipleOf !== undefined)
|
|
70
|
+
conditions.push(value % output.multipleOf === 0);
|
|
71
|
+
return conditions.every((cond) => cond);
|
|
72
|
+
})((str) => Number(str));
|
|
73
|
+
|
|
74
|
+
// RETURNS
|
|
75
|
+
return output;
|
|
76
|
+
};
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
5
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
6
|
-
|
|
7
|
-
import { PatternUtil } from "../../utils/PatternUtil";
|
|
8
|
-
|
|
9
|
-
import { IJsonSchema } from "../../module";
|
|
10
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
11
|
-
import { application_schema } from "./application_schema";
|
|
12
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export const application_object =
|
|
18
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
19
|
-
(components: IJsonComponents) =>
|
|
20
|
-
(key: string, obj: MetadataObject, nullable: boolean): void => {
|
|
21
|
-
// TEMPORARY ASSIGNMENT
|
|
22
|
-
if (components.schemas[key] !== undefined) return;
|
|
23
|
-
components.schemas[key] = {} as any;
|
|
24
|
-
|
|
25
|
-
// ITERATE PROPERTIES
|
|
26
|
-
const properties: Record<string, any> = {};
|
|
27
|
-
const patternProperties: Record<string, any> = {};
|
|
28
|
-
const additionalProperties: IJsonSchema[] = [];
|
|
29
|
-
const required: string[] = [];
|
|
30
|
-
|
|
31
|
-
for (const property of obj.properties) {
|
|
32
|
-
if (
|
|
33
|
-
property.value.functional === true &&
|
|
34
|
-
property.value.nullable === false &&
|
|
35
|
-
property.value.required === true &&
|
|
36
|
-
property.value.size() === 0
|
|
37
|
-
)
|
|
38
|
-
continue;
|
|
39
|
-
|
|
40
|
-
const key: string | null = property.key.getSoleLiteral();
|
|
41
|
-
const value: IJsonSchema | null = application_schema(options)(
|
|
42
|
-
components,
|
|
43
|
-
)(true)(property.value, {
|
|
44
|
-
deprecated:
|
|
45
|
-
!!property.jsDocTags.find(
|
|
46
|
-
(tag) => tag.name === "deprecated",
|
|
47
|
-
) || undefined,
|
|
48
|
-
title: (() => {
|
|
49
|
-
const info: IJsDocTagInfo | undefined =
|
|
50
|
-
property.jsDocTags.find((tag) => tag.name === "title");
|
|
51
|
-
return info?.text?.length
|
|
52
|
-
? CommentFactory.generate(info.text)
|
|
53
|
-
: undefined;
|
|
54
|
-
})(),
|
|
55
|
-
description: property.description,
|
|
56
|
-
"x-typia-metaTags": property.tags.length
|
|
57
|
-
? property.tags
|
|
58
|
-
: undefined,
|
|
59
|
-
"x-typia-jsDocTags": property.jsDocTags.length
|
|
60
|
-
? property.jsDocTags
|
|
61
|
-
: undefined,
|
|
62
|
-
"x-typia-required": property.value.required,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
if (value === null) continue;
|
|
66
|
-
else if (key !== null) {
|
|
67
|
-
properties[key] = value;
|
|
68
|
-
if (property.value.required === true) required.push(key);
|
|
69
|
-
} else {
|
|
70
|
-
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
71
|
-
if (
|
|
72
|
-
options.purpose === "swagger" ||
|
|
73
|
-
pattern === PatternUtil.STRING
|
|
74
|
-
)
|
|
75
|
-
additionalProperties.push(value);
|
|
76
|
-
else patternProperties[pattern] = value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const schema: IJsonComponents.IObject = {
|
|
81
|
-
$id:
|
|
82
|
-
options.purpose === "ajv"
|
|
83
|
-
? options.prefix + "/" + key
|
|
84
|
-
: undefined,
|
|
85
|
-
$recursiveAnchor:
|
|
86
|
-
(options.purpose === "ajv" && obj.recursive) || undefined,
|
|
87
|
-
type: "object",
|
|
88
|
-
properties,
|
|
89
|
-
patternProperties: Object.keys(patternProperties).length
|
|
90
|
-
? patternProperties
|
|
91
|
-
: undefined,
|
|
92
|
-
additionalProperties: additionalProperties.length
|
|
93
|
-
? additionalProperties.length === 1
|
|
94
|
-
? additionalProperties[0]
|
|
95
|
-
: { oneOf: additionalProperties }
|
|
96
|
-
: undefined,
|
|
97
|
-
nullable,
|
|
98
|
-
required: required.length ? required : undefined,
|
|
99
|
-
description: obj.description,
|
|
100
|
-
"x-typia_jsDocTags": obj.jsDocTags,
|
|
101
|
-
};
|
|
102
|
-
components.schemas[key] = schema;
|
|
103
|
-
};
|
|
1
|
+
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
5
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
6
|
+
|
|
7
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
8
|
+
|
|
9
|
+
import { IJsonSchema } from "../../module";
|
|
10
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
11
|
+
import { application_schema } from "./application_schema";
|
|
12
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export const application_object =
|
|
18
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
19
|
+
(components: IJsonComponents) =>
|
|
20
|
+
(key: string, obj: MetadataObject, nullable: boolean): void => {
|
|
21
|
+
// TEMPORARY ASSIGNMENT
|
|
22
|
+
if (components.schemas[key] !== undefined) return;
|
|
23
|
+
components.schemas[key] = {} as any;
|
|
24
|
+
|
|
25
|
+
// ITERATE PROPERTIES
|
|
26
|
+
const properties: Record<string, any> = {};
|
|
27
|
+
const patternProperties: Record<string, any> = {};
|
|
28
|
+
const additionalProperties: IJsonSchema[] = [];
|
|
29
|
+
const required: string[] = [];
|
|
30
|
+
|
|
31
|
+
for (const property of obj.properties) {
|
|
32
|
+
if (
|
|
33
|
+
property.value.functional === true &&
|
|
34
|
+
property.value.nullable === false &&
|
|
35
|
+
property.value.required === true &&
|
|
36
|
+
property.value.size() === 0
|
|
37
|
+
)
|
|
38
|
+
continue;
|
|
39
|
+
|
|
40
|
+
const key: string | null = property.key.getSoleLiteral();
|
|
41
|
+
const value: IJsonSchema | null = application_schema(options)(
|
|
42
|
+
components,
|
|
43
|
+
)(true)(property.value, {
|
|
44
|
+
deprecated:
|
|
45
|
+
!!property.jsDocTags.find(
|
|
46
|
+
(tag) => tag.name === "deprecated",
|
|
47
|
+
) || undefined,
|
|
48
|
+
title: (() => {
|
|
49
|
+
const info: IJsDocTagInfo | undefined =
|
|
50
|
+
property.jsDocTags.find((tag) => tag.name === "title");
|
|
51
|
+
return info?.text?.length
|
|
52
|
+
? CommentFactory.generate(info.text)
|
|
53
|
+
: undefined;
|
|
54
|
+
})(),
|
|
55
|
+
description: property.description,
|
|
56
|
+
"x-typia-metaTags": property.tags.length
|
|
57
|
+
? property.tags
|
|
58
|
+
: undefined,
|
|
59
|
+
"x-typia-jsDocTags": property.jsDocTags.length
|
|
60
|
+
? property.jsDocTags
|
|
61
|
+
: undefined,
|
|
62
|
+
"x-typia-required": property.value.required,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (value === null) continue;
|
|
66
|
+
else if (key !== null) {
|
|
67
|
+
properties[key] = value;
|
|
68
|
+
if (property.value.required === true) required.push(key);
|
|
69
|
+
} else {
|
|
70
|
+
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
71
|
+
if (
|
|
72
|
+
options.purpose === "swagger" ||
|
|
73
|
+
pattern === PatternUtil.STRING
|
|
74
|
+
)
|
|
75
|
+
additionalProperties.push(value);
|
|
76
|
+
else patternProperties[pattern] = value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const schema: IJsonComponents.IObject = {
|
|
81
|
+
$id:
|
|
82
|
+
options.purpose === "ajv"
|
|
83
|
+
? options.prefix + "/" + key
|
|
84
|
+
: undefined,
|
|
85
|
+
$recursiveAnchor:
|
|
86
|
+
(options.purpose === "ajv" && obj.recursive) || undefined,
|
|
87
|
+
type: "object",
|
|
88
|
+
properties,
|
|
89
|
+
patternProperties: Object.keys(patternProperties).length
|
|
90
|
+
? patternProperties
|
|
91
|
+
: undefined,
|
|
92
|
+
additionalProperties: additionalProperties.length
|
|
93
|
+
? additionalProperties.length === 1
|
|
94
|
+
? additionalProperties[0]
|
|
95
|
+
: { oneOf: additionalProperties }
|
|
96
|
+
: undefined,
|
|
97
|
+
nullable,
|
|
98
|
+
required: required.length ? required : undefined,
|
|
99
|
+
description: obj.description,
|
|
100
|
+
"x-typia_jsDocTags": obj.jsDocTags,
|
|
101
|
+
};
|
|
102
|
+
components.schemas[key] = schema;
|
|
103
|
+
};
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
-
|
|
4
|
-
import { application_default_string } from "./application_default_string";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const application_string = (
|
|
10
|
-
meta: Metadata,
|
|
11
|
-
attribute: IJsonSchema.IAttribute,
|
|
12
|
-
): IJsonSchema.IString => {
|
|
13
|
-
const output: IJsonSchema.IString = {
|
|
14
|
-
type: "string",
|
|
15
|
-
nullable: meta.nullable,
|
|
16
|
-
...attribute,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// FORMAT TAG OF METADATA
|
|
20
|
-
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
21
|
-
(tag) => tag.name === "format",
|
|
22
|
-
);
|
|
23
|
-
if (formatJsdocTag?.text?.length)
|
|
24
|
-
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
25
|
-
|
|
26
|
-
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
27
|
-
for (const tag of attribute["x-typia-metaTags"] || []) {
|
|
28
|
-
// RANGE
|
|
29
|
-
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
30
|
-
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
31
|
-
else if (tag.kind === "length") {
|
|
32
|
-
if (tag.minimum !== undefined)
|
|
33
|
-
output.minLength =
|
|
34
|
-
tag.minimum.value + (tag.minimum.include ? 0 : 1);
|
|
35
|
-
if (tag.maximum !== undefined)
|
|
36
|
-
output.maxLength =
|
|
37
|
-
tag.maximum.value - (tag.maximum.include ? 0 : 1);
|
|
38
|
-
}
|
|
39
|
-
// FORMAT AND PATTERN
|
|
40
|
-
else if (tag.kind === "format") output.format = tag.value;
|
|
41
|
-
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// DEFAULT CONFIGURATION
|
|
45
|
-
output.default = application_default_string(meta, attribute)(output);
|
|
46
|
-
|
|
47
|
-
// RETURNS
|
|
48
|
-
return output;
|
|
49
|
-
};
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
+
|
|
4
|
+
import { application_default_string } from "./application_default_string";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const application_string = (
|
|
10
|
+
meta: Metadata,
|
|
11
|
+
attribute: IJsonSchema.IAttribute,
|
|
12
|
+
): IJsonSchema.IString => {
|
|
13
|
+
const output: IJsonSchema.IString = {
|
|
14
|
+
type: "string",
|
|
15
|
+
nullable: meta.nullable,
|
|
16
|
+
...attribute,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// FORMAT TAG OF METADATA
|
|
20
|
+
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
21
|
+
(tag) => tag.name === "format",
|
|
22
|
+
);
|
|
23
|
+
if (formatJsdocTag?.text?.length)
|
|
24
|
+
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
25
|
+
|
|
26
|
+
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
27
|
+
for (const tag of attribute["x-typia-metaTags"] || []) {
|
|
28
|
+
// RANGE
|
|
29
|
+
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
30
|
+
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
31
|
+
else if (tag.kind === "length") {
|
|
32
|
+
if (tag.minimum !== undefined)
|
|
33
|
+
output.minLength =
|
|
34
|
+
tag.minimum.value + (tag.minimum.include ? 0 : 1);
|
|
35
|
+
if (tag.maximum !== undefined)
|
|
36
|
+
output.maxLength =
|
|
37
|
+
tag.maximum.value - (tag.maximum.include ? 0 : 1);
|
|
38
|
+
}
|
|
39
|
+
// FORMAT AND PATTERN
|
|
40
|
+
else if (tag.kind === "format") output.format = tag.value;
|
|
41
|
+
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// DEFAULT CONFIGURATION
|
|
45
|
+
output.default = application_default_string(meta, attribute)(output);
|
|
46
|
+
|
|
47
|
+
// RETURNS
|
|
48
|
+
return output;
|
|
49
|
+
};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { IJsDocTagInfo } from "../metadata/IJsDocTagInfo";
|
|
2
|
-
|
|
3
|
-
import { IJsonSchema } from "./IJsonSchema";
|
|
4
|
-
|
|
5
|
-
export interface IJsonComponents {
|
|
6
|
-
schemas: Record<string, IJsonComponents.IObject>;
|
|
7
|
-
}
|
|
8
|
-
export namespace IJsonComponents {
|
|
9
|
-
export interface IObject {
|
|
10
|
-
$id?: string;
|
|
11
|
-
type: "object";
|
|
12
|
-
nullable: boolean;
|
|
13
|
-
|
|
14
|
-
properties: Record<string, IJsonSchema>;
|
|
15
|
-
patternProperties?: Record<string, IJsonSchema>;
|
|
16
|
-
additionalProperties?: IJsonSchema;
|
|
17
|
-
|
|
18
|
-
required?: string[];
|
|
19
|
-
description?: string;
|
|
20
|
-
"x-typia_jsDocTags"?: IJsDocTagInfo[];
|
|
21
|
-
|
|
22
|
-
$recursiveAnchor?: boolean;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
import { IJsDocTagInfo } from "../metadata/IJsDocTagInfo";
|
|
2
|
+
|
|
3
|
+
import { IJsonSchema } from "./IJsonSchema";
|
|
4
|
+
|
|
5
|
+
export interface IJsonComponents {
|
|
6
|
+
schemas: Record<string, IJsonComponents.IObject>;
|
|
7
|
+
}
|
|
8
|
+
export namespace IJsonComponents {
|
|
9
|
+
export interface IObject {
|
|
10
|
+
$id?: string;
|
|
11
|
+
type: "object";
|
|
12
|
+
nullable: boolean;
|
|
13
|
+
|
|
14
|
+
properties: Record<string, IJsonSchema>;
|
|
15
|
+
patternProperties?: Record<string, IJsonSchema>;
|
|
16
|
+
additionalProperties?: IJsonSchema;
|
|
17
|
+
|
|
18
|
+
required?: string[];
|
|
19
|
+
description?: string;
|
|
20
|
+
"x-typia_jsDocTags"?: IJsDocTagInfo[];
|
|
21
|
+
|
|
22
|
+
$recursiveAnchor?: boolean;
|
|
23
|
+
}
|
|
24
|
+
}
|