@nestia/migrate 0.12.0 → 0.13.0-dev.20240411
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/MigrateApplication.d.ts +3 -4
- package/lib/MigrateApplication.js +5160 -947
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateControllerAnalyzer.js +2 -1
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateMethodAnalyzer.d.ts +2 -2
- package/lib/analyzers/MigrateMethodAnalyzer.js +60 -143
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/factories/TypeLiteralFactory.d.ts +4 -0
- package/lib/factories/TypeLiteralFactory.js +35 -0
- package/lib/factories/TypeLiteralFactory.js.map +1 -0
- package/lib/internal/MigrateCommander.js +2 -2
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/module.d.ts +0 -6
- package/lib/module.js +0 -6
- package/lib/module.js.map +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +3 -3
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiProgrammer.js +2 -2
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiSimulatationProgrammer.d.ts +3 -3
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiStartProgrammer.js +8 -8
- package/lib/programmers/MigrateApiStartProgrammer.js.map +1 -1
- package/lib/programmers/MigrateDtoProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateDtoProgrammer.js.map +1 -1
- package/lib/programmers/MigrateE2eFileProgrammer.d.ts +3 -3
- package/lib/programmers/MigrateE2eFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateE2eProgrammer.js +1 -1
- package/lib/programmers/MigrateE2eProgrammer.js.map +1 -1
- package/lib/programmers/MigrateImportProgrammer.d.ts +1 -1
- package/lib/programmers/MigrateImportProgrammer.js +2 -4
- package/lib/programmers/MigrateImportProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestControllerProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateNestControllerProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestMethodProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestProgrammer.js +2 -2
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.d.ts +2 -3
- package/lib/programmers/MigrateSchemaProgrammer.js +151 -28
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
- package/lib/structures/IMigrateDto.d.ts +2 -2
- package/lib/structures/IMigrateProgram.d.ts +3 -4
- package/lib/structures/IMigrateRoute.d.ts +6 -6
- package/lib/utils/OpenApiTypeChecker.d.ts +15 -0
- package/lib/utils/OpenApiTypeChecker.js +28 -0
- package/lib/utils/OpenApiTypeChecker.js.map +1 -0
- package/package.json +4 -3
- package/src/MigrateApplication.ts +81 -86
- package/src/analyzers/MigrateControllerAnalyzer.ts +7 -5
- package/src/analyzers/MigrateMethodAnalyzer.ts +103 -179
- package/src/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/factories/TypeLiteralFactory.ts +57 -0
- package/src/internal/MigrateCommander.ts +4 -4
- package/src/module.ts +0 -6
- package/src/programmers/MigrateApiFileProgrammer.ts +2 -2
- package/src/programmers/MigrateApiFunctionProgrammer.ts +3 -3
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +5 -5
- package/src/programmers/MigrateApiProgrammer.ts +4 -2
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +4 -4
- package/src/programmers/MigrateApiStartProgrammer.ts +8 -8
- package/src/programmers/MigrateDtoProgrammer.ts +5 -6
- package/src/programmers/MigrateE2eFileProgrammer.ts +4 -4
- package/src/programmers/MigrateE2eProgrammer.ts +3 -3
- package/src/programmers/MigrateImportProgrammer.ts +117 -121
- package/src/programmers/MigrateNestControllerProgrammer.ts +2 -2
- package/src/programmers/MigrateNestMethodProgrammer.ts +6 -7
- package/src/programmers/MigrateNestProgrammer.ts +2 -2
- package/src/programmers/MigrateSchemaProgrammer.ts +355 -263
- package/src/structures/IMigrateDto.ts +2 -2
- package/src/structures/IMigrateProgram.ts +4 -4
- package/src/structures/IMigrateRoute.ts +6 -6
- package/src/utils/OpenApiTypeChecker.ts +73 -0
- package/lib/structures/ISwagger.d.ts +0 -18
- package/lib/structures/ISwagger.js +0 -3
- package/lib/structures/ISwagger.js.map +0 -1
- package/lib/structures/ISwaggerComponents.d.ts +0 -12
- package/lib/structures/ISwaggerComponents.js +0 -3
- package/lib/structures/ISwaggerComponents.js.map +0 -1
- package/lib/structures/ISwaggerInfo.d.ts +0 -71
- package/lib/structures/ISwaggerInfo.js +0 -3
- package/lib/structures/ISwaggerInfo.js.map +0 -1
- package/lib/structures/ISwaggerRoute.d.ts +0 -15
- package/lib/structures/ISwaggerRoute.js +0 -3
- package/lib/structures/ISwaggerRoute.js.map +0 -1
- package/lib/structures/ISwaggerRouteBodyContent.d.ts +0 -14
- package/lib/structures/ISwaggerRouteBodyContent.js +0 -3
- package/lib/structures/ISwaggerRouteBodyContent.js.map +0 -1
- package/lib/structures/ISwaggerRouteHeader.d.ts +0 -0
- package/lib/structures/ISwaggerRouteHeader.js +0 -2
- package/lib/structures/ISwaggerRouteHeader.js.map +0 -1
- package/lib/structures/ISwaggerRouteParameter.d.ts +0 -13
- package/lib/structures/ISwaggerRouteParameter.js +0 -3
- package/lib/structures/ISwaggerRouteParameter.js.map +0 -1
- package/lib/structures/ISwaggerRouteRequestBody.d.ts +0 -11
- package/lib/structures/ISwaggerRouteRequestBody.js +0 -3
- package/lib/structures/ISwaggerRouteRequestBody.js.map +0 -1
- package/lib/structures/ISwaggerRouteResponse.d.ts +0 -10
- package/lib/structures/ISwaggerRouteResponse.js +0 -3
- package/lib/structures/ISwaggerRouteResponse.js.map +0 -1
- package/lib/structures/ISwaggerSchema.d.ts +0 -75
- package/lib/structures/ISwaggerSchema.js +0 -3
- package/lib/structures/ISwaggerSchema.js.map +0 -1
- package/lib/structures/ISwaggerSecurityScheme.d.ts +0 -40
- package/lib/structures/ISwaggerSecurityScheme.js +0 -3
- package/lib/structures/ISwaggerSecurityScheme.js.map +0 -1
- package/lib/structures/ISwaggerV20.d.ts +0 -8
- package/lib/structures/ISwaggerV20.js +0 -3
- package/lib/structures/ISwaggerV20.js.map +0 -1
- package/lib/structures/ISwaggerV31.d.ts +0 -9
- package/lib/structures/ISwaggerV31.js +0 -3
- package/lib/structures/ISwaggerV31.js.map +0 -1
- package/lib/utils/OpenApiConverter.d.ts +0 -5
- package/lib/utils/OpenApiConverter.js +0 -1568
- package/lib/utils/OpenApiConverter.js.map +0 -1
- package/lib/utils/SwaggerComponentsExplorer.d.ts +0 -9
- package/lib/utils/SwaggerComponentsExplorer.js +0 -29
- package/lib/utils/SwaggerComponentsExplorer.js.map +0 -1
- package/lib/utils/SwaggerTypeChecker.d.ts +0 -16
- package/lib/utils/SwaggerTypeChecker.js +0 -34
- package/lib/utils/SwaggerTypeChecker.js.map +0 -1
- package/src/structures/ISwagger.ts +0 -23
- package/src/structures/ISwaggerComponents.ts +0 -13
- package/src/structures/ISwaggerInfo.ts +0 -80
- package/src/structures/ISwaggerRoute.ts +0 -20
- package/src/structures/ISwaggerRouteBodyContent.ts +0 -15
- package/src/structures/ISwaggerRouteHeader.ts +0 -0
- package/src/structures/ISwaggerRouteParameter.ts +0 -14
- package/src/structures/ISwaggerRouteRequestBody.ts +0 -12
- package/src/structures/ISwaggerRouteResponse.ts +0 -11
- package/src/structures/ISwaggerSchema.ts +0 -90
- package/src/structures/ISwaggerSecurityScheme.ts +0 -47
- package/src/structures/ISwaggerV20.ts +0 -10
- package/src/structures/ISwaggerV31.ts +0 -10
- package/src/utils/OpenApiConverter.ts +0 -19
- package/src/utils/SwaggerComponentsExplorer.ts +0 -43
- package/src/utils/SwaggerTypeChecker.ts +0 -67
@@ -1,86 +1,81 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import {
|
12
|
-
import {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
}
|
77
|
-
export
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
export interface IConfig {
|
83
|
-
simulate: boolean;
|
84
|
-
e2e: boolean;
|
85
|
-
}
|
86
|
-
}
|
1
|
+
import { OpenApi, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
|
2
|
+
import typia, { IValidation } from "typia";
|
3
|
+
|
4
|
+
import { MigrateAnalyzer } from "./analyzers/MigrateAnalyzer";
|
5
|
+
import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
|
6
|
+
import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
|
7
|
+
import { MigrateApiProgrammer } from "./programmers/MigrateApiProgrammer";
|
8
|
+
import { MigrateApiStartProgrammer } from "./programmers/MigrateApiStartProgrammer";
|
9
|
+
import { MigrateE2eProgrammer } from "./programmers/MigrateE2eProgrammer";
|
10
|
+
import { MigrateNestProgrammer } from "./programmers/MigrateNestProgrammer";
|
11
|
+
import { IMigrateFile } from "./structures/IMigrateFile";
|
12
|
+
import { IMigrateProgram } from "./structures/IMigrateProgram";
|
13
|
+
|
14
|
+
export class MigrateApplication {
|
15
|
+
private constructor(public readonly document: OpenApi.IDocument) {}
|
16
|
+
|
17
|
+
public static async create(
|
18
|
+
document: SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument,
|
19
|
+
): Promise<IValidation<MigrateApplication>> {
|
20
|
+
const result = typia.validate(document);
|
21
|
+
if (result.success === false) return result;
|
22
|
+
return {
|
23
|
+
success: true,
|
24
|
+
data: new MigrateApplication(OpenApi.convert(document)),
|
25
|
+
errors: [],
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
public nest(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
|
30
|
+
const program: IMigrateProgram = MigrateAnalyzer.analyze({
|
31
|
+
mode: "nest",
|
32
|
+
document: this.document,
|
33
|
+
dictionary: new Map(),
|
34
|
+
simulate: config.simulate,
|
35
|
+
e2e: config.e2e,
|
36
|
+
});
|
37
|
+
return {
|
38
|
+
program,
|
39
|
+
files: [
|
40
|
+
...NEST_TEMPLATE,
|
41
|
+
...MigrateNestProgrammer.write(program),
|
42
|
+
...MigrateApiProgrammer.write(program),
|
43
|
+
...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
|
44
|
+
],
|
45
|
+
};
|
46
|
+
}
|
47
|
+
|
48
|
+
public sdk(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
|
49
|
+
const program: IMigrateProgram = MigrateAnalyzer.analyze({
|
50
|
+
mode: "sdk",
|
51
|
+
document: this.document,
|
52
|
+
dictionary: new Map(),
|
53
|
+
simulate: config.simulate,
|
54
|
+
e2e: config.e2e,
|
55
|
+
});
|
56
|
+
return {
|
57
|
+
program,
|
58
|
+
files: [
|
59
|
+
...SDK_TEMPLATE,
|
60
|
+
...MigrateApiProgrammer.write(program),
|
61
|
+
MigrateApiStartProgrammer.write(program),
|
62
|
+
...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
|
63
|
+
{
|
64
|
+
location: "",
|
65
|
+
file: "swagger.json",
|
66
|
+
content: JSON.stringify(this.document, null, 2),
|
67
|
+
},
|
68
|
+
],
|
69
|
+
};
|
70
|
+
}
|
71
|
+
}
|
72
|
+
export namespace MigrateApplication {
|
73
|
+
export interface IOutput {
|
74
|
+
program: IMigrateProgram;
|
75
|
+
files: IMigrateFile[];
|
76
|
+
}
|
77
|
+
export interface IConfig {
|
78
|
+
simulate: boolean;
|
79
|
+
e2e: boolean;
|
80
|
+
}
|
81
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
1
2
|
import { Escaper } from "typia/lib/utils/Escaper";
|
2
3
|
|
3
4
|
import { IMigrateController } from "../structures/IMigrateController";
|
4
5
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
5
6
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
6
|
-
import { ISwaggerRoute } from "../structures/ISwaggerRoute";
|
7
7
|
import { MapUtil } from "../utils/MapUtil";
|
8
8
|
import { StringUtil } from "../utils/StringUtil";
|
9
9
|
import { MigrateMethodAnalzyer } from "./MigrateMethodAnalyzer";
|
@@ -13,13 +13,15 @@ export namespace MigrateControllerAnalyzer {
|
|
13
13
|
props: IMigrateProgram.IProps,
|
14
14
|
): IMigrateController[] => {
|
15
15
|
interface IEntry {
|
16
|
-
endpoint:
|
16
|
+
endpoint: OpenApi.IOperation;
|
17
17
|
route: IMigrateRoute;
|
18
18
|
}
|
19
19
|
const endpoints: Map<string, IEntry[]> = new Map();
|
20
20
|
|
21
21
|
// GATHER ROUTES
|
22
|
-
for (const [path, collection] of Object.entries(
|
22
|
+
for (const [path, collection] of Object.entries(
|
23
|
+
props.document.paths ?? {},
|
24
|
+
)) {
|
23
25
|
if (collection === undefined) continue;
|
24
26
|
|
25
27
|
// PREPARE DIRECTORIES
|
@@ -39,10 +41,10 @@ export namespace MigrateControllerAnalyzer {
|
|
39
41
|
const r: IMigrateRoute | null = MigrateMethodAnalzyer.analyze(props)({
|
40
42
|
path,
|
41
43
|
method,
|
42
|
-
})(value);
|
44
|
+
})(value as OpenApi.IOperation);
|
43
45
|
if (r === null) continue;
|
44
46
|
routes.push({
|
45
|
-
endpoint: value,
|
47
|
+
endpoint: value as OpenApi.IOperation,
|
46
48
|
route: r,
|
47
49
|
});
|
48
50
|
}
|
@@ -1,71 +1,28 @@
|
|
1
|
-
import
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
2
|
import { Escaper } from "typia/lib/utils/Escaper";
|
3
3
|
|
4
4
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
5
5
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
6
|
-
import {
|
7
|
-
import { ISwaggerRoute } from "../structures/ISwaggerRoute";
|
8
|
-
import { ISwaggerRouteBodyContent } from "../structures/ISwaggerRouteBodyContent";
|
9
|
-
import { ISwaggerRouteParameter } from "../structures/ISwaggerRouteParameter";
|
10
|
-
import { ISwaggerRouteResponse } from "../structures/ISwaggerRouteResponse";
|
11
|
-
import { ISwaggerSchema } from "../structures/ISwaggerSchema";
|
6
|
+
import { OpenApiTypeChecker } from "../utils/OpenApiTypeChecker";
|
12
7
|
import { StringUtil } from "../utils/StringUtil";
|
13
|
-
import { SwaggerComponentsExplorer } from "../utils/SwaggerComponentsExplorer";
|
14
|
-
import { SwaggerTypeChecker } from "../utils/SwaggerTypeChecker";
|
15
8
|
|
16
9
|
export namespace MigrateMethodAnalzyer {
|
17
10
|
export const analyze =
|
18
11
|
(props: Omit<IMigrateProgram.IProps, "dictionary">) =>
|
19
12
|
(endpoint: { path: string; method: string }) =>
|
20
|
-
(route:
|
13
|
+
(route: OpenApi.IOperation): IMigrateRoute | null => {
|
21
14
|
const body = emplaceBodySchema("request")(
|
22
|
-
emplaceReference(props.
|
15
|
+
emplaceReference(props.document)("body"),
|
23
16
|
)(route.requestBody);
|
24
17
|
const success = emplaceBodySchema("response")(
|
25
|
-
emplaceReference(props.
|
18
|
+
emplaceReference(props.document)("response"),
|
26
19
|
)(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
route.responses?.["200"] ??
|
31
|
-
route.responses?.default;
|
32
|
-
if (response === undefined) return undefined;
|
33
|
-
return (
|
34
|
-
SwaggerComponentsExplorer.getResponse(props.swagger.components)(
|
35
|
-
response,
|
36
|
-
) ?? undefined
|
37
|
-
);
|
38
|
-
})(),
|
20
|
+
route.responses?.["201"] ??
|
21
|
+
route.responses?.["200"] ??
|
22
|
+
route.responses?.default,
|
39
23
|
);
|
40
24
|
|
41
25
|
const failures: string[] = [];
|
42
|
-
for (const p of route.parameters ?? [])
|
43
|
-
if (
|
44
|
-
SwaggerComponentsExplorer.getParameter(props.swagger.components)(
|
45
|
-
p,
|
46
|
-
) === null
|
47
|
-
)
|
48
|
-
failures.push(
|
49
|
-
`parameter "${(p as ISwaggerRouteParameter.IReference).$ref}" is not defined in "components.parameters".`,
|
50
|
-
);
|
51
|
-
for (const value of Object.values(route.responses ?? {}))
|
52
|
-
if (
|
53
|
-
SwaggerComponentsExplorer.getResponse(props.swagger.components)(
|
54
|
-
value,
|
55
|
-
) === null
|
56
|
-
)
|
57
|
-
failures.push(
|
58
|
-
`response "${(value as ISwaggerRouteResponse.IReference).$ref}" is not defined in "components.responses".`,
|
59
|
-
);
|
60
|
-
if (
|
61
|
-
route.requestBody &&
|
62
|
-
SwaggerComponentsExplorer.getRequestBody(props.swagger.components)(
|
63
|
-
route.requestBody,
|
64
|
-
) === null
|
65
|
-
)
|
66
|
-
failures.push(
|
67
|
-
`requestBody "${(route.requestBody as ISwaggerRouteParameter.IReference).$ref}" is not defined in "components.requestBodies".`,
|
68
|
-
);
|
69
26
|
if (body === false)
|
70
27
|
failures.push(
|
71
28
|
`supports only "application/json", "application/x-www-form-urlencoded", "multipart/form-data" and "text/plain" content type in the request body.`,
|
@@ -80,28 +37,18 @@ export namespace MigrateMethodAnalzyer {
|
|
80
37
|
);
|
81
38
|
|
82
39
|
const [headers, query] = ["header", "query"].map((type) => {
|
83
|
-
const parameters:
|
84
|
-
.
|
85
|
-
|
86
|
-
SwaggerComponentsExplorer.getParameter(props.swagger.components)(
|
87
|
-
p,
|
88
|
-
)?.in === type,
|
89
|
-
)
|
90
|
-
.map(
|
91
|
-
(p) =>
|
92
|
-
SwaggerComponentsExplorer.getParameter(props.swagger.components)(
|
93
|
-
p,
|
94
|
-
)!,
|
95
|
-
);
|
40
|
+
const parameters: OpenApi.IOperation.IParameter[] = (
|
41
|
+
route.parameters ?? []
|
42
|
+
).filter((p) => p.in === type);
|
96
43
|
if (parameters.length === 0) return null;
|
97
44
|
|
98
45
|
const objects = parameters
|
99
46
|
.map((p) =>
|
100
|
-
|
47
|
+
OpenApiTypeChecker.isObject(p.schema)
|
101
48
|
? p.schema
|
102
|
-
:
|
103
|
-
|
104
|
-
|
49
|
+
: OpenApiTypeChecker.isReference(p.schema) &&
|
50
|
+
OpenApiTypeChecker.isObject(
|
51
|
+
props.document.components.schemas[
|
105
52
|
p.schema.$ref.replace(`#/components/schemas/`, ``)
|
106
53
|
] ?? {},
|
107
54
|
)
|
@@ -111,11 +58,11 @@ export namespace MigrateMethodAnalzyer {
|
|
111
58
|
.filter((s) => !!s);
|
112
59
|
const primitives = parameters.filter(
|
113
60
|
(p) =>
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
61
|
+
OpenApiTypeChecker.isBoolean(p.schema) ||
|
62
|
+
OpenApiTypeChecker.isInteger(p.schema) ||
|
63
|
+
OpenApiTypeChecker.isNumber(p.schema) ||
|
64
|
+
OpenApiTypeChecker.isString(p.schema) ||
|
65
|
+
OpenApiTypeChecker.isArray(p.schema),
|
119
66
|
);
|
120
67
|
if (objects.length === 1 && primitives.length === 0) return objects[0];
|
121
68
|
else if (objects.length > 1) {
|
@@ -125,23 +72,23 @@ export namespace MigrateMethodAnalzyer {
|
|
125
72
|
return false;
|
126
73
|
}
|
127
74
|
|
128
|
-
const dto:
|
129
|
-
?
|
75
|
+
const dto: OpenApi.IJsonSchema.IObject | null = objects[0]
|
76
|
+
? OpenApiTypeChecker.isObject(objects[0])
|
130
77
|
? objects[0]
|
131
|
-
: ((props.
|
132
|
-
(objects[0] as
|
78
|
+
: ((props.document.components.schemas ?? {})[
|
79
|
+
(objects[0] as OpenApi.IJsonSchema.IReference).$ref.replace(
|
133
80
|
`#/components/schemas/`,
|
134
81
|
``,
|
135
82
|
)
|
136
|
-
] as
|
83
|
+
] as OpenApi.IJsonSchema.IObject)
|
137
84
|
: null;
|
138
|
-
const entire:
|
85
|
+
const entire: OpenApi.IJsonSchema.IObject[] = [
|
139
86
|
...objects.map((o) =>
|
140
|
-
|
87
|
+
OpenApiTypeChecker.isObject(o)
|
141
88
|
? o
|
142
|
-
: (props.
|
89
|
+
: (props.document.components.schemas?.[
|
143
90
|
o.$ref.replace(`#/components/schemas/`, ``)
|
144
|
-
]! as
|
91
|
+
]! as OpenApi.IJsonSchema.IObject),
|
145
92
|
),
|
146
93
|
{
|
147
94
|
type: "object",
|
@@ -163,14 +110,14 @@ export namespace MigrateMethodAnalzyer {
|
|
163
110
|
];
|
164
111
|
return parameters.length === 0
|
165
112
|
? null
|
166
|
-
: emplaceReference(props.
|
113
|
+
: emplaceReference(props.document)(
|
167
114
|
StringUtil.pascal(`I/Api/${endpoint.path}`) +
|
168
115
|
"." +
|
169
116
|
StringUtil.pascal(`${endpoint.method}/${type}`),
|
170
117
|
)({
|
171
118
|
type: "object",
|
172
119
|
properties: Object.fromEntries([
|
173
|
-
...new Map<string,
|
120
|
+
...new Map<string, OpenApi.IJsonSchema>(
|
174
121
|
entire
|
175
122
|
.map((o) =>
|
176
123
|
Object.entries(o.properties ?? {}).map(
|
@@ -181,7 +128,7 @@ export namespace MigrateMethodAnalzyer {
|
|
181
128
|
...schema,
|
182
129
|
description:
|
183
130
|
schema.description ?? schema.description,
|
184
|
-
} as
|
131
|
+
} as OpenApi.IJsonSchema,
|
185
132
|
] as const,
|
186
133
|
),
|
187
134
|
)
|
@@ -203,11 +150,7 @@ export namespace MigrateMethodAnalzyer {
|
|
203
150
|
);
|
204
151
|
if (
|
205
152
|
parameterNames.length !==
|
206
|
-
|
207
|
-
(p) =>
|
208
|
-
SwaggerComponentsExplorer.getParameter(props.swagger.components)(p)
|
209
|
-
?.in === "path",
|
210
|
-
).length
|
153
|
+
route.parameters.filter((p) => p.in === "path").length
|
211
154
|
)
|
212
155
|
failures.push(
|
213
156
|
"number of path parameters are not matched with its full path.",
|
@@ -233,11 +176,8 @@ export namespace MigrateMethodAnalzyer {
|
|
233
176
|
schema: headers,
|
234
177
|
}
|
235
178
|
: null,
|
236
|
-
parameters:
|
237
|
-
.
|
238
|
-
SwaggerComponentsExplorer.getParameter(props.swagger.components)(p),
|
239
|
-
)
|
240
|
-
.filter((p) => p !== null && p.in === "path")
|
179
|
+
parameters: route.parameters
|
180
|
+
.filter((p) => p.in === "path")
|
241
181
|
.map((p, i) => ({
|
242
182
|
name: parameterNames[i],
|
243
183
|
key: (() => {
|
@@ -265,105 +205,77 @@ export namespace MigrateMethodAnalzyer {
|
|
265
205
|
exceptions: Object.fromEntries(
|
266
206
|
Object.entries(route.responses ?? {})
|
267
207
|
.filter(
|
268
|
-
([key
|
269
|
-
key !== "200" &&
|
270
|
-
key !== "201" &&
|
271
|
-
key !== "default" &&
|
272
|
-
!!SwaggerComponentsExplorer.getResponse(
|
273
|
-
props.swagger.components,
|
274
|
-
)(value)?.content?.["application/json"],
|
208
|
+
([key]) => key !== "200" && key !== "201" && key !== "default",
|
275
209
|
)
|
276
|
-
.map(([key, value]) =>
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
description: r.description,
|
284
|
-
schema: r.content?.["application/json"]?.schema ?? {},
|
285
|
-
},
|
286
|
-
];
|
287
|
-
}),
|
210
|
+
.map(([key, value]) => [
|
211
|
+
key,
|
212
|
+
{
|
213
|
+
description: value.description,
|
214
|
+
schema: value.content?.["application/json"]?.schema ?? {},
|
215
|
+
},
|
216
|
+
]),
|
288
217
|
),
|
289
218
|
deprecated: route.deprecated ?? false,
|
290
|
-
comment: () => describe(
|
219
|
+
comment: () => describe(route),
|
291
220
|
tags: route.tags ?? [],
|
292
221
|
};
|
293
222
|
};
|
294
223
|
|
295
|
-
const describe =
|
296
|
-
|
297
|
-
(
|
298
|
-
|
299
|
-
const add = (text: string) => {
|
300
|
-
if (commentTags.every((line) => line !== text)) commentTags.push(text);
|
301
|
-
};
|
302
|
-
|
303
|
-
let description: string = route.description ?? "";
|
304
|
-
if (route.summary) {
|
305
|
-
const emended: string = route.summary.endsWith(".")
|
306
|
-
? route.summary
|
307
|
-
: route.summary + ".";
|
308
|
-
if (
|
309
|
-
!!description.length &&
|
310
|
-
!description.startsWith(route.summary) &&
|
311
|
-
!route["x-nestia-jsDocTags"]?.some((t) => t.name === "summary")
|
312
|
-
)
|
313
|
-
description = `${emended}\n${description}`;
|
314
|
-
}
|
315
|
-
for (const p of route.parameters ?? []) {
|
316
|
-
const param: ISwaggerRouteParameter | null = (() => {
|
317
|
-
if (!typia.is<ISwaggerRouteParameter.IReference>(p))
|
318
|
-
return typia.is<ISwaggerRouteParameter>(p) ? p : null;
|
319
|
-
return (
|
320
|
-
swagger.components.parameters?.[
|
321
|
-
p.$ref.replace(`#/components/parameters/`, ``)
|
322
|
-
] ?? null
|
323
|
-
);
|
324
|
-
})();
|
325
|
-
if (param !== null && param.description)
|
326
|
-
add(`@param ${param.name} ${param.description}`);
|
327
|
-
}
|
328
|
-
if (route.requestBody?.description)
|
329
|
-
add(`@param body ${route.requestBody.description}`);
|
330
|
-
for (const security of route.security ?? [])
|
331
|
-
for (const [name, scopes] of Object.entries(security))
|
332
|
-
add(`@security ${[name, ...scopes].join("")}`);
|
333
|
-
if (route.tags) route.tags.forEach((name) => add(`@tag ${name}`));
|
334
|
-
if (route.deprecated) add("@deprecated");
|
335
|
-
return description.length
|
336
|
-
? commentTags.length
|
337
|
-
? `${description}\n\n${commentTags.join("\n")}`
|
338
|
-
: description
|
339
|
-
: commentTags.join("\n");
|
224
|
+
const describe = (route: OpenApi.IOperation): string => {
|
225
|
+
const commentTags: string[] = [];
|
226
|
+
const add = (text: string) => {
|
227
|
+
if (commentTags.every((line) => line !== text)) commentTags.push(text);
|
340
228
|
};
|
341
229
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
(
|
230
|
+
let description: string = route.description ?? "";
|
231
|
+
if (route.summary) {
|
232
|
+
const emended: string = route.summary.endsWith(".")
|
233
|
+
? route.summary
|
234
|
+
: route.summary + ".";
|
235
|
+
if (!!description.length && !description.startsWith(route.summary))
|
236
|
+
description = `${emended}\n${description}`;
|
237
|
+
}
|
238
|
+
for (const p of route.parameters)
|
239
|
+
if (p.description) add(`@param ${p.name} ${p.description}`);
|
240
|
+
if (route.requestBody?.description)
|
241
|
+
add(`@param body ${route.requestBody.description}`);
|
242
|
+
for (const security of route.security ?? [])
|
243
|
+
for (const [name, scopes] of Object.entries(security))
|
244
|
+
add(`@security ${[name, ...scopes].join("")}`);
|
245
|
+
if (route.tags) route.tags.forEach((name) => add(`@tag ${name}`));
|
246
|
+
if (route.deprecated) add("@deprecated");
|
247
|
+
return description.length
|
248
|
+
? commentTags.length
|
249
|
+
? `${description}\n\n${commentTags.join("\n")}`
|
250
|
+
: description
|
251
|
+
: commentTags.join("\n");
|
252
|
+
};
|
253
|
+
|
254
|
+
const isNotObjectLiteral = (schema: OpenApi.IJsonSchema): boolean =>
|
255
|
+
OpenApiTypeChecker.isReference(schema) ||
|
256
|
+
OpenApiTypeChecker.isBoolean(schema) ||
|
257
|
+
OpenApiTypeChecker.isNumber(schema) ||
|
258
|
+
OpenApiTypeChecker.isString(schema) ||
|
259
|
+
OpenApiTypeChecker.isUnknown(schema) ||
|
260
|
+
(OpenApiTypeChecker.isOneOf(schema) &&
|
351
261
|
schema.oneOf.every(isNotObjectLiteral)) ||
|
352
|
-
(
|
262
|
+
(OpenApiTypeChecker.isArray(schema) && isNotObjectLiteral(schema.items));
|
353
263
|
|
354
264
|
const emplaceBodySchema =
|
355
265
|
(from: "request" | "response") =>
|
356
|
-
(
|
266
|
+
(
|
267
|
+
emplacer: (schema: OpenApi.IJsonSchema) => OpenApi.IJsonSchema.IReference,
|
268
|
+
) =>
|
357
269
|
(meta?: {
|
358
270
|
description?: string;
|
359
|
-
content?: ISwaggerRouteBodyContent;
|
271
|
+
content?: Record<string, OpenApi.IOperation.IMediaType>; // ISwaggerRouteBodyContent;
|
360
272
|
"x-nestia-encrypted"?: boolean;
|
361
273
|
}): false | null | IMigrateRoute.IBody => {
|
362
274
|
if (!meta?.content) return null;
|
363
275
|
|
364
|
-
const entries: [string,
|
276
|
+
const entries: [string, OpenApi.IOperation.IMediaType][] = Object.entries(
|
365
277
|
meta.content,
|
366
|
-
);
|
278
|
+
).filter(([_, v]) => !!v);
|
367
279
|
const json = entries.find((e) =>
|
368
280
|
meta["x-nestia-encrypted"] === true
|
369
281
|
? e[0].includes("text/plain") || e[0].includes("application/json")
|
@@ -375,7 +287,11 @@ export namespace MigrateMethodAnalzyer {
|
|
375
287
|
type: "application/json",
|
376
288
|
name: "body",
|
377
289
|
key: "body",
|
378
|
-
schema:
|
290
|
+
schema: schema
|
291
|
+
? isNotObjectLiteral(schema)
|
292
|
+
? schema
|
293
|
+
: emplacer(schema)
|
294
|
+
: {},
|
379
295
|
"x-nestia-encrypted": meta["x-nestia-encrypted"],
|
380
296
|
};
|
381
297
|
}
|
@@ -389,7 +305,11 @@ export namespace MigrateMethodAnalzyer {
|
|
389
305
|
type: "application/x-www-form-urlencoded",
|
390
306
|
name: "body",
|
391
307
|
key: "body",
|
392
|
-
schema:
|
308
|
+
schema: schema
|
309
|
+
? isNotObjectLiteral(schema)
|
310
|
+
? schema
|
311
|
+
: emplacer(schema)
|
312
|
+
: {},
|
393
313
|
};
|
394
314
|
}
|
395
315
|
|
@@ -412,7 +332,11 @@ export namespace MigrateMethodAnalzyer {
|
|
412
332
|
type: "multipart/form-data",
|
413
333
|
name: "body",
|
414
334
|
key: "body",
|
415
|
-
schema:
|
335
|
+
schema: schema
|
336
|
+
? isNotObjectLiteral(schema)
|
337
|
+
? schema
|
338
|
+
: emplacer(schema)
|
339
|
+
: {},
|
416
340
|
};
|
417
341
|
}
|
418
342
|
}
|
@@ -420,9 +344,9 @@ export namespace MigrateMethodAnalzyer {
|
|
420
344
|
};
|
421
345
|
|
422
346
|
const emplaceReference =
|
423
|
-
(swagger:
|
347
|
+
(swagger: OpenApi.IDocument) =>
|
424
348
|
(name: string) =>
|
425
|
-
(schema:
|
349
|
+
(schema: OpenApi.IJsonSchema): OpenApi.IJsonSchema.IReference => {
|
426
350
|
swagger.components.schemas ??= {};
|
427
351
|
swagger.components.schemas[name] = schema;
|
428
352
|
return { $ref: `#/components/schemas/${name}` };
|