@nestia/sdk 2.0.0-dev.20230831-5 → 2.0.0-dev.20230901-2
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/assets/bundle/api/utils/NestiaSimulator.ts +1 -22
- package/lib/NestiaSdkApplication.js +1 -1
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/ControllerAnalyzer.js +11 -5
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ExceptionAnalyzer.js +7 -2
- package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
- package/lib/analyses/ImportAnalyzer.js +1 -1
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js +0 -10
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaSdkConfig.js +37 -46
- package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +10 -0
- package/lib/generates/SwaggerGenerator.js +37 -497
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +5 -44
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +13 -11
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkSimulationProgrammer.js +4 -4
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +19 -0
- package/lib/generates/internal/SwaggerSchemaGenerator.js +301 -0
- package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -0
- package/lib/generates/internal/SwaggerSchemaValidator.d.ts +7 -0
- package/lib/generates/internal/SwaggerSchemaValidator.js +196 -0
- package/lib/generates/internal/SwaggerSchemaValidator.js.map +1 -0
- package/lib/structures/IController.d.ts +0 -4
- package/lib/structures/IRoute.d.ts +6 -3
- package/lib/structures/ISwaggerError.d.ts +6 -0
- package/lib/structures/ISwaggerError.js +3 -0
- package/lib/structures/ISwaggerError.js.map +1 -0
- package/lib/structures/ISwaggerRoute.d.ts +2 -1
- package/lib/structures/ISwaggerSchemaTuple.d.ts +6 -0
- package/lib/structures/ISwaggerSchemaTuple.js +3 -0
- package/lib/structures/ISwaggerSchemaTuple.js.map +1 -0
- package/lib/structures/ITypeTuple.d.ts +1 -1
- package/lib/utils/ImportDictionary.d.ts +1 -2
- package/lib/utils/ImportDictionary.js +28 -24
- package/lib/utils/ImportDictionary.js.map +1 -1
- package/package.json +5 -5
- package/src/NestiaSdkApplication.ts +1 -1
- package/src/analyses/ControllerAnalyzer.ts +13 -4
- package/src/analyses/ExceptionAnalyzer.ts +3 -2
- package/src/analyses/ImportAnalyzer.ts +1 -1
- package/src/analyses/ReflectAnalyzer.ts +0 -10
- package/src/generates/SwaggerGenerator.ts +102 -478
- package/src/generates/internal/E2eFileProgrammer.ts +7 -49
- package/src/generates/internal/SdkFunctionProgrammer.ts +14 -12
- package/src/generates/internal/SdkSimulationProgrammer.ts +5 -5
- package/src/generates/internal/SwaggerSchemaGenerator.ts +433 -0
- package/src/generates/internal/SwaggerSchemaValidator.ts +216 -0
- package/src/structures/IController.ts +0 -4
- package/src/structures/IRoute.ts +6 -3
- package/src/structures/ISwaggerError.ts +8 -0
- package/src/structures/ISwaggerRoute.ts +2 -1
- package/src/structures/ISwaggerSchemaTuple.ts +7 -0
- package/src/structures/ITypeTuple.ts +1 -1
- package/src/utils/ImportDictionary.ts +29 -26
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
2
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
+
import { MetadataArray } from "typia/lib/schemas/metadata/MetadataArray";
|
|
4
|
+
|
|
5
|
+
export namespace SwaggerSchemaValidator {
|
|
6
|
+
export const path = (meta: Metadata): string[] => {
|
|
7
|
+
const errors: string[] = [];
|
|
8
|
+
const insert = (msg: string) => errors.push(msg);
|
|
9
|
+
|
|
10
|
+
if (meta.any) insert("do not allow any type");
|
|
11
|
+
if (meta.isRequired() === false)
|
|
12
|
+
insert("do not allow undefindable type");
|
|
13
|
+
|
|
14
|
+
const atomics = CoreMetadataUtil.atomics(meta);
|
|
15
|
+
const expected: number =
|
|
16
|
+
meta.atomics.length +
|
|
17
|
+
meta.templates.length +
|
|
18
|
+
meta.constants
|
|
19
|
+
.map((c) => c.values.length)
|
|
20
|
+
.reduce((a, b) => a + b, 0);
|
|
21
|
+
if (meta.size() !== expected || atomics.size === 0)
|
|
22
|
+
insert("only atomic or constant types are allowed");
|
|
23
|
+
if (atomics.size > 1) insert("do not allow union type");
|
|
24
|
+
|
|
25
|
+
return errors;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const query = (
|
|
29
|
+
meta: Metadata,
|
|
30
|
+
explore: MetadataFactory.IExplore,
|
|
31
|
+
): string[] => {
|
|
32
|
+
const errors: string[] = [];
|
|
33
|
+
const insert = (msg: string) => errors.push(msg);
|
|
34
|
+
|
|
35
|
+
if (explore.top === true) {
|
|
36
|
+
// TOP MUST BE ONLY OBJECT
|
|
37
|
+
if (meta.objects.length !== 1 || meta.bucket() !== 1)
|
|
38
|
+
insert("only one object type is allowed.");
|
|
39
|
+
if (meta.nullable === true)
|
|
40
|
+
insert("query parameters cannot be null.");
|
|
41
|
+
if (meta.isRequired() === false)
|
|
42
|
+
insert("query parameters cannot be undefined.");
|
|
43
|
+
} else if (
|
|
44
|
+
explore.nested !== null &&
|
|
45
|
+
explore.nested instanceof MetadataArray
|
|
46
|
+
) {
|
|
47
|
+
const atomics = CoreMetadataUtil.atomics(meta);
|
|
48
|
+
const expected: number =
|
|
49
|
+
meta.atomics.length +
|
|
50
|
+
meta.templates.length +
|
|
51
|
+
meta.constants
|
|
52
|
+
.map((c) => c.values.length)
|
|
53
|
+
.reduce((a, b) => a + b, 0);
|
|
54
|
+
if (atomics.size > 1) insert("union type is not allowed in array.");
|
|
55
|
+
if (meta.nullable) insert("nullable type is not allowed in array.");
|
|
56
|
+
if (meta.isRequired() === false)
|
|
57
|
+
insert("optional type is not allowed in array.");
|
|
58
|
+
if (meta.size() !== expected)
|
|
59
|
+
insert("only atomic or constant types are allowed in array.");
|
|
60
|
+
} else if (explore.object && explore.property !== null) {
|
|
61
|
+
//----
|
|
62
|
+
// COMMON
|
|
63
|
+
//----
|
|
64
|
+
// PROPERTY MUST BE SOLE
|
|
65
|
+
if (typeof explore.property === "object")
|
|
66
|
+
insert("dynamic property is not allowed.");
|
|
67
|
+
// DO NOT ALLOW TUPLE TYPE
|
|
68
|
+
if (meta.tuples.length) insert("tuple type is not allowed.");
|
|
69
|
+
// DO NOT ALLOW UNION TYPE
|
|
70
|
+
if (CoreMetadataUtil.isUnion(meta))
|
|
71
|
+
insert("union type is not allowed.");
|
|
72
|
+
// DO NOT ALLOW NESTED OBJECT
|
|
73
|
+
if (
|
|
74
|
+
meta.objects.length ||
|
|
75
|
+
meta.sets.length ||
|
|
76
|
+
meta.maps.length ||
|
|
77
|
+
meta.natives.length
|
|
78
|
+
)
|
|
79
|
+
insert("nested object type is not allowed.");
|
|
80
|
+
|
|
81
|
+
//----
|
|
82
|
+
// ARRAY CASES
|
|
83
|
+
//----
|
|
84
|
+
const isArray: boolean =
|
|
85
|
+
meta.arrays.length > 1 || meta.tuples.length > 1;
|
|
86
|
+
// ARRAY TYPE MUST BE REQUIRED
|
|
87
|
+
if (isArray && meta.isRequired() === false)
|
|
88
|
+
insert("optional type is not allowed when array.");
|
|
89
|
+
// SET-COOKIE MUST BE ARRAY
|
|
90
|
+
if (explore.property === "set-cookie" && !isArray)
|
|
91
|
+
insert("set-cookie property must be array.");
|
|
92
|
+
}
|
|
93
|
+
return errors;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const headers = (
|
|
97
|
+
meta: Metadata,
|
|
98
|
+
explore: MetadataFactory.IExplore,
|
|
99
|
+
): string[] => {
|
|
100
|
+
const errors: string[] = [];
|
|
101
|
+
const insert = (msg: string) => errors.push(msg);
|
|
102
|
+
|
|
103
|
+
if (explore.top === true) {
|
|
104
|
+
// TOP MUST BE ONLY OBJECT
|
|
105
|
+
if (meta.objects.length !== 1 || meta.bucket() !== 1)
|
|
106
|
+
insert("only one object type is allowed.");
|
|
107
|
+
if (meta.nullable === true) insert("headers cannot be null.");
|
|
108
|
+
if (meta.isRequired() === false) insert("headers cannot be null.");
|
|
109
|
+
} else if (
|
|
110
|
+
explore.nested !== null &&
|
|
111
|
+
explore.nested instanceof MetadataArray
|
|
112
|
+
) {
|
|
113
|
+
const atomics = CoreMetadataUtil.atomics(meta);
|
|
114
|
+
const expected: number =
|
|
115
|
+
meta.atomics.length +
|
|
116
|
+
meta.templates.length +
|
|
117
|
+
meta.constants
|
|
118
|
+
.map((c) => c.values.length)
|
|
119
|
+
.reduce((a, b) => a + b, 0);
|
|
120
|
+
if (atomics.size > 1) insert("union type is not allowed in array.");
|
|
121
|
+
if (meta.nullable) insert("nullable type is not allowed in array.");
|
|
122
|
+
if (meta.isRequired() === false)
|
|
123
|
+
insert("optional type is not allowed.");
|
|
124
|
+
if (meta.size() !== expected)
|
|
125
|
+
insert("only atomic or constant types are allowed in array.");
|
|
126
|
+
} else if (explore.object && explore.property !== null) {
|
|
127
|
+
//----
|
|
128
|
+
// COMMON
|
|
129
|
+
//----
|
|
130
|
+
// PROPERTY MUST BE SOLE
|
|
131
|
+
if (typeof explore.property === "object")
|
|
132
|
+
insert("dynamic property is not allowed.");
|
|
133
|
+
// MUST BE LOWER-CASE
|
|
134
|
+
if (
|
|
135
|
+
typeof explore.property === "string" &&
|
|
136
|
+
explore.property !== explore.property.toLowerCase()
|
|
137
|
+
)
|
|
138
|
+
insert("property name must be lower-case.");
|
|
139
|
+
// DO NOT ALLOW TUPLE TYPE
|
|
140
|
+
if (meta.tuples.length) insert("tuple type is not allowed.");
|
|
141
|
+
// DO NOT ALLOW UNION TYPE
|
|
142
|
+
if (CoreMetadataUtil.isUnion(meta))
|
|
143
|
+
insert("union type is not allowed.");
|
|
144
|
+
// DO NOT ALLOW NESTED OBJECT
|
|
145
|
+
if (
|
|
146
|
+
meta.objects.length ||
|
|
147
|
+
meta.sets.length ||
|
|
148
|
+
meta.maps.length ||
|
|
149
|
+
meta.natives.length
|
|
150
|
+
)
|
|
151
|
+
insert("nested object type is not allowed.");
|
|
152
|
+
// DO NOT ALLOW NULLABLE
|
|
153
|
+
if (meta.nullable) insert("nullable type is not allowed.");
|
|
154
|
+
|
|
155
|
+
//----
|
|
156
|
+
// ARRAY CASES
|
|
157
|
+
//----
|
|
158
|
+
const isArray: boolean = meta.arrays.length > 1;
|
|
159
|
+
// ARRAY TYPE MUST BE REQUIRED
|
|
160
|
+
if (isArray && meta.isRequired() === false)
|
|
161
|
+
insert("optional type is not allowed when array.");
|
|
162
|
+
// SET-COOKIE MUST BE ARRAY
|
|
163
|
+
if (explore.property === "set-cookie" && !isArray)
|
|
164
|
+
insert("set-cookie property must be array.");
|
|
165
|
+
// MUST BE SINGULAR CASE
|
|
166
|
+
if (
|
|
167
|
+
typeof explore.property === "string" &&
|
|
168
|
+
SINGULAR.has(explore.property) &&
|
|
169
|
+
isArray
|
|
170
|
+
)
|
|
171
|
+
insert("property cannot be array.");
|
|
172
|
+
}
|
|
173
|
+
return errors;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
namespace CoreMetadataUtil {
|
|
178
|
+
export const atomics = (
|
|
179
|
+
meta: Metadata,
|
|
180
|
+
): Set<"boolean" | "bigint" | "number" | "string"> =>
|
|
181
|
+
new Set([
|
|
182
|
+
...meta.atomics.map((a) => a.type),
|
|
183
|
+
...meta.constants.map((c) => c.type),
|
|
184
|
+
...(meta.templates.length ? (["string"] as const) : []),
|
|
185
|
+
]);
|
|
186
|
+
|
|
187
|
+
export const isUnion = (meta: Metadata): boolean =>
|
|
188
|
+
atomics(meta).size +
|
|
189
|
+
meta.arrays.length +
|
|
190
|
+
meta.tuples.length +
|
|
191
|
+
meta.natives.length +
|
|
192
|
+
meta.maps.length +
|
|
193
|
+
meta.objects.length >
|
|
194
|
+
1;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const SINGULAR: Set<string> = new Set([
|
|
198
|
+
"age",
|
|
199
|
+
"authorization",
|
|
200
|
+
"content-length",
|
|
201
|
+
"content-type",
|
|
202
|
+
"etag",
|
|
203
|
+
"expires",
|
|
204
|
+
"from",
|
|
205
|
+
"host",
|
|
206
|
+
"if-modified-since",
|
|
207
|
+
"if-unmodified-since",
|
|
208
|
+
"last-modified",
|
|
209
|
+
"location",
|
|
210
|
+
"max-forwards",
|
|
211
|
+
"proxy-authorization",
|
|
212
|
+
"referer",
|
|
213
|
+
"retry-after",
|
|
214
|
+
"server",
|
|
215
|
+
"user-agent",
|
|
216
|
+
]);
|
package/src/structures/IRoute.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
import { IController } from "./IController";
|
|
4
|
-
import { ITypeTuple } from "./ITypeTuple";
|
|
5
4
|
|
|
6
5
|
export interface IRoute {
|
|
7
6
|
name: string;
|
|
@@ -18,6 +17,7 @@ export interface IRoute {
|
|
|
18
17
|
location: string;
|
|
19
18
|
symbol: string;
|
|
20
19
|
description?: string;
|
|
20
|
+
operationId?: string;
|
|
21
21
|
tags: ts.JSDocTagInfo[];
|
|
22
22
|
setHeaders: Array<
|
|
23
23
|
| { type: "setter"; source: string; target?: string }
|
|
@@ -30,9 +30,12 @@ export interface IRoute {
|
|
|
30
30
|
export namespace IRoute {
|
|
31
31
|
export type IParameter = IController.IParameter & {
|
|
32
32
|
optional: boolean;
|
|
33
|
-
type:
|
|
33
|
+
type: ts.Type;
|
|
34
|
+
typeName: string;
|
|
34
35
|
};
|
|
35
|
-
export interface IOutput
|
|
36
|
+
export interface IOutput {
|
|
37
|
+
type: ts.Type;
|
|
38
|
+
typeName: string;
|
|
36
39
|
description?: string;
|
|
37
40
|
contentType: "application/json" | "text/plain";
|
|
38
41
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IJsonSchema } from "typia";
|
|
2
|
-
import { IJsDocTagInfo } from "typia/lib/metadata/IJsDocTagInfo";
|
|
2
|
+
import { IJsDocTagInfo } from "typia/lib/schemas/metadata/IJsDocTagInfo";
|
|
3
3
|
|
|
4
4
|
export interface ISwaggerRoute {
|
|
5
5
|
deprecated?: boolean;
|
|
6
6
|
security?: Record<string, string[]>[];
|
|
7
|
+
operationId?: string;
|
|
7
8
|
tags: string[];
|
|
8
9
|
parameters: ISwaggerRoute.IParameter[];
|
|
9
10
|
requestBody?: ISwaggerRoute.IRequestBody;
|
|
@@ -4,20 +4,18 @@ import { HashSet } from "tstl/container/HashSet";
|
|
|
4
4
|
import { Pair } from "tstl/utility/Pair";
|
|
5
5
|
|
|
6
6
|
export class ImportDictionary {
|
|
7
|
-
private readonly
|
|
8
|
-
new HashMap();
|
|
9
|
-
private readonly internals_: HashMap<Pair<string, boolean>, IComposition> =
|
|
7
|
+
private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
|
|
10
8
|
new HashMap();
|
|
11
9
|
|
|
12
10
|
public empty(): boolean {
|
|
13
|
-
return this.
|
|
11
|
+
return this.components_.empty();
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
public external(props: ImportDictionary.IExternalProps): string {
|
|
17
|
-
const composition: IComposition = this.
|
|
15
|
+
const composition: IComposition = this.components_.take(
|
|
18
16
|
new Pair(props.library, props.type),
|
|
19
17
|
() => ({
|
|
20
|
-
location: props.library
|
|
18
|
+
location: `node_modules/${props.library}`,
|
|
21
19
|
elements: new HashSet(),
|
|
22
20
|
default: false,
|
|
23
21
|
type: props.type,
|
|
@@ -36,7 +34,7 @@ export class ImportDictionary {
|
|
|
36
34
|
return props.file.substring(0, props.file.length - 3);
|
|
37
35
|
return props.file;
|
|
38
36
|
})();
|
|
39
|
-
const composition: IComposition = this.
|
|
37
|
+
const composition: IComposition = this.components_.take(
|
|
40
38
|
new Pair(file, props.type),
|
|
41
39
|
() => ({
|
|
42
40
|
location: file,
|
|
@@ -53,12 +51,26 @@ export class ImportDictionary {
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
public toScript(outDir: string): string {
|
|
56
|
-
const
|
|
54
|
+
const external: string[] = [];
|
|
55
|
+
const internal: string[] = [];
|
|
56
|
+
|
|
57
|
+
const locator = (str: string) => {
|
|
58
|
+
const location: string = path
|
|
59
|
+
.relative(outDir, str)
|
|
60
|
+
.split("\\")
|
|
61
|
+
.join("/");
|
|
62
|
+
const index: number = location.lastIndexOf(NODE_MODULES);
|
|
63
|
+
return index === -1
|
|
64
|
+
? location.startsWith("..")
|
|
65
|
+
? location
|
|
66
|
+
: `./${location}`
|
|
67
|
+
: location.substring(index + NODE_MODULES.length);
|
|
68
|
+
};
|
|
57
69
|
const enroll =
|
|
58
|
-
(
|
|
59
|
-
|
|
60
|
-
const compositions: IComposition[] = dict
|
|
70
|
+
(filter: (str: string) => boolean) => (container: string[]) => {
|
|
71
|
+
const compositions: IComposition[] = this.components_
|
|
61
72
|
.toJSON()
|
|
73
|
+
.filter((c) => filter(c.second.location))
|
|
62
74
|
.map((e) => ({
|
|
63
75
|
...e.second,
|
|
64
76
|
location: locator(e.second.location),
|
|
@@ -74,7 +86,7 @@ export class ImportDictionary {
|
|
|
74
86
|
.sort((a, b) => a.localeCompare(b))
|
|
75
87
|
.join(", ")} }`,
|
|
76
88
|
);
|
|
77
|
-
|
|
89
|
+
container.push(
|
|
78
90
|
`import ${c.type ? "type " : ""}${brackets.join(
|
|
79
91
|
", ",
|
|
80
92
|
)} from "${c.location}";`,
|
|
@@ -82,20 +94,11 @@ export class ImportDictionary {
|
|
|
82
94
|
}
|
|
83
95
|
};
|
|
84
96
|
|
|
85
|
-
enroll((str) => str)(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
.relative(outDir, str)
|
|
91
|
-
.split("\\")
|
|
92
|
-
.join("/");
|
|
93
|
-
const index: number = location.lastIndexOf(NODE_MODULES);
|
|
94
|
-
return index === -1
|
|
95
|
-
? `./${location}`
|
|
96
|
-
: location.substring(index + NODE_MODULES.length);
|
|
97
|
-
})(this.internals_);
|
|
98
|
-
return statements.join("\n");
|
|
97
|
+
enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
|
|
98
|
+
enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
|
|
99
|
+
|
|
100
|
+
if (external.length && internal.length) external.push("");
|
|
101
|
+
return [...external, ...internal].join("\n");
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
export namespace ImportDictionary {
|