@nestia/sdk 3.11.0-dev.20240813-11 → 3.11.0-dev.20240814-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/lib/NestiaSdkApplication.js +0 -13
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/ReflectControllerAnalyzer.js +2 -0
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +1 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +14 -7
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +2 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/TypedHttpRouteAnalyzer.js +3 -1
- package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +60 -8
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +11 -10
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +5 -1
- package/lib/generates/internal/SdkAliasCollection.js +31 -19
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +8 -7
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneProgrammer.js +4 -0
- package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.js +6 -0
- package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +20 -13
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +16 -8
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpRouteProgrammer.js +2 -2
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +6 -3
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +11 -5
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationComposer.js +19 -1
- package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +3 -3
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/transform.js +1 -1
- package/lib/transform.js.map +1 -1
- package/lib/transformers/SdkOperationProgrammer.js +17 -11
- package/lib/transformers/SdkOperationProgrammer.js.map +1 -1
- package/lib/transformers/SdkOperationTransformer.d.ts +1 -1
- package/lib/transformers/SdkOperationTransformer.js +12 -8
- package/lib/transformers/SdkOperationTransformer.js.map +1 -1
- package/lib/validators/HttpHeadersValidator.d.ts +5 -0
- package/lib/validators/HttpHeadersValidator.js +29 -0
- package/lib/validators/HttpHeadersValidator.js.map +1 -0
- package/lib/validators/HttpQueryValidator.d.ts +5 -0
- package/lib/validators/HttpQueryValidator.js +29 -0
- package/lib/validators/HttpQueryValidator.js.map +1 -0
- package/package.json +6 -6
- package/src/NestiaSdkApplication.ts +0 -14
- package/src/analyses/ReflectControllerAnalyzer.ts +2 -0
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +1 -0
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +37 -5
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +8 -0
- package/src/analyses/TypedHttpRouteAnalyzer.ts +4 -1
- package/src/generates/SwaggerGenerator.ts +84 -10
- package/src/generates/internal/E2eFileProgrammer.ts +13 -10
- package/src/generates/internal/SdkAliasCollection.ts +42 -25
- package/src/generates/internal/SdkFileProgrammer.ts +8 -7
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +4 -1
- package/src/generates/internal/SdkHttpCloneReferencer.ts +10 -0
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +25 -16
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +256 -228
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +2 -2
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +6 -3
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +23 -10
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +1 -1
- package/src/generates/internal/SwaggerOperationComposer.ts +25 -0
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +3 -0
- package/src/transform.ts +1 -1
- package/src/transformers/SdkOperationProgrammer.ts +41 -36
- package/src/transformers/SdkOperationTransformer.ts +29 -8
- package/src/validators/HttpHeadersValidator.ts +34 -0
- package/src/validators/HttpQueryValidator.ts +34 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/sdk",
|
|
3
|
-
"version": "3.11.0-dev.
|
|
3
|
+
"version": "3.11.0-dev.20240814-2",
|
|
4
4
|
"description": "Nestia SDK and Swagger generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://nestia.io",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@nestia/core": "^3.11.0-dev.
|
|
36
|
-
"@nestia/fetcher": "^3.11.0-dev.
|
|
37
|
-
"@samchon/openapi": "^0.4.
|
|
35
|
+
"@nestia/core": "^3.11.0-dev.20240814-2",
|
|
36
|
+
"@nestia/fetcher": "^3.11.0-dev.20240814-2",
|
|
37
|
+
"@samchon/openapi": "^0.4.5",
|
|
38
38
|
"@wrtnio/openai-function-schema": "^0.2.3",
|
|
39
39
|
"cli": "^1.0.1",
|
|
40
40
|
"get-function-location": "^2.0.0",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"typia": "^6.8.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@nestia/core": ">=3.11.0-dev.
|
|
52
|
-
"@nestia/fetcher": ">=3.11.0-dev.
|
|
51
|
+
"@nestia/core": ">=3.11.0-dev.20240814-2",
|
|
52
|
+
"@nestia/fetcher": ">=3.11.0-dev.20240814-2",
|
|
53
53
|
"@nestjs/common": ">=7.0.1",
|
|
54
54
|
"@nestjs/core": ">=7.0.1",
|
|
55
55
|
"reflect-metadata": ">=0.1.12",
|
|
@@ -315,20 +315,6 @@ const report = (props: {
|
|
|
315
315
|
].join("");
|
|
316
316
|
console.log(message);
|
|
317
317
|
}
|
|
318
|
-
|
|
319
|
-
// for (const [file, cMap] of map) {
|
|
320
|
-
// for (const [controller, fMap] of cMap)
|
|
321
|
-
// for (const [func, messages] of fMap) {
|
|
322
|
-
// const location: string = path.relative(process.cwd(), file);
|
|
323
|
-
// console.log(
|
|
324
|
-
// `${location} - ${
|
|
325
|
-
// func !== null ? `${controller}.${func}()` : controller
|
|
326
|
-
// }`,
|
|
327
|
-
// );
|
|
328
|
-
// for (const msg of messages) console.log(` - ${msg}`);
|
|
329
|
-
// console.log("");
|
|
330
|
-
// }
|
|
331
|
-
// }
|
|
332
318
|
};
|
|
333
319
|
|
|
334
320
|
const wrapPaths = (paths: string[]): string[] =>
|
|
@@ -72,6 +72,8 @@ export namespace ReflectControllerAnalyzer {
|
|
|
72
72
|
key,
|
|
73
73
|
);
|
|
74
74
|
if (metadata === undefined) continue;
|
|
75
|
+
else if (metadata.jsDocTags.some((tag) => tag.name === "ignore"))
|
|
76
|
+
continue;
|
|
75
77
|
const next: ReflectHttpOperationAnalyzer.IProps = {
|
|
76
78
|
project: props.project,
|
|
77
79
|
controller: controller,
|
|
@@ -107,6 +107,7 @@ export namespace ReflectHttpOperationAnalyzer {
|
|
|
107
107
|
.filter((x) => parameters.some((y) => x.index === y.index))
|
|
108
108
|
.map((x) => x.imports),
|
|
109
109
|
...props.metadata.success.imports,
|
|
110
|
+
...Object.values(props.metadata.exceptions).map((e) => e.imports),
|
|
110
111
|
].flat(),
|
|
111
112
|
),
|
|
112
113
|
description: props.metadata.description,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SwaggerExample } from "@nestia/core";
|
|
1
2
|
import { ROUTE_ARGS_METADATA } from "@nestjs/common/constants";
|
|
2
3
|
import { RouteParamtypes } from "@nestjs/common/enums/route-paramtypes.enum";
|
|
3
4
|
import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
|
|
@@ -11,6 +12,8 @@ import { IReflectHttpOperationParameter } from "../structures/IReflectHttpOperat
|
|
|
11
12
|
import { IReflectOperationError } from "../structures/IReflectOperationError";
|
|
12
13
|
import { IOperationMetadata } from "../transformers/IOperationMetadata";
|
|
13
14
|
import { TextPlainValidator } from "../transformers/TextPlainValidator";
|
|
15
|
+
import { HttpHeadersValidator } from "../validators/HttpHeadersValidator";
|
|
16
|
+
import { HttpQueryValidator } from "../validators/HttpQueryValidator";
|
|
14
17
|
|
|
15
18
|
export namespace ReflectHttpOperationParameterAnalyzer {
|
|
16
19
|
export interface IContext {
|
|
@@ -146,6 +149,14 @@ export namespace ReflectHttpOperationParameterAnalyzer {
|
|
|
146
149
|
)
|
|
147
150
|
return null; // unreachable
|
|
148
151
|
|
|
152
|
+
const example: SwaggerExample.IData<any> | undefined = (
|
|
153
|
+
Reflect.getMetadata(
|
|
154
|
+
"nestia/SwaggerExample/Parameters",
|
|
155
|
+
ctx.controller.class.prototype,
|
|
156
|
+
ctx.functionName,
|
|
157
|
+
) ?? []
|
|
158
|
+
).find((x: SwaggerExample.IData<any>) => x.index === matched.index);
|
|
159
|
+
|
|
149
160
|
// COMPOSITION
|
|
150
161
|
if (p.category === "param")
|
|
151
162
|
return {
|
|
@@ -157,21 +168,40 @@ export namespace ReflectHttpOperationParameterAnalyzer {
|
|
|
157
168
|
validate: HttpParameterProgrammer.validate,
|
|
158
169
|
description: matched.description,
|
|
159
170
|
jsDocTags: matched.jsDocTags,
|
|
171
|
+
example: example?.example,
|
|
172
|
+
examples: example?.examples,
|
|
160
173
|
...schema,
|
|
161
174
|
};
|
|
162
|
-
else if (p.category === "query"
|
|
175
|
+
else if (p.category === "query")
|
|
163
176
|
return {
|
|
164
177
|
category: p.category,
|
|
165
178
|
index: p.index,
|
|
166
179
|
field: p.field ?? null,
|
|
167
180
|
name: matched.name,
|
|
168
181
|
type: matched.type,
|
|
169
|
-
validate:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
182
|
+
validate: p.field
|
|
183
|
+
? HttpQueryValidator.validate
|
|
184
|
+
: HttpQueryProgrammer.validate,
|
|
185
|
+
description: matched.description,
|
|
186
|
+
jsDocTags: matched.jsDocTags,
|
|
187
|
+
example: example?.example,
|
|
188
|
+
examples: example?.examples,
|
|
189
|
+
...schema,
|
|
190
|
+
};
|
|
191
|
+
else if (p.category === "headers")
|
|
192
|
+
return {
|
|
193
|
+
category: p.category,
|
|
194
|
+
index: p.index,
|
|
195
|
+
field: p.field ?? null,
|
|
196
|
+
name: matched.name,
|
|
197
|
+
type: matched.type,
|
|
198
|
+
validate: p.field
|
|
199
|
+
? HttpHeadersValidator.validate
|
|
200
|
+
: HttpHeadersProgrammer.validate,
|
|
173
201
|
description: matched.description,
|
|
174
202
|
jsDocTags: matched.jsDocTags,
|
|
203
|
+
example: example?.example,
|
|
204
|
+
examples: example?.examples,
|
|
175
205
|
...schema,
|
|
176
206
|
};
|
|
177
207
|
else if (p.category === "body")
|
|
@@ -192,6 +222,8 @@ export namespace ReflectHttpOperationParameterAnalyzer {
|
|
|
192
222
|
: TextPlainValidator.validate,
|
|
193
223
|
description: matched.description,
|
|
194
224
|
jsDocTags: matched.jsDocTags,
|
|
225
|
+
example: example?.example,
|
|
226
|
+
examples: example?.examples,
|
|
195
227
|
...schema,
|
|
196
228
|
};
|
|
197
229
|
else {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SwaggerExample } from "@nestia/core";
|
|
1
2
|
import {
|
|
2
3
|
HEADERS_METADATA,
|
|
3
4
|
HTTP_CODE_METADATA,
|
|
@@ -78,6 +79,11 @@ export namespace ReflectHttpOperationResponseAnalyzer {
|
|
|
78
79
|
!typia.is<IReflectHttpOperationSuccess["contentType"]>(contentType)
|
|
79
80
|
)
|
|
80
81
|
return null;
|
|
82
|
+
|
|
83
|
+
const example: SwaggerExample.IData<any> | undefined = Reflect.getMetadata(
|
|
84
|
+
"nestia/SwaggerExample/Response",
|
|
85
|
+
ctx.function,
|
|
86
|
+
);
|
|
81
87
|
return {
|
|
82
88
|
contentType: contentType,
|
|
83
89
|
encrypted,
|
|
@@ -96,6 +102,8 @@ export namespace ReflectHttpOperationResponseAnalyzer {
|
|
|
96
102
|
meta.size()
|
|
97
103
|
? ["HEAD method must not have any return value."]
|
|
98
104
|
: [],
|
|
105
|
+
example: example?.example,
|
|
106
|
+
examples: example?.examples,
|
|
99
107
|
};
|
|
100
108
|
};
|
|
101
109
|
|
|
@@ -151,7 +151,10 @@ export namespace TypedHttpRouteAnalyzer {
|
|
|
151
151
|
},
|
|
152
152
|
),
|
|
153
153
|
};
|
|
154
|
-
if (errors.length)
|
|
154
|
+
if (errors.length) {
|
|
155
|
+
props.errors.push(...errors);
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
155
158
|
return props.paths.map((path) => ({
|
|
156
159
|
...props.operation,
|
|
157
160
|
controller: props.controller,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SwaggerCustomizer } from "@nestia/core";
|
|
1
2
|
import { OpenApi, OpenApiV3, SwaggerV2 } from "@samchon/openapi";
|
|
2
3
|
import fs from "fs";
|
|
3
4
|
import path from "path";
|
|
@@ -16,6 +17,7 @@ import { SwaggerOperationComposer } from "./internal/SwaggerOperationComposer";
|
|
|
16
17
|
export namespace SwaggerGenerator {
|
|
17
18
|
export const generate = async (app: ITypedApplication): Promise<void> => {
|
|
18
19
|
// GET CONFIGURATION
|
|
20
|
+
console.log("Generating Swagger Document");
|
|
19
21
|
if (app.project.config.swagger === undefined)
|
|
20
22
|
throw new Error("Swagger configuration is not defined.");
|
|
21
23
|
const config: INestiaConfig.ISwaggerConfig = app.project.config.swagger;
|
|
@@ -92,7 +94,7 @@ export namespace SwaggerGenerator {
|
|
|
92
94
|
const document: OpenApi.IDocument = props.document;
|
|
93
95
|
document.components.schemas ??= {};
|
|
94
96
|
Object.assign(document.components.schemas, json.components.schemas);
|
|
95
|
-
|
|
97
|
+
fillPaths({ ...props, schema, document });
|
|
96
98
|
|
|
97
99
|
return document;
|
|
98
100
|
};
|
|
@@ -175,23 +177,85 @@ export namespace SwaggerGenerator {
|
|
|
175
177
|
};
|
|
176
178
|
};
|
|
177
179
|
|
|
178
|
-
const
|
|
180
|
+
const fillPaths = (props: {
|
|
179
181
|
config: INestiaConfig.ISwaggerConfig;
|
|
180
182
|
document: OpenApi.IDocument;
|
|
181
183
|
schema: (metadata: Metadata) => OpenApi.IJsonSchema | undefined;
|
|
182
184
|
routes: ITypedHttpRoute[];
|
|
183
|
-
}):
|
|
184
|
-
|
|
185
|
+
}): void => {
|
|
186
|
+
// SWAGGER CUSTOMIZER
|
|
187
|
+
const customizers: Array<() => void> = [];
|
|
188
|
+
const neighbor = {
|
|
189
|
+
at: new Singleton(() => {
|
|
190
|
+
const functor: Map<Function, Endpoint> = new Map();
|
|
191
|
+
for (const r of props.routes) {
|
|
192
|
+
const method: OpenApi.Method =
|
|
193
|
+
r.method.toLowerCase() as OpenApi.Method;
|
|
194
|
+
const path: string = getPath(r);
|
|
195
|
+
const operation: OpenApi.IOperation | undefined =
|
|
196
|
+
props.document.paths?.[path]?.[method];
|
|
197
|
+
if (operation === undefined) continue;
|
|
198
|
+
functor.set(r.function, {
|
|
199
|
+
method,
|
|
200
|
+
path,
|
|
201
|
+
route: operation,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return functor;
|
|
205
|
+
}),
|
|
206
|
+
get: new Singleton(
|
|
207
|
+
() =>
|
|
208
|
+
(key: Accessor): OpenApi.IOperation | undefined => {
|
|
209
|
+
const method: OpenApi.Method =
|
|
210
|
+
key.method.toLowerCase() as OpenApi.Method;
|
|
211
|
+
const path: string =
|
|
212
|
+
"/" +
|
|
213
|
+
key.path
|
|
214
|
+
.split("/")
|
|
215
|
+
.filter((str) => !!str.length)
|
|
216
|
+
.map((str) =>
|
|
217
|
+
str.startsWith(":") ? `{${str.substring(1)}}` : str,
|
|
218
|
+
)
|
|
219
|
+
.join("/");
|
|
220
|
+
return props.document.paths?.[path]?.[method];
|
|
221
|
+
},
|
|
222
|
+
),
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// COMPOSE OPERATIONS
|
|
185
226
|
for (const r of props.routes) {
|
|
227
|
+
const operation: OpenApi.IOperation = SwaggerOperationComposer.compose({
|
|
228
|
+
...props,
|
|
229
|
+
route: r,
|
|
230
|
+
});
|
|
186
231
|
const path: string = getPath(r);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
232
|
+
props.document.paths ??= {};
|
|
233
|
+
props.document.paths[path] ??= {};
|
|
234
|
+
props.document.paths[path][r.method.toLowerCase() as "get"] = operation;
|
|
235
|
+
|
|
236
|
+
const closure: Function | Function[] | undefined = Reflect.getMetadata(
|
|
237
|
+
"nestia/SwaggerCustomizer",
|
|
238
|
+
r.controller.class.prototype,
|
|
239
|
+
r.name,
|
|
240
|
+
);
|
|
241
|
+
if (closure !== undefined) {
|
|
242
|
+
const array: Function[] = Array.isArray(closure) ? closure : [closure];
|
|
243
|
+
customizers.push(() => {
|
|
244
|
+
for (const closure of array)
|
|
245
|
+
closure({
|
|
246
|
+
swagger: props.document,
|
|
247
|
+
method: r.method,
|
|
248
|
+
path,
|
|
249
|
+
route: operation,
|
|
250
|
+
at: (func: Function) => neighbor.at.get().get(func),
|
|
251
|
+
get: (accessor: Accessor) => neighbor.get.get()(accessor),
|
|
252
|
+
} satisfies SwaggerCustomizer.IProps);
|
|
192
253
|
});
|
|
254
|
+
}
|
|
193
255
|
}
|
|
194
|
-
|
|
256
|
+
|
|
257
|
+
// DO CUSTOMIZE
|
|
258
|
+
for (const fn of customizers) fn();
|
|
195
259
|
};
|
|
196
260
|
|
|
197
261
|
const getPath = (route: {
|
|
@@ -207,3 +271,13 @@ export namespace SwaggerGenerator {
|
|
|
207
271
|
return str;
|
|
208
272
|
};
|
|
209
273
|
}
|
|
274
|
+
|
|
275
|
+
interface Accessor {
|
|
276
|
+
method: string;
|
|
277
|
+
path: string;
|
|
278
|
+
}
|
|
279
|
+
interface Endpoint {
|
|
280
|
+
method: string;
|
|
281
|
+
path: string;
|
|
282
|
+
route: OpenApi.IOperation;
|
|
283
|
+
}
|
|
@@ -30,13 +30,6 @@ export namespace E2eFileProgrammer {
|
|
|
30
30
|
instance: null,
|
|
31
31
|
name: "api",
|
|
32
32
|
});
|
|
33
|
-
for (const tuple of route.imports)
|
|
34
|
-
for (const instance of tuple.instances)
|
|
35
|
-
importer.internal({
|
|
36
|
-
type: true,
|
|
37
|
-
file: tuple.file,
|
|
38
|
-
instance,
|
|
39
|
-
});
|
|
40
33
|
|
|
41
34
|
const functor = generate_function(project)(importer)(route);
|
|
42
35
|
await FilePrinter.write({
|
|
@@ -73,7 +66,7 @@ export namespace E2eFileProgrammer {
|
|
|
73
66
|
(importer: ImportDictionary) =>
|
|
74
67
|
(route: ITypedHttpRoute) => {
|
|
75
68
|
const headers = route.parameters.find(
|
|
76
|
-
(p) => p.category === "headers" && p.field ===
|
|
69
|
+
(p) => p.category === "headers" && p.field === null,
|
|
77
70
|
);
|
|
78
71
|
const connection = headers
|
|
79
72
|
? ts.factory.createObjectLiteralExpression(
|
|
@@ -97,7 +90,13 @@ export namespace E2eFileProgrammer {
|
|
|
97
90
|
SdkImportWizard.typia(importer),
|
|
98
91
|
),
|
|
99
92
|
)("random"),
|
|
100
|
-
[
|
|
93
|
+
[
|
|
94
|
+
project.config.clone === true
|
|
95
|
+
? SdkAliasCollection.from(project)(importer)(
|
|
96
|
+
headers.metadata,
|
|
97
|
+
)
|
|
98
|
+
: SdkAliasCollection.name(headers),
|
|
99
|
+
],
|
|
101
100
|
undefined,
|
|
102
101
|
),
|
|
103
102
|
),
|
|
@@ -123,7 +122,11 @@ export namespace E2eFileProgrammer {
|
|
|
123
122
|
IdentifierFactory.access(
|
|
124
123
|
ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
|
|
125
124
|
)("random"),
|
|
126
|
-
[
|
|
125
|
+
[
|
|
126
|
+
project.config.clone === true
|
|
127
|
+
? SdkAliasCollection.from(project)(importer)(p.metadata)
|
|
128
|
+
: SdkAliasCollection.name(p),
|
|
129
|
+
],
|
|
127
130
|
undefined,
|
|
128
131
|
),
|
|
129
132
|
),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import typia from "typia";
|
|
3
3
|
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
4
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
4
5
|
|
|
5
6
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
6
7
|
import { IReflectHttpOperationParameter } from "../../structures/IReflectHttpOperationParameter";
|
|
@@ -8,18 +9,29 @@ import { IReflectType } from "../../structures/IReflectType";
|
|
|
8
9
|
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
9
10
|
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
10
11
|
import { ImportDictionary } from "./ImportDictionary";
|
|
12
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
11
13
|
|
|
12
14
|
export namespace SdkAliasCollection {
|
|
13
|
-
export const name = (type: IReflectType): ts.TypeNode =>
|
|
15
|
+
export const name = ({ type }: { type: IReflectType }): ts.TypeNode =>
|
|
14
16
|
ts.factory.createTypeReferenceNode(
|
|
15
17
|
type.name,
|
|
16
|
-
type.typeArguments
|
|
18
|
+
type.typeArguments
|
|
19
|
+
? type.typeArguments.map((a) => name({ type: a }))
|
|
20
|
+
: undefined,
|
|
17
21
|
);
|
|
18
22
|
|
|
23
|
+
export const from =
|
|
24
|
+
(project: INestiaProject) =>
|
|
25
|
+
(importer: ImportDictionary) =>
|
|
26
|
+
(metadata: Metadata) =>
|
|
27
|
+
SdkTypeProgrammer.write(project)(importer)(metadata);
|
|
28
|
+
|
|
19
29
|
export const headers =
|
|
20
30
|
(project: INestiaProject) =>
|
|
21
31
|
(importer: ImportDictionary) =>
|
|
22
32
|
(param: ITypedHttpRouteParameter.IHeaders): ts.TypeNode => {
|
|
33
|
+
if (project.config.clone === true)
|
|
34
|
+
return from(project)(importer)(param.metadata);
|
|
23
35
|
const type: ts.TypeNode = name(param);
|
|
24
36
|
if (project.config.primitive === false) return type;
|
|
25
37
|
return ts.factory.createTypeReferenceNode(
|
|
@@ -36,6 +48,8 @@ export namespace SdkAliasCollection {
|
|
|
36
48
|
(project: INestiaProject) =>
|
|
37
49
|
(importer: ImportDictionary) =>
|
|
38
50
|
(param: ITypedHttpRouteParameter.IQuery): ts.TypeNode => {
|
|
51
|
+
if (project.config.clone === true)
|
|
52
|
+
return from(project)(importer)(param.metadata);
|
|
39
53
|
const type: ts.TypeNode = name(param);
|
|
40
54
|
if (project.config.primitive === false) return type;
|
|
41
55
|
return ts.factory.createTypeReferenceNode(
|
|
@@ -52,9 +66,10 @@ export namespace SdkAliasCollection {
|
|
|
52
66
|
(project: INestiaProject) =>
|
|
53
67
|
(importer: ImportDictionary) =>
|
|
54
68
|
(param: ITypedHttpRouteParameter): ts.TypeNode => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
if (project.config.clone === true)
|
|
70
|
+
return from(project)(importer)(param.metadata);
|
|
71
|
+
const type: ts.TypeNode = name(param);
|
|
72
|
+
if (project.config.primitive === false) return type;
|
|
58
73
|
return ts.factory.createTypeReferenceNode(
|
|
59
74
|
importer.external({
|
|
60
75
|
type: true,
|
|
@@ -74,35 +89,37 @@ export namespace SdkAliasCollection {
|
|
|
74
89
|
(project: INestiaProject) =>
|
|
75
90
|
(importer: ImportDictionary) =>
|
|
76
91
|
(route: ITypedHttpRoute): ts.TypeNode => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
const schema = (p: { metadata: Metadata; type: IReflectType }) =>
|
|
93
|
+
p.metadata.size() === 0
|
|
94
|
+
? TypeFactory.keyword("void")
|
|
95
|
+
: project.config.clone === true
|
|
96
|
+
? from(project)(importer)(p.metadata)
|
|
97
|
+
: project.config.primitive !== false
|
|
98
|
+
? ts.factory.createTypeReferenceNode(
|
|
99
|
+
importer.external({
|
|
100
|
+
type: true,
|
|
101
|
+
library: "@nestia/fetcher",
|
|
102
|
+
instance:
|
|
103
|
+
route.success.contentType === "application/json" ||
|
|
104
|
+
route.success.encrypted === true
|
|
105
|
+
? "Primitive"
|
|
106
|
+
: "Resolved",
|
|
107
|
+
}),
|
|
108
|
+
[name(p)],
|
|
109
|
+
)
|
|
110
|
+
: name(p);
|
|
111
|
+
if (project.config.propagate !== true) return schema(route.success);
|
|
95
112
|
|
|
96
113
|
const branches: IBranch[] = [
|
|
97
114
|
{
|
|
98
115
|
status: String(
|
|
99
116
|
route.success.status ?? (route.method === "POST" ? 201 : 200),
|
|
100
117
|
),
|
|
101
|
-
type:
|
|
118
|
+
type: schema(route.success),
|
|
102
119
|
},
|
|
103
120
|
...Object.entries(route.exceptions).map(([status, value]) => ({
|
|
104
121
|
status,
|
|
105
|
-
type:
|
|
122
|
+
type: schema(value),
|
|
106
123
|
})),
|
|
107
124
|
];
|
|
108
125
|
return ts.factory.createTypeReferenceNode(
|
|
@@ -75,13 +75,14 @@ export namespace SdkFileProgrammer {
|
|
|
75
75
|
`${outDir}/index.ts`,
|
|
76
76
|
);
|
|
77
77
|
directory.routes.forEach((route, i) => {
|
|
78
|
-
|
|
79
|
-
for (const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
if (!(project.config.clone === true && route.protocol === "http"))
|
|
79
|
+
for (const tuple of route.imports)
|
|
80
|
+
for (const instance of tuple.instances)
|
|
81
|
+
importer.internal({
|
|
82
|
+
file: tuple.file,
|
|
83
|
+
instance,
|
|
84
|
+
type: true,
|
|
85
|
+
});
|
|
85
86
|
statements.push(
|
|
86
87
|
...(route.protocol === "http"
|
|
87
88
|
? SdkHttpRouteProgrammer.write(project)(importer)(route)
|
|
@@ -23,6 +23,10 @@ export namespace SdkHttpCloneProgrammer {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const write = (app: ITypedApplication): Map<string, IModule> => {
|
|
26
|
+
// console.log({
|
|
27
|
+
// objects: Array.from(app.collection.objects.keys()).sort(),
|
|
28
|
+
// aliases: Array.from(app.collection.aliases.keys()).sort(),
|
|
29
|
+
// });
|
|
26
30
|
// COMPOSE THE DICTIONARY
|
|
27
31
|
const dict: Map<string, IModule> = new Map();
|
|
28
32
|
for (const [k, v] of app.collection.objects.entries())
|
|
@@ -39,7 +43,6 @@ export namespace SdkHttpCloneProgrammer {
|
|
|
39
43
|
name: k,
|
|
40
44
|
programmer: (importer) => write_alias(app.project)(importer)(v),
|
|
41
45
|
});
|
|
42
|
-
|
|
43
46
|
return dict;
|
|
44
47
|
};
|
|
45
48
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
2
2
|
|
|
3
|
+
import { IReflectType } from "../../structures/IReflectType";
|
|
3
4
|
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
4
5
|
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
5
6
|
import { StringUtil } from "../../utils/StringUtil";
|
|
@@ -24,17 +25,20 @@ export namespace SdkHttpCloneReferencer {
|
|
|
24
25
|
visitType({
|
|
25
26
|
unique,
|
|
26
27
|
metadata: p.metadata,
|
|
28
|
+
type: p.type,
|
|
27
29
|
name: (name) => (p.type = { name }),
|
|
28
30
|
});
|
|
29
31
|
for (const v of Object.values(props.route.exceptions))
|
|
30
32
|
visitType({
|
|
31
33
|
unique,
|
|
32
34
|
metadata: v.metadata,
|
|
35
|
+
type: v.type,
|
|
33
36
|
name: (name) => (v.type = { name }),
|
|
34
37
|
});
|
|
35
38
|
visitType({
|
|
36
39
|
unique,
|
|
37
40
|
metadata: props.route.success.metadata,
|
|
41
|
+
type: props.route.success.type,
|
|
38
42
|
name: (name) => (props.route.success.type = { name }),
|
|
39
43
|
});
|
|
40
44
|
props.route.imports = Array.from(unique).map((str) => ({
|
|
@@ -46,6 +50,7 @@ export namespace SdkHttpCloneReferencer {
|
|
|
46
50
|
const visitType = (p: {
|
|
47
51
|
unique: Set<string>;
|
|
48
52
|
metadata: Metadata;
|
|
53
|
+
type: IReflectType;
|
|
49
54
|
name: (key: string) => void;
|
|
50
55
|
}): void => {
|
|
51
56
|
const enroll = (key: string) => {
|
|
@@ -59,3 +64,8 @@ export namespace SdkHttpCloneReferencer {
|
|
|
59
64
|
p.name(p.metadata.getName());
|
|
60
65
|
};
|
|
61
66
|
}
|
|
67
|
+
|
|
68
|
+
const getFullText = (type: IReflectType): string =>
|
|
69
|
+
type.typeArguments === undefined
|
|
70
|
+
? type.name
|
|
71
|
+
: `${type.name}<${type.typeArguments.map(getFullText).join(", ")}>`;
|