typia 6.7.3-dev.20240808 → 6.8.0-dev.20240811

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.
Files changed (109) hide show
  1. package/lib/factories/TypeFactory.d.ts +0 -2
  2. package/lib/factories/TypeFactory.js +4 -83
  3. package/lib/factories/TypeFactory.js.map +1 -1
  4. package/lib/factories/internal/metadata/emplace_metadata_array_type.js +1 -5
  5. package/lib/factories/internal/metadata/emplace_metadata_array_type.js.map +1 -1
  6. package/lib/factories/internal/metadata/emplace_metadata_object.js +3 -4
  7. package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
  8. package/lib/factories/internal/metadata/iterate_metadata.js +1 -2
  9. package/lib/factories/internal/metadata/iterate_metadata.js.map +1 -1
  10. package/lib/factories/internal/metadata/iterate_metadata_array.js +1 -2
  11. package/lib/factories/internal/metadata/iterate_metadata_array.js.map +1 -1
  12. package/lib/factories/internal/metadata/iterate_metadata_atomic.js +1 -1
  13. package/lib/factories/internal/metadata/iterate_metadata_atomic.js.map +1 -1
  14. package/lib/factories/internal/metadata/iterate_metadata_coalesce.js +1 -1
  15. package/lib/factories/internal/metadata/iterate_metadata_coalesce.js.map +1 -1
  16. package/lib/factories/internal/metadata/iterate_metadata_constant.js +2 -3
  17. package/lib/factories/internal/metadata/iterate_metadata_constant.js.map +1 -1
  18. package/lib/factories/internal/metadata/iterate_metadata_intersection.js +2 -3
  19. package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
  20. package/lib/factories/internal/metadata/iterate_metadata_map.js +1 -1
  21. package/lib/factories/internal/metadata/iterate_metadata_map.js.map +1 -1
  22. package/lib/factories/internal/metadata/iterate_metadata_native.js +1 -1
  23. package/lib/factories/internal/metadata/iterate_metadata_native.js.map +1 -1
  24. package/lib/factories/internal/metadata/iterate_metadata_object.js +2 -3
  25. package/lib/factories/internal/metadata/iterate_metadata_object.js.map +1 -1
  26. package/lib/factories/internal/metadata/iterate_metadata_set.js +1 -1
  27. package/lib/factories/internal/metadata/iterate_metadata_set.js.map +1 -1
  28. package/lib/factories/internal/metadata/iterate_metadata_template.js +1 -1
  29. package/lib/factories/internal/metadata/iterate_metadata_template.js.map +1 -1
  30. package/lib/factories/internal/metadata/iterate_metadata_union.js +1 -2
  31. package/lib/factories/internal/metadata/iterate_metadata_union.js.map +1 -1
  32. package/lib/programmers/internal/application_bigint.d.ts +1 -0
  33. package/lib/programmers/internal/application_bigint.js +14 -0
  34. package/lib/programmers/internal/application_bigint.js.map +1 -0
  35. package/lib/programmers/internal/application_v30_schema.js +10 -12
  36. package/lib/programmers/internal/application_v30_schema.js.map +1 -1
  37. package/lib/programmers/internal/application_v31_constant.js +3 -1
  38. package/lib/programmers/internal/application_v31_constant.js.map +1 -1
  39. package/lib/programmers/internal/application_v31_schema.js +10 -12
  40. package/lib/programmers/internal/application_v31_schema.js.map +1 -1
  41. package/lib/tags/Constant.d.ts +2 -2
  42. package/lib/tags/Default.d.ts +5 -1
  43. package/lib/tags/ExclusiveMaximum.d.ts +9 -5
  44. package/lib/tags/ExclusiveMinimum.d.ts +9 -5
  45. package/lib/tags/JsonSchemaPlugin.d.ts +1 -1
  46. package/lib/tags/Maximum.d.ts +8 -5
  47. package/lib/tags/Minimum.d.ts +8 -5
  48. package/lib/tags/MultipleOf.d.ts +7 -4
  49. package/lib/transformers/features/CreateRandomTransformer.js +1 -2
  50. package/lib/transformers/features/CreateRandomTransformer.js.map +1 -1
  51. package/lib/transformers/features/RandomTransformer.js +1 -2
  52. package/lib/transformers/features/RandomTransformer.js.map +1 -1
  53. package/lib/transformers/features/json/JsonApplicationTransformer.js +4 -5
  54. package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
  55. package/lib/transformers/features/misc/MiscLiteralsTransformer.js +1 -2
  56. package/lib/transformers/features/misc/MiscLiteralsTransformer.js.map +1 -1
  57. package/lib/transformers/features/protobuf/ProtobufMessageTransformer.js +1 -2
  58. package/lib/transformers/features/protobuf/ProtobufMessageTransformer.js.map +1 -1
  59. package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +1 -2
  60. package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -1
  61. package/lib/transformers/internal/GenericTransformer.js +2 -3
  62. package/lib/transformers/internal/GenericTransformer.js.map +1 -1
  63. package/package.json +2 -2
  64. package/src/factories/CommentFactory.ts +79 -79
  65. package/src/factories/MetadataCollection.ts +274 -274
  66. package/src/factories/MetadataFactory.ts +272 -272
  67. package/src/factories/TypeFactory.ts +118 -190
  68. package/src/factories/internal/metadata/emplace_metadata_array_type.ts +42 -42
  69. package/src/factories/internal/metadata/emplace_metadata_object.ts +176 -179
  70. package/src/factories/internal/metadata/iterate_metadata.ts +94 -96
  71. package/src/factories/internal/metadata/iterate_metadata_array.ts +63 -64
  72. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
  73. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  74. package/src/factories/internal/metadata/iterate_metadata_constant.ts +76 -77
  75. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +213 -214
  76. package/src/factories/internal/metadata/iterate_metadata_map.ts +50 -50
  77. package/src/factories/internal/metadata/iterate_metadata_native.ts +220 -217
  78. package/src/factories/internal/metadata/iterate_metadata_object.ts +33 -34
  79. package/src/factories/internal/metadata/iterate_metadata_set.ts +41 -41
  80. package/src/factories/internal/metadata/iterate_metadata_template.ts +44 -44
  81. package/src/factories/internal/metadata/iterate_metadata_union.ts +27 -29
  82. package/src/programmers/internal/application_bigint.ts +25 -0
  83. package/src/programmers/internal/application_v30_alias.ts +52 -52
  84. package/src/programmers/internal/application_v30_object.ts +149 -149
  85. package/src/programmers/internal/application_v30_schema.ts +162 -159
  86. package/src/programmers/internal/application_v30_tuple.ts +33 -33
  87. package/src/programmers/internal/application_v31_constant.ts +4 -1
  88. package/src/programmers/internal/application_v31_schema.ts +159 -157
  89. package/src/programmers/json/JsonApplicationProgrammer.ts +82 -82
  90. package/src/tags/Constant.ts +2 -2
  91. package/src/tags/Default.ts +7 -3
  92. package/src/tags/ExclusiveMaximum.ts +12 -6
  93. package/src/tags/ExclusiveMinimum.ts +12 -6
  94. package/src/tags/JsonSchemaPlugin.ts +1 -1
  95. package/src/tags/Maximum.ts +9 -8
  96. package/src/tags/Minimum.ts +9 -8
  97. package/src/tags/MultipleOf.ts +9 -8
  98. package/src/transformers/FileTransformer.ts +91 -91
  99. package/src/transformers/features/CreateRandomTransformer.ts +40 -42
  100. package/src/transformers/features/RandomTransformer.ts +44 -46
  101. package/src/transformers/features/json/JsonApplicationTransformer.ts +124 -126
  102. package/src/transformers/features/misc/MiscLiteralsTransformer.ts +32 -34
  103. package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +33 -35
  104. package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +62 -64
  105. package/src/transformers/internal/GenericTransformer.ts +2 -4
  106. package/lib/utils/TypePredicator.d.ts +0 -10
  107. package/lib/utils/TypePredicator.js +0 -36
  108. package/lib/utils/TypePredicator.js.map +0 -1
  109. package/src/utils/TypePredicator.ts +0 -32
@@ -1,44 +1,44 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../schemas/metadata/Metadata";
4
- import { MetadataTemplate } from "../../../schemas/metadata/MetadataTemplate";
5
-
6
- import { MetadataCollection } from "../../MetadataCollection";
7
- import { MetadataFactory } from "../../MetadataFactory";
8
- import { MetadataHelper } from "./MetadataHelper";
9
- import { explore_metadata } from "./explore_metadata";
10
-
11
- export const iterate_metadata_template =
12
- (checker: ts.TypeChecker) =>
13
- (options: MetadataFactory.IOptions) =>
14
- (collection: MetadataCollection) =>
15
- (errors: MetadataFactory.IError[]) =>
16
- (
17
- meta: Metadata,
18
- type: ts.Type,
19
- explore: MetadataFactory.IExplore,
20
- ): boolean => {
21
- const filter = (flag: ts.TypeFlags) => (type.flags & flag) !== 0;
22
- if (!filter(ts.TypeFlags.TemplateLiteral)) return false;
23
-
24
- const template: ts.TemplateLiteralType = type as ts.TemplateLiteralType;
25
- const row: Metadata[] = [];
26
-
27
- template.texts.forEach((text, i) => {
28
- // TEXT LITERAL TYPE
29
- if (text !== "") row.push(MetadataHelper.literal_to_metadata(text));
30
-
31
- // BINDED TEMPLATE TYPE
32
- const binded: ts.Type | undefined = template.types[i];
33
- if (binded)
34
- row.push(
35
- explore_metadata(checker)(options)(collection)(errors)(binded, {
36
- ...explore,
37
- escaped: false,
38
- aliased: false,
39
- }),
40
- );
41
- });
42
- meta.templates.push(MetadataTemplate.create({ row, tags: undefined }));
43
- return true;
44
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../schemas/metadata/Metadata";
4
+ import { MetadataTemplate } from "../../../schemas/metadata/MetadataTemplate";
5
+
6
+ import { MetadataCollection } from "../../MetadataCollection";
7
+ import { MetadataFactory } from "../../MetadataFactory";
8
+ import { MetadataHelper } from "./MetadataHelper";
9
+ import { explore_metadata } from "./explore_metadata";
10
+
11
+ export const iterate_metadata_template =
12
+ (checker: ts.TypeChecker) =>
13
+ (options: MetadataFactory.IOptions) =>
14
+ (collection: MetadataCollection) =>
15
+ (errors: MetadataFactory.IError[]) =>
16
+ (
17
+ meta: Metadata,
18
+ type: ts.Type,
19
+ explore: MetadataFactory.IExplore,
20
+ ): boolean => {
21
+ const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
22
+ if (!filter(ts.TypeFlags.TemplateLiteral)) return false;
23
+
24
+ const template: ts.TemplateLiteralType = type as ts.TemplateLiteralType;
25
+ const row: Metadata[] = [];
26
+
27
+ template.texts.forEach((text, i) => {
28
+ // TEXT LITERAL TYPE
29
+ if (text !== "") row.push(MetadataHelper.literal_to_metadata(text));
30
+
31
+ // BINDED TEMPLATE TYPE
32
+ const binded: ts.Type | undefined = template.types[i];
33
+ if (binded)
34
+ row.push(
35
+ explore_metadata(checker)(options)(collection)(errors)(binded, {
36
+ ...explore,
37
+ escaped: false,
38
+ aliased: false,
39
+ }),
40
+ );
41
+ });
42
+ meta.templates.push(MetadataTemplate.create({ row, tags: undefined }));
43
+ return true;
44
+ };
@@ -1,29 +1,27 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../schemas/metadata/Metadata";
4
-
5
- import { TypePredicator } from "../../../utils/TypePredicator";
6
-
7
- import { MetadataCollection } from "../../MetadataCollection";
8
- import { MetadataFactory } from "../../MetadataFactory";
9
- import { iterate_metadata } from "./iterate_metadata";
10
-
11
- export const iterate_metadata_union =
12
- (checker: ts.TypeChecker) =>
13
- (options: MetadataFactory.IOptions) =>
14
- (collection: MetadataCollection) =>
15
- (errors: MetadataFactory.IError[]) =>
16
- (
17
- meta: Metadata,
18
- type: ts.Type,
19
- explore: MetadataFactory.IExplore,
20
- ): boolean => {
21
- if (TypePredicator.isUnion(type) === false) return false;
22
- type.types.forEach((t) =>
23
- iterate_metadata(checker)(options)(collection)(errors)(meta, t, {
24
- ...explore,
25
- aliased: false,
26
- }),
27
- );
28
- return true;
29
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../schemas/metadata/Metadata";
4
+
5
+ import { MetadataCollection } from "../../MetadataCollection";
6
+ import { MetadataFactory } from "../../MetadataFactory";
7
+ import { iterate_metadata } from "./iterate_metadata";
8
+
9
+ export const iterate_metadata_union =
10
+ (checker: ts.TypeChecker) =>
11
+ (options: MetadataFactory.IOptions) =>
12
+ (collection: MetadataCollection) =>
13
+ (errors: MetadataFactory.IError[]) =>
14
+ (
15
+ meta: Metadata,
16
+ type: ts.Type,
17
+ explore: MetadataFactory.IExplore,
18
+ ): boolean => {
19
+ if (!type.isUnion()) return false;
20
+ type.types.forEach((t) =>
21
+ iterate_metadata(checker)(options)(collection)(errors)(meta, t, {
22
+ ...explore,
23
+ aliased: false,
24
+ }),
25
+ );
26
+ return true;
27
+ };
@@ -0,0 +1,25 @@
1
+ import { OpenApi, OpenApiV3 } from "@samchon/openapi";
2
+
3
+ import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
4
+
5
+ import { application_plugin } from "./application_plugin";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const application_bigint = <Version extends "3.0" | "3.1">(
11
+ atomic: MetadataAtomic,
12
+ ): Schema<Version>[] =>
13
+ application_plugin(
14
+ {
15
+ type: "integer",
16
+ } satisfies Schema<Version>,
17
+ atomic.tags,
18
+ );
19
+
20
+ /**
21
+ * @internal
22
+ */
23
+ type Schema<Version extends "3.0" | "3.1"> = Version extends "3.0"
24
+ ? OpenApiV3.IJsonSchema.IInteger
25
+ : OpenApi.IJsonSchema.IInteger;
@@ -1,52 +1,52 @@
1
- import { OpenApiV3 } from "@samchon/openapi";
2
-
3
- import { CommentFactory } from "../../factories/CommentFactory";
4
-
5
- import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
6
- import { MetadataAlias } from "../../schemas/metadata/MetadataAlias";
7
-
8
- import { application_description } from "./application_description";
9
- import { application_v30_object } from "./application_v30_object";
10
- import { application_v30_schema } from "./application_v30_schema";
11
-
12
- /**
13
- * @internal
14
- */
15
- export const application_v30_alias =
16
- <BlockNever extends boolean>(blockNever: BlockNever) =>
17
- (components: OpenApiV3.IComponents) =>
18
- (alias: MetadataAlias) =>
19
- (nullable: boolean): OpenApiV3.IJsonSchema.IReference => {
20
- if (alias.value.size() === 1 && alias.value.objects.length === 1)
21
- return application_v30_object(components)(alias.value.objects[0]!)(
22
- nullable,
23
- ) as OpenApiV3.IJsonSchema.IReference;
24
-
25
- const key: string = `${alias.name}${nullable ? ".Nullable" : ""}`;
26
- const $ref: string = `#/components/schemas/${key}`;
27
-
28
- if (components.schemas?.[key] === undefined) {
29
- // TEMPORARY ASSIGNMENT
30
- components.schemas ??= {};
31
- components.schemas[key] = {};
32
-
33
- // GENERATE SCHEMA
34
- const schema: OpenApiV3.IJsonSchema | null = application_v30_schema(
35
- blockNever,
36
- )(components)({
37
- deprecated:
38
- alias.jsDocTags.some((tag) => tag.name === "deprecated") || undefined,
39
- title: (() => {
40
- const info: IJsDocTagInfo | undefined = alias.jsDocTags.find(
41
- (tag) => tag.name === "title",
42
- );
43
- return info?.text?.length
44
- ? CommentFactory.merge(info.text)
45
- : undefined;
46
- })(),
47
- description: application_description(alias),
48
- })(alias.value);
49
- if (schema !== null) Object.assign(components.schemas[key]!, schema);
50
- }
51
- return { $ref };
52
- };
1
+ import { OpenApiV3 } from "@samchon/openapi";
2
+
3
+ import { CommentFactory } from "../../factories/CommentFactory";
4
+
5
+ import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
6
+ import { MetadataAlias } from "../../schemas/metadata/MetadataAlias";
7
+
8
+ import { application_description } from "./application_description";
9
+ import { application_v30_object } from "./application_v30_object";
10
+ import { application_v30_schema } from "./application_v30_schema";
11
+
12
+ /**
13
+ * @internal
14
+ */
15
+ export const application_v30_alias =
16
+ <BlockNever extends boolean>(blockNever: BlockNever) =>
17
+ (components: OpenApiV3.IComponents) =>
18
+ (alias: MetadataAlias) =>
19
+ (nullable: boolean): OpenApiV3.IJsonSchema.IReference => {
20
+ if (alias.value.size() === 1 && alias.value.objects.length === 1)
21
+ return application_v30_object(components)(alias.value.objects[0]!)(
22
+ nullable,
23
+ ) as OpenApiV3.IJsonSchema.IReference;
24
+
25
+ const key: string = `${alias.name}${nullable ? ".Nullable" : ""}`;
26
+ const $ref: string = `#/components/schemas/${key}`;
27
+
28
+ if (components.schemas?.[key] === undefined) {
29
+ // TEMPORARY ASSIGNMENT
30
+ components.schemas ??= {};
31
+ components.schemas[key] = {};
32
+
33
+ // GENERATE SCHEMA
34
+ const schema: OpenApiV3.IJsonSchema | null = application_v30_schema(
35
+ blockNever,
36
+ )(components)({
37
+ deprecated:
38
+ alias.jsDocTags.some((tag) => tag.name === "deprecated") || undefined,
39
+ title: (() => {
40
+ const info: IJsDocTagInfo | undefined = alias.jsDocTags.find(
41
+ (tag) => tag.name === "title",
42
+ );
43
+ return info?.text?.length
44
+ ? CommentFactory.merge(info.text)
45
+ : undefined;
46
+ })(),
47
+ description: application_description(alias),
48
+ })(alias.value);
49
+ if (schema !== null) Object.assign(components.schemas[key]!, schema);
50
+ }
51
+ return { $ref };
52
+ };
@@ -1,149 +1,149 @@
1
- import { OpenApiV3 } from "@samchon/openapi";
2
-
3
- import { CommentFactory } from "../../factories/CommentFactory";
4
-
5
- import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
6
- import { Metadata } from "../../schemas/metadata/Metadata";
7
- import { MetadataObject } from "../../schemas/metadata/MetadataObject";
8
-
9
- import { PatternUtil } from "../../utils/PatternUtil";
10
-
11
- import { application_description } from "./application_description";
12
- import { application_v30_schema } from "./application_v30_schema";
13
- import { metadata_to_pattern } from "./metadata_to_pattern";
14
-
15
- /**
16
- * @internal
17
- */
18
- export const application_v30_object =
19
- (components: OpenApiV3.IComponents) =>
20
- (obj: MetadataObject) =>
21
- (
22
- nullable: boolean,
23
- ): OpenApiV3.IJsonSchema.IReference | OpenApiV3.IJsonSchema.IObject => {
24
- if (obj.isLiteral() === true)
25
- return create_object_schema(components)(obj)(nullable);
26
-
27
- const key: string = `${obj.name}${nullable ? ".Nullable" : ""}`;
28
- const $ref: string = `#/components/schemas/${key}`;
29
- if (components.schemas?.[key] !== undefined) return { $ref };
30
-
31
- const object: OpenApiV3.IJsonSchema = {};
32
- components.schemas ??= {};
33
- components.schemas[key] = object;
34
- Object.assign(object, create_object_schema(components)(obj)(nullable));
35
- return { $ref };
36
- };
37
-
38
- /**
39
- * @internal
40
- */
41
- const create_object_schema =
42
- (components: OpenApiV3.IComponents) =>
43
- (obj: MetadataObject) =>
44
- (nullable: boolean): OpenApiV3.IJsonSchema.IObject => {
45
- // ITERATE PROPERTIES
46
- const properties: Record<string, any> = {};
47
- const extraMeta: ISuperfluous = {
48
- patternProperties: {},
49
- additionalProperties: undefined,
50
- };
51
- const required: string[] = [];
52
-
53
- for (const property of obj.properties) {
54
- if (
55
- // FUNCTIONAL TYPE
56
- property.value.functional === true &&
57
- property.value.nullable === false &&
58
- property.value.isRequired() === true &&
59
- property.value.size() === 0
60
- )
61
- continue;
62
- else if (property.jsDocTags.find((tag) => tag.name === "hidden"))
63
- continue; // THE HIDDEN TAG
64
-
65
- const key: string | null = property.key.getSoleLiteral();
66
- const schema: OpenApiV3.IJsonSchema | null = application_v30_schema(true)(
67
- components,
68
- )({
69
- deprecated:
70
- property.jsDocTags.some((tag) => tag.name === "deprecated") ||
71
- undefined,
72
- title: (() => {
73
- const info: IJsDocTagInfo | undefined = property.jsDocTags.find(
74
- (tag) => tag.name === "title",
75
- );
76
- if (info?.text?.length) return CommentFactory.merge(info.text);
77
- else if (!property.description?.length) return undefined;
78
-
79
- const index: number = property.description.indexOf("\n");
80
- const top: string = (
81
- index === -1
82
- ? property.description
83
- : property.description.substring(0, index)
84
- ).trim();
85
- return top.endsWith(".")
86
- ? top.substring(0, top.length - 1)
87
- : undefined;
88
- })(),
89
- description: application_description(property),
90
- })(property.value);
91
-
92
- if (schema === null) continue;
93
- if (key !== null) {
94
- properties[key] = schema;
95
- if (property.value.isRequired() === true) required.push(key);
96
- } else {
97
- const pattern: string = metadata_to_pattern(true)(property.key);
98
- if (pattern === PatternUtil.STRING)
99
- extraMeta.additionalProperties = [property.value, schema];
100
- else extraMeta.patternProperties[pattern] = [property.value, schema];
101
- }
102
- }
103
-
104
- return {
105
- type: "object",
106
- properties,
107
- nullable,
108
- required: required.length ? required : undefined,
109
- title: (() => {
110
- const info: IJsDocTagInfo | undefined = obj.jsDocTags.find(
111
- (tag) => tag.name === "title",
112
- );
113
- return info?.text?.length ? CommentFactory.merge(info.text) : undefined;
114
- })(),
115
- description: application_description(obj),
116
- additionalProperties: join(components)(extraMeta),
117
- };
118
- };
119
-
120
- /**
121
- * @internal
122
- */
123
- const join =
124
- (components: OpenApiV3.IComponents) =>
125
- (extra: ISuperfluous): OpenApiV3.IJsonSchema | undefined => {
126
- // LIST UP METADATA
127
- const elements: [Metadata, OpenApiV3.IJsonSchema][] = Object.values(
128
- extra.patternProperties || {},
129
- );
130
- if (extra.additionalProperties) elements.push(extra.additionalProperties);
131
-
132
- // SHORT RETURN
133
- if (elements.length === 0) return undefined;
134
- else if (elements.length === 1) return elements[0]![1]!;
135
-
136
- // MERGE METADATA AND GENERATE VULNERABLE SCHEMA
137
- const meta: Metadata = elements
138
- .map((tuple) => tuple[0])
139
- .reduce((x, y) => Metadata.merge(x, y));
140
- return application_v30_schema(true)(components)({})(meta) ?? undefined;
141
- };
142
-
143
- /**
144
- * @internal
145
- */
146
- interface ISuperfluous {
147
- additionalProperties?: undefined | [Metadata, OpenApiV3.IJsonSchema];
148
- patternProperties: Record<string, [Metadata, OpenApiV3.IJsonSchema]>;
149
- }
1
+ import { OpenApiV3 } from "@samchon/openapi";
2
+
3
+ import { CommentFactory } from "../../factories/CommentFactory";
4
+
5
+ import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
6
+ import { Metadata } from "../../schemas/metadata/Metadata";
7
+ import { MetadataObject } from "../../schemas/metadata/MetadataObject";
8
+
9
+ import { PatternUtil } from "../../utils/PatternUtil";
10
+
11
+ import { application_description } from "./application_description";
12
+ import { application_v30_schema } from "./application_v30_schema";
13
+ import { metadata_to_pattern } from "./metadata_to_pattern";
14
+
15
+ /**
16
+ * @internal
17
+ */
18
+ export const application_v30_object =
19
+ (components: OpenApiV3.IComponents) =>
20
+ (obj: MetadataObject) =>
21
+ (
22
+ nullable: boolean,
23
+ ): OpenApiV3.IJsonSchema.IReference | OpenApiV3.IJsonSchema.IObject => {
24
+ if (obj.isLiteral() === true)
25
+ return create_object_schema(components)(obj)(nullable);
26
+
27
+ const key: string = `${obj.name}${nullable ? ".Nullable" : ""}`;
28
+ const $ref: string = `#/components/schemas/${key}`;
29
+ if (components.schemas?.[key] !== undefined) return { $ref };
30
+
31
+ const object: OpenApiV3.IJsonSchema = {};
32
+ components.schemas ??= {};
33
+ components.schemas[key] = object;
34
+ Object.assign(object, create_object_schema(components)(obj)(nullable));
35
+ return { $ref };
36
+ };
37
+
38
+ /**
39
+ * @internal
40
+ */
41
+ const create_object_schema =
42
+ (components: OpenApiV3.IComponents) =>
43
+ (obj: MetadataObject) =>
44
+ (nullable: boolean): OpenApiV3.IJsonSchema.IObject => {
45
+ // ITERATE PROPERTIES
46
+ const properties: Record<string, any> = {};
47
+ const extraMeta: ISuperfluous = {
48
+ patternProperties: {},
49
+ additionalProperties: undefined,
50
+ };
51
+ const required: string[] = [];
52
+
53
+ for (const property of obj.properties) {
54
+ if (
55
+ // FUNCTIONAL TYPE
56
+ property.value.functional === true &&
57
+ property.value.nullable === false &&
58
+ property.value.isRequired() === true &&
59
+ property.value.size() === 0
60
+ )
61
+ continue;
62
+ else if (property.jsDocTags.find((tag) => tag.name === "hidden"))
63
+ continue; // THE HIDDEN TAG
64
+
65
+ const key: string | null = property.key.getSoleLiteral();
66
+ const schema: OpenApiV3.IJsonSchema | null = application_v30_schema(true)(
67
+ components,
68
+ )({
69
+ deprecated:
70
+ property.jsDocTags.some((tag) => tag.name === "deprecated") ||
71
+ undefined,
72
+ title: (() => {
73
+ const info: IJsDocTagInfo | undefined = property.jsDocTags.find(
74
+ (tag) => tag.name === "title",
75
+ );
76
+ if (info?.text?.length) return CommentFactory.merge(info.text);
77
+ else if (!property.description?.length) return undefined;
78
+
79
+ const index: number = property.description.indexOf("\n");
80
+ const top: string = (
81
+ index === -1
82
+ ? property.description
83
+ : property.description.substring(0, index)
84
+ ).trim();
85
+ return top.endsWith(".")
86
+ ? top.substring(0, top.length - 1)
87
+ : undefined;
88
+ })(),
89
+ description: application_description(property),
90
+ })(property.value);
91
+
92
+ if (schema === null) continue;
93
+ if (key !== null) {
94
+ properties[key] = schema;
95
+ if (property.value.isRequired() === true) required.push(key);
96
+ } else {
97
+ const pattern: string = metadata_to_pattern(true)(property.key);
98
+ if (pattern === PatternUtil.STRING)
99
+ extraMeta.additionalProperties = [property.value, schema];
100
+ else extraMeta.patternProperties[pattern] = [property.value, schema];
101
+ }
102
+ }
103
+
104
+ return {
105
+ type: "object",
106
+ properties,
107
+ nullable,
108
+ required: required.length ? required : undefined,
109
+ title: (() => {
110
+ const info: IJsDocTagInfo | undefined = obj.jsDocTags.find(
111
+ (tag) => tag.name === "title",
112
+ );
113
+ return info?.text?.length ? CommentFactory.merge(info.text) : undefined;
114
+ })(),
115
+ description: application_description(obj),
116
+ additionalProperties: join(components)(extraMeta),
117
+ };
118
+ };
119
+
120
+ /**
121
+ * @internal
122
+ */
123
+ const join =
124
+ (components: OpenApiV3.IComponents) =>
125
+ (extra: ISuperfluous): OpenApiV3.IJsonSchema | undefined => {
126
+ // LIST UP METADATA
127
+ const elements: [Metadata, OpenApiV3.IJsonSchema][] = Object.values(
128
+ extra.patternProperties || {},
129
+ );
130
+ if (extra.additionalProperties) elements.push(extra.additionalProperties);
131
+
132
+ // SHORT RETURN
133
+ if (elements.length === 0) return undefined;
134
+ else if (elements.length === 1) return elements[0]![1]!;
135
+
136
+ // MERGE METADATA AND GENERATE VULNERABLE SCHEMA
137
+ const meta: Metadata = elements
138
+ .map((tuple) => tuple[0])
139
+ .reduce((x, y) => Metadata.merge(x, y));
140
+ return application_v30_schema(true)(components)({})(meta) ?? undefined;
141
+ };
142
+
143
+ /**
144
+ * @internal
145
+ */
146
+ interface ISuperfluous {
147
+ additionalProperties?: undefined | [Metadata, OpenApiV3.IJsonSchema];
148
+ patternProperties: Record<string, [Metadata, OpenApiV3.IJsonSchema]>;
149
+ }