@nestia/sdk 3.0.5 → 3.1.0-dev.20240429
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.d.ts +1 -0
- package/lib/NestiaSdkApplication.js +17 -17
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/AccessorAnalyzer.d.ts +3 -2
- package/lib/analyses/AccessorAnalyzer.js.map +1 -1
- package/lib/analyses/ExceptionAnalyzer.d.ts +11 -3
- package/lib/analyses/ExceptionAnalyzer.js +23 -18
- package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
- package/lib/analyses/GenericAnalyzer.d.ts +1 -0
- package/lib/analyses/ImportAnalyzer.d.ts +6 -1
- package/lib/analyses/ImportAnalyzer.js +27 -29
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/PathAnalyzer.d.ts +0 -5
- package/lib/analyses/PathAnalyzer.js +0 -32
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/{ReflectAnalyzer.d.ts → ReflectControllerAnalyzer.d.ts} +3 -4
- package/lib/analyses/ReflectControllerAnalyzer.js +145 -0
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +10 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +224 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectMetadataAnalyzer.d.ts +8 -0
- package/lib/analyses/ReflectMetadataAnalyzer.js +34 -0
- package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +10 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +78 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -0
- package/lib/analyses/SecurityAnalyzer.js +1 -1
- package/lib/analyses/SecurityAnalyzer.js.map +1 -1
- package/lib/analyses/TypedControllerAnalyzer.d.ts +9 -0
- package/lib/analyses/TypedControllerAnalyzer.js +77 -0
- package/lib/analyses/TypedControllerAnalyzer.js.map +1 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.d.ts +16 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.js +251 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.js.map +1 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.d.ts +16 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js +218 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +1 -0
- package/lib/executable/internal/NestiaConfigLoader.d.ts +1 -0
- package/lib/generates/CloneGenerator.d.ts +3 -4
- package/lib/generates/CloneGenerator.js +8 -8
- package/lib/generates/CloneGenerator.js.map +1 -1
- package/lib/generates/E2eGenerator.d.ts +3 -4
- package/lib/generates/E2eGenerator.js +7 -7
- package/lib/generates/E2eGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.d.ts +4 -4
- package/lib/generates/SdkGenerator.js +8 -8
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +5 -2
- package/lib/generates/SwaggerGenerator.js +15 -13
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +4 -5
- package/lib/generates/internal/E2eFileProgrammer.js +13 -12
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/FilePrinter.d.ts +1 -0
- package/lib/generates/internal/ImportDictionary.d.ts +1 -0
- package/lib/generates/internal/SdkAliasCollection.d.ts +9 -8
- package/lib/generates/internal/SdkAliasCollection.js +20 -20
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.d.ts +1 -1
- package/lib/generates/internal/SdkDistributionComposer.js +36 -2
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.d.ts +4 -4
- package/lib/generates/internal/SdkFileProgrammer.js +10 -7
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +13 -0
- package/lib/generates/internal/{SdkCloneProgrammer.js → SdkHttpCloneProgrammer.js} +14 -14
- package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +12 -0
- package/lib/generates/internal/{SdkFunctionProgrammer.js → SdkHttpFunctionProgrammer.js} +12 -12
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +12 -0
- package/lib/generates/internal/{SdkNamespaceProgrammer.js → SdkHttpNamespaceProgrammer.js} +26 -26
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpRouteProgrammer.d.ts +8 -0
- package/lib/generates/internal/{SdkRouteProgrammer.js → SdkHttpRouteProgrammer.js} +11 -11
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +13 -0
- package/lib/generates/internal/{SdkSimulationProgrammer.js → SdkHttpSimulationProgrammer.js} +18 -18
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteDirectory.d.ts +3 -2
- package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
- package/lib/generates/internal/SdkTypeProgrammer.d.ts +4 -3
- package/lib/generates/internal/SdkTypeProgrammer.js +33 -33
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +8 -0
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +115 -0
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +8 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +79 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +6 -5
- package/lib/generates/internal/SwaggerSchemaGenerator.js +3 -1
- package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
- package/lib/structures/INestiaProject.d.ts +1 -0
- package/lib/structures/IReflectController.d.ts +15 -0
- package/lib/structures/{IRoute.js → IReflectController.js} +1 -1
- package/lib/structures/IReflectController.js.map +1 -0
- package/lib/structures/{IController.d.ts → IReflectHttpOperation.d.ts} +15 -25
- package/lib/structures/IReflectHttpOperation.js +3 -0
- package/lib/structures/IReflectHttpOperation.js.map +1 -0
- package/lib/structures/IReflectWebSocketOperation.d.ts +16 -0
- package/lib/structures/IReflectWebSocketOperation.js +3 -0
- package/lib/structures/IReflectWebSocketOperation.js.map +1 -0
- package/lib/structures/ISwaggerError.d.ts +2 -2
- package/lib/structures/ITypeTuple.d.ts +1 -0
- package/lib/structures/{IRoute.d.ts → ITypedHttpRoute.d.ts} +12 -12
- package/lib/structures/{IController.js → ITypedHttpRoute.js} +1 -1
- package/lib/structures/ITypedHttpRoute.js.map +1 -0
- package/lib/structures/ITypedWebSocketRoute.d.ts +54 -0
- package/lib/structures/ITypedWebSocketRoute.js +3 -0
- package/lib/structures/ITypedWebSocketRoute.js.map +1 -0
- package/lib/structures/TypeEntry.d.ts +1 -0
- package/lib/utils/VersioningStrategy.d.ts +6 -0
- package/lib/utils/VersioningStrategy.js +22 -0
- package/lib/utils/VersioningStrategy.js.map +1 -0
- package/package.json +9 -7
- package/src/NestiaSdkApplication.ts +36 -34
- package/src/analyses/AccessorAnalyzer.ts +12 -5
- package/src/analyses/ExceptionAnalyzer.ts +49 -39
- package/src/analyses/ImportAnalyzer.ts +123 -104
- package/src/analyses/PathAnalyzer.ts +0 -41
- package/src/analyses/ReflectControllerAnalyzer.ts +155 -0
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +290 -0
- package/src/analyses/ReflectMetadataAnalyzer.ts +53 -0
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +96 -0
- package/src/analyses/SecurityAnalyzer.ts +2 -1
- package/src/analyses/TypedControllerAnalyzer.ts +92 -0
- package/src/analyses/TypedHttpOperationAnalyzer.ts +352 -0
- package/src/analyses/TypedWebSocketOperationAnalyzer.ts +368 -0
- package/src/generates/CloneGenerator.ts +17 -15
- package/src/generates/E2eGenerator.ts +10 -12
- package/src/generates/SdkGenerator.ts +19 -12
- package/src/generates/SwaggerGenerator.ts +32 -22
- package/src/generates/internal/E2eFileProgrammer.ts +20 -24
- package/src/generates/internal/SdkAliasCollection.ts +38 -33
- package/src/generates/internal/SdkDistributionComposer.ts +13 -4
- package/src/generates/internal/SdkFileProgrammer.ts +17 -13
- package/src/generates/internal/{SdkCloneProgrammer.ts → SdkHttpCloneProgrammer.ts} +14 -15
- package/src/generates/internal/{SdkFunctionProgrammer.ts → SdkHttpFunctionProgrammer.ts} +24 -23
- package/src/generates/internal/{SdkNamespaceProgrammer.ts → SdkHttpNamespaceProgrammer.ts} +44 -49
- package/src/generates/internal/{SdkRouteProgrammer.ts → SdkHttpRouteProgrammer.ts} +12 -13
- package/src/generates/internal/{SdkSimulationProgrammer.ts → SdkHttpSimulationProgrammer.ts} +23 -25
- package/src/generates/internal/SdkRouteDirectory.ts +3 -2
- package/src/generates/internal/SdkTypeProgrammer.ts +43 -37
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +378 -0
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +248 -0
- package/src/generates/internal/SwaggerSchemaGenerator.ts +26 -21
- package/src/structures/IReflectController.ts +17 -0
- package/src/structures/{IController.ts → IReflectHttpOperation.ts} +78 -94
- package/src/structures/IReflectWebSocketOperation.ts +17 -0
- package/src/structures/ISwaggerError.ts +2 -2
- package/src/structures/{IRoute.ts → ITypedHttpRoute.ts} +14 -12
- package/src/structures/ITypedWebSocketRoute.ts +67 -0
- package/src/utils/VersioningStrategy.ts +28 -0
- package/lib/analyses/ControllerAnalyzer.d.ts +0 -7
- package/lib/analyses/ControllerAnalyzer.js +0 -269
- package/lib/analyses/ControllerAnalyzer.js.map +0 -1
- package/lib/analyses/ReflectAnalyzer.js +0 -377
- package/lib/analyses/ReflectAnalyzer.js.map +0 -1
- package/lib/generates/internal/SdkCloneProgrammer.d.ts +0 -12
- package/lib/generates/internal/SdkCloneProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +0 -11
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +0 -11
- package/lib/generates/internal/SdkNamespaceProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkRouteProgrammer.d.ts +0 -7
- package/lib/generates/internal/SdkRouteProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +0 -12
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +0 -1
- package/lib/structures/IController.js.map +0 -1
- package/lib/structures/IRoute.js.map +0 -1
- package/src/analyses/ControllerAnalyzer.ts +0 -402
- package/src/analyses/ReflectAnalyzer.ts +0 -471
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
3
|
+
|
|
4
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
5
|
+
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
6
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
7
|
+
import { SdkImportWizard } from "./SdkImportWizard";
|
|
8
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
9
|
+
import { SdkWebSocketNamespaceProgrammer } from "./SdkWebSocketNamespaceProgrammer";
|
|
10
|
+
|
|
11
|
+
export namespace SdkWebSocketRouteProgrammer {
|
|
12
|
+
export const write =
|
|
13
|
+
(project: INestiaProject) =>
|
|
14
|
+
(importer: ImportDictionary) =>
|
|
15
|
+
(route: ITypedWebSocketRoute): ts.Statement[] => [
|
|
16
|
+
writeFunction(project)(importer)(route),
|
|
17
|
+
SdkWebSocketNamespaceProgrammer.write(project)(importer)(route),
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const writeFunction =
|
|
21
|
+
(project: INestiaProject) =>
|
|
22
|
+
(importer: ImportDictionary) =>
|
|
23
|
+
(route: ITypedWebSocketRoute): ts.FunctionDeclaration =>
|
|
24
|
+
ts.factory.createFunctionDeclaration(
|
|
25
|
+
[
|
|
26
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
27
|
+
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
|
28
|
+
],
|
|
29
|
+
undefined,
|
|
30
|
+
route.name,
|
|
31
|
+
undefined,
|
|
32
|
+
[
|
|
33
|
+
IdentifierFactory.parameter(
|
|
34
|
+
"connection",
|
|
35
|
+
ts.factory.createTypeReferenceNode(
|
|
36
|
+
SdkImportWizard.IConnection(importer),
|
|
37
|
+
[ts.factory.createTypeReferenceNode(`${route.name}.Header`)],
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
...route.parameters
|
|
41
|
+
.filter((p) => p.category === "param" || p.category === "query")
|
|
42
|
+
.map((p) =>
|
|
43
|
+
IdentifierFactory.parameter(
|
|
44
|
+
p.name,
|
|
45
|
+
p.category === "param"
|
|
46
|
+
? getPathParameterType(project)(importer)(p)
|
|
47
|
+
: ts.factory.createTypeReferenceNode(`${route.name}.Query`),
|
|
48
|
+
),
|
|
49
|
+
),
|
|
50
|
+
IdentifierFactory.parameter(
|
|
51
|
+
"provider",
|
|
52
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Provider`),
|
|
53
|
+
),
|
|
54
|
+
],
|
|
55
|
+
ts.factory.createTypeReferenceNode("Promise", [
|
|
56
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Output`),
|
|
57
|
+
]),
|
|
58
|
+
ts.factory.createBlock(writeFunctionBody(importer)(route), true),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const writeFunctionBody =
|
|
62
|
+
(importer: ImportDictionary) =>
|
|
63
|
+
(route: ITypedWebSocketRoute): ts.Statement[] => [
|
|
64
|
+
local("connector")(
|
|
65
|
+
ts.factory.createTypeReferenceNode(
|
|
66
|
+
importer.external({
|
|
67
|
+
type: false,
|
|
68
|
+
library: "tgrid",
|
|
69
|
+
instance: "WebConnector",
|
|
70
|
+
}),
|
|
71
|
+
[
|
|
72
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Header`),
|
|
73
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Provider`),
|
|
74
|
+
ts.factory.createTypeReferenceNode(`${route.name}.Listener`),
|
|
75
|
+
],
|
|
76
|
+
),
|
|
77
|
+
)(
|
|
78
|
+
ts.factory.createNewExpression(
|
|
79
|
+
ts.factory.createIdentifier(
|
|
80
|
+
importer.external({
|
|
81
|
+
type: false,
|
|
82
|
+
library: "tgrid",
|
|
83
|
+
instance: "WebConnector",
|
|
84
|
+
}),
|
|
85
|
+
),
|
|
86
|
+
undefined,
|
|
87
|
+
[
|
|
88
|
+
ts.factory.createAsExpression(
|
|
89
|
+
ts.factory.createBinaryExpression(
|
|
90
|
+
ts.factory.createPropertyAccessExpression(
|
|
91
|
+
ts.factory.createIdentifier("connection"),
|
|
92
|
+
"headers",
|
|
93
|
+
),
|
|
94
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
|
95
|
+
ts.factory.createObjectLiteralExpression([], false),
|
|
96
|
+
),
|
|
97
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
|
|
98
|
+
),
|
|
99
|
+
ts.factory.createIdentifier("provider"),
|
|
100
|
+
],
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
ts.factory.createExpressionStatement(
|
|
104
|
+
ts.factory.createAwaitExpression(
|
|
105
|
+
ts.factory.createCallExpression(
|
|
106
|
+
ts.factory.createPropertyAccessExpression(
|
|
107
|
+
ts.factory.createIdentifier("connector"),
|
|
108
|
+
"connect",
|
|
109
|
+
),
|
|
110
|
+
undefined,
|
|
111
|
+
[
|
|
112
|
+
joinPath(
|
|
113
|
+
ts.factory.createCallExpression(
|
|
114
|
+
ts.factory.createPropertyAccessExpression(
|
|
115
|
+
ts.factory.createIdentifier(route.name),
|
|
116
|
+
"path",
|
|
117
|
+
),
|
|
118
|
+
[],
|
|
119
|
+
route.parameters
|
|
120
|
+
.filter(
|
|
121
|
+
(p) => p.category === "param" || p.category === "query",
|
|
122
|
+
)
|
|
123
|
+
.map((x) => ts.factory.createIdentifier(x.name)),
|
|
124
|
+
),
|
|
125
|
+
),
|
|
126
|
+
],
|
|
127
|
+
),
|
|
128
|
+
),
|
|
129
|
+
),
|
|
130
|
+
local("driver")(
|
|
131
|
+
ts.factory.createTypeReferenceNode(
|
|
132
|
+
ts.factory.createIdentifier(
|
|
133
|
+
importer.external({
|
|
134
|
+
type: true,
|
|
135
|
+
library: "tgrid",
|
|
136
|
+
instance: "Driver",
|
|
137
|
+
}),
|
|
138
|
+
),
|
|
139
|
+
[ts.factory.createTypeReferenceNode(`${route.name}.Listener`)],
|
|
140
|
+
),
|
|
141
|
+
)(
|
|
142
|
+
ts.factory.createCallExpression(
|
|
143
|
+
ts.factory.createPropertyAccessExpression(
|
|
144
|
+
ts.factory.createIdentifier("connector"),
|
|
145
|
+
"getDriver",
|
|
146
|
+
),
|
|
147
|
+
undefined,
|
|
148
|
+
undefined,
|
|
149
|
+
),
|
|
150
|
+
),
|
|
151
|
+
ts.factory.createReturnStatement(
|
|
152
|
+
ts.factory.createObjectLiteralExpression(
|
|
153
|
+
[
|
|
154
|
+
ts.factory.createShorthandPropertyAssignment("connector"),
|
|
155
|
+
ts.factory.createShorthandPropertyAssignment("driver"),
|
|
156
|
+
],
|
|
157
|
+
true,
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const local =
|
|
164
|
+
(name: string) => (type: ts.TypeNode) => (expression: ts.Expression) =>
|
|
165
|
+
ts.factory.createVariableStatement(
|
|
166
|
+
[],
|
|
167
|
+
ts.factory.createVariableDeclarationList(
|
|
168
|
+
[
|
|
169
|
+
ts.factory.createVariableDeclaration(
|
|
170
|
+
name,
|
|
171
|
+
undefined,
|
|
172
|
+
type,
|
|
173
|
+
expression,
|
|
174
|
+
),
|
|
175
|
+
],
|
|
176
|
+
ts.NodeFlags.Const,
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const joinPath = (caller: ts.Expression) =>
|
|
181
|
+
ts.factory.createCallExpression(
|
|
182
|
+
ts.factory.createPropertyAccessExpression(
|
|
183
|
+
ts.factory.createCallExpression(
|
|
184
|
+
ts.factory.createPropertyAccessExpression(
|
|
185
|
+
ts.factory.createCallExpression(
|
|
186
|
+
ts.factory.createPropertyAccessExpression(
|
|
187
|
+
ts.factory.createTemplateExpression(
|
|
188
|
+
ts.factory.createTemplateHead("", ""),
|
|
189
|
+
[
|
|
190
|
+
ts.factory.createTemplateSpan(
|
|
191
|
+
ts.factory.createPropertyAccessExpression(
|
|
192
|
+
ts.factory.createIdentifier("connection"),
|
|
193
|
+
ts.factory.createIdentifier("host"),
|
|
194
|
+
),
|
|
195
|
+
ts.factory.createTemplateMiddle("/", "/"),
|
|
196
|
+
),
|
|
197
|
+
ts.factory.createTemplateSpan(
|
|
198
|
+
caller,
|
|
199
|
+
ts.factory.createTemplateTail("", ""),
|
|
200
|
+
),
|
|
201
|
+
],
|
|
202
|
+
),
|
|
203
|
+
ts.factory.createIdentifier("split"),
|
|
204
|
+
),
|
|
205
|
+
undefined,
|
|
206
|
+
[ts.factory.createStringLiteral("/")],
|
|
207
|
+
),
|
|
208
|
+
ts.factory.createIdentifier("filter"),
|
|
209
|
+
),
|
|
210
|
+
undefined,
|
|
211
|
+
[
|
|
212
|
+
ts.factory.createArrowFunction(
|
|
213
|
+
undefined,
|
|
214
|
+
undefined,
|
|
215
|
+
[
|
|
216
|
+
ts.factory.createParameterDeclaration(
|
|
217
|
+
undefined,
|
|
218
|
+
undefined,
|
|
219
|
+
ts.factory.createIdentifier("str"),
|
|
220
|
+
undefined,
|
|
221
|
+
undefined,
|
|
222
|
+
undefined,
|
|
223
|
+
),
|
|
224
|
+
],
|
|
225
|
+
undefined,
|
|
226
|
+
ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
227
|
+
ts.factory.createPrefixUnaryExpression(
|
|
228
|
+
ts.SyntaxKind.ExclamationToken,
|
|
229
|
+
ts.factory.createPrefixUnaryExpression(
|
|
230
|
+
ts.SyntaxKind.ExclamationToken,
|
|
231
|
+
ts.factory.createIdentifier("str"),
|
|
232
|
+
),
|
|
233
|
+
),
|
|
234
|
+
),
|
|
235
|
+
],
|
|
236
|
+
),
|
|
237
|
+
ts.factory.createIdentifier("join"),
|
|
238
|
+
),
|
|
239
|
+
undefined,
|
|
240
|
+
[ts.factory.createStringLiteral("/")],
|
|
241
|
+
);
|
|
242
|
+
const getPathParameterType =
|
|
243
|
+
(project: INestiaProject) =>
|
|
244
|
+
(importer: ImportDictionary) =>
|
|
245
|
+
(p: ITypedWebSocketRoute.IPathParameter) =>
|
|
246
|
+
p.metadata
|
|
247
|
+
? SdkTypeProgrammer.write(project)(importer)(p.metadata)
|
|
248
|
+
: ts.factory.createTypeReferenceNode(p.typeName);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
|
1
2
|
import { Singleton, VariadicSingleton } from "tstl";
|
|
2
3
|
import ts from "typescript";
|
|
3
4
|
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
@@ -7,12 +8,11 @@ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
|
7
8
|
import { ValidationPipe } from "typia/lib/typings/ValidationPipe";
|
|
8
9
|
|
|
9
10
|
import { INestiaConfig } from "../../INestiaConfig";
|
|
10
|
-
import { IRoute } from "../../structures/IRoute";
|
|
11
|
-
import { SwaggerSchemaValidator } from "./SwaggerSchemaValidator";
|
|
12
|
-
import { OpenApi } from "@samchon/openapi";
|
|
13
11
|
import { ISwaggerError } from "../../structures/ISwaggerError";
|
|
14
12
|
import { ISwaggerLazyProperty } from "../../structures/ISwaggerLazyProperty";
|
|
15
13
|
import { ISwaggerLazySchema } from "../../structures/ISwaggerLazySchema";
|
|
14
|
+
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
15
|
+
import { SwaggerSchemaValidator } from "./SwaggerSchemaValidator";
|
|
16
16
|
|
|
17
17
|
export namespace SwaggerSchemaGenerator {
|
|
18
18
|
export interface IProps {
|
|
@@ -26,7 +26,7 @@ export namespace SwaggerSchemaGenerator {
|
|
|
26
26
|
|
|
27
27
|
export const response =
|
|
28
28
|
(props: IProps) =>
|
|
29
|
-
(route:
|
|
29
|
+
(route: ITypedHttpRoute): Record<string, OpenApi.IOperation.IResponse> => {
|
|
30
30
|
const output: Record<string, OpenApi.IOperation.IResponse> = {};
|
|
31
31
|
|
|
32
32
|
//----
|
|
@@ -159,8 +159,8 @@ export namespace SwaggerSchemaGenerator {
|
|
|
159
159
|
|
|
160
160
|
export const body =
|
|
161
161
|
(props: IProps) =>
|
|
162
|
-
(route:
|
|
163
|
-
(param:
|
|
162
|
+
(route: ITypedHttpRoute) =>
|
|
163
|
+
(param: ITypedHttpRoute.IParameter): OpenApi.IOperation.IRequestBody => {
|
|
164
164
|
// ANALZE TYPE WITH VALIDATION
|
|
165
165
|
const result = MetadataFactory.analyze(props.checker)({
|
|
166
166
|
escape: true,
|
|
@@ -221,8 +221,8 @@ export namespace SwaggerSchemaGenerator {
|
|
|
221
221
|
|
|
222
222
|
export const parameter =
|
|
223
223
|
(props: IProps) =>
|
|
224
|
-
(route:
|
|
225
|
-
(param:
|
|
224
|
+
(route: ITypedHttpRoute) =>
|
|
225
|
+
(param: ITypedHttpRoute.IParameter): OpenApi.IOperation.IParameter[] =>
|
|
226
226
|
param.category === "headers"
|
|
227
227
|
? headers(props)(route)(param)
|
|
228
228
|
: param.category === "param"
|
|
@@ -231,8 +231,8 @@ export namespace SwaggerSchemaGenerator {
|
|
|
231
231
|
|
|
232
232
|
const path =
|
|
233
233
|
(props: IProps) =>
|
|
234
|
-
(route:
|
|
235
|
-
(param:
|
|
234
|
+
(route: ITypedHttpRoute) =>
|
|
235
|
+
(param: ITypedHttpRoute.IParameter): OpenApi.IOperation.IParameter => {
|
|
236
236
|
// ANALZE TYPE WITH VALIDATION
|
|
237
237
|
const result = MetadataFactory.analyze(props.checker)({
|
|
238
238
|
escape: false,
|
|
@@ -255,8 +255,8 @@ export namespace SwaggerSchemaGenerator {
|
|
|
255
255
|
|
|
256
256
|
const headers =
|
|
257
257
|
(props: IProps) =>
|
|
258
|
-
(route:
|
|
259
|
-
(param:
|
|
258
|
+
(route: ITypedHttpRoute) =>
|
|
259
|
+
(param: ITypedHttpRoute.IParameter): OpenApi.IOperation.IParameter[] =>
|
|
260
260
|
decomposible(props)(route)(param)(
|
|
261
261
|
MetadataFactory.analyze(props.checker)({
|
|
262
262
|
escape: false,
|
|
@@ -268,8 +268,8 @@ export namespace SwaggerSchemaGenerator {
|
|
|
268
268
|
|
|
269
269
|
const query =
|
|
270
270
|
(props: IProps) =>
|
|
271
|
-
(route:
|
|
272
|
-
(param:
|
|
271
|
+
(route: ITypedHttpRoute) =>
|
|
272
|
+
(param: ITypedHttpRoute.IParameter): OpenApi.IOperation.IParameter[] =>
|
|
273
273
|
decomposible(props)(route)(param)(
|
|
274
274
|
MetadataFactory.analyze(props.checker)({
|
|
275
275
|
escape: false,
|
|
@@ -281,8 +281,8 @@ export namespace SwaggerSchemaGenerator {
|
|
|
281
281
|
|
|
282
282
|
const decomposible =
|
|
283
283
|
(props: IProps) =>
|
|
284
|
-
(route:
|
|
285
|
-
(param:
|
|
284
|
+
(route: ITypedHttpRoute) =>
|
|
285
|
+
(param: ITypedHttpRoute.IParameter) =>
|
|
286
286
|
(
|
|
287
287
|
result: ValidationPipe<Metadata, MetadataFactory.IError>,
|
|
288
288
|
): OpenApi.IOperation.IParameter[] => {
|
|
@@ -316,7 +316,10 @@ export namespace SwaggerSchemaGenerator {
|
|
|
316
316
|
});
|
|
317
317
|
return {
|
|
318
318
|
name: p.key.constants[0].values[0].value as string,
|
|
319
|
-
in:
|
|
319
|
+
in:
|
|
320
|
+
param.category === "headers"
|
|
321
|
+
? "header"
|
|
322
|
+
: (param.category as "path"),
|
|
320
323
|
schema,
|
|
321
324
|
description: p.description ?? undefined,
|
|
322
325
|
required: p.value.isRequired(),
|
|
@@ -326,9 +329,9 @@ export namespace SwaggerSchemaGenerator {
|
|
|
326
329
|
|
|
327
330
|
const lazy =
|
|
328
331
|
(props: IProps) =>
|
|
329
|
-
(route:
|
|
332
|
+
(route: ITypedHttpRoute) =>
|
|
330
333
|
(
|
|
331
|
-
param:
|
|
334
|
+
param: ITypedHttpRoute.IParameter,
|
|
332
335
|
result: ValidationPipe<Metadata, MetadataFactory.IError>,
|
|
333
336
|
): OpenApi.IOperation.IParameter => {
|
|
334
337
|
const schema: OpenApi.IJsonSchema = coalesce(props)(result);
|
|
@@ -348,7 +351,9 @@ export namespace SwaggerSchemaGenerator {
|
|
|
348
351
|
|
|
349
352
|
const coalesce =
|
|
350
353
|
(props: IProps) =>
|
|
351
|
-
(
|
|
354
|
+
(
|
|
355
|
+
result: ValidationPipe<Metadata, MetadataFactory.IError>,
|
|
356
|
+
): OpenApi.IJsonSchema => {
|
|
352
357
|
const schema: OpenApi.IJsonSchema = {} as any;
|
|
353
358
|
props.lazySchemas.push({
|
|
354
359
|
metadata: result.success ? result.data : any.get(),
|
|
@@ -358,7 +363,7 @@ export namespace SwaggerSchemaGenerator {
|
|
|
358
363
|
};
|
|
359
364
|
|
|
360
365
|
const describe = (
|
|
361
|
-
route:
|
|
366
|
+
route: ITypedHttpRoute,
|
|
362
367
|
tagName: string,
|
|
363
368
|
parameterName?: string,
|
|
364
369
|
): string | undefined => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { VERSION_NEUTRAL } from "@nestjs/common/interfaces";
|
|
2
|
+
|
|
3
|
+
import { IReflectHttpOperation } from "./IReflectHttpOperation";
|
|
4
|
+
import { IReflectWebSocketOperation } from "./IReflectWebSocketOperation";
|
|
5
|
+
|
|
6
|
+
export interface IReflectController {
|
|
7
|
+
constructor: Function;
|
|
8
|
+
prototype: any;
|
|
9
|
+
file: string;
|
|
10
|
+
name: string;
|
|
11
|
+
prefixes: string[];
|
|
12
|
+
paths: string[];
|
|
13
|
+
versions: Array<string | typeof VERSION_NEUTRAL> | undefined;
|
|
14
|
+
operations: Array<IReflectHttpOperation | IReflectWebSocketOperation>;
|
|
15
|
+
security: Record<string, string[]>[];
|
|
16
|
+
swaggerTgas: string[];
|
|
17
|
+
}
|
|
@@ -1,94 +1,78 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
name: string;
|
|
9
|
-
|
|
10
|
-
paths: string[];
|
|
11
|
-
versions:
|
|
12
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
| "text/plain";
|
|
80
|
-
}
|
|
81
|
-
export interface IPathParameter {
|
|
82
|
-
custom: true;
|
|
83
|
-
category: "param";
|
|
84
|
-
index: number;
|
|
85
|
-
name: string;
|
|
86
|
-
field: string | undefined;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface IException {
|
|
90
|
-
type: string;
|
|
91
|
-
status: number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
92
|
-
description: string | undefined;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
import { VERSION_NEUTRAL } from "@nestjs/common/interfaces";
|
|
2
|
+
|
|
3
|
+
import { ParamCategory } from "./ParamCategory";
|
|
4
|
+
|
|
5
|
+
export interface IReflectHttpOperation {
|
|
6
|
+
protocol: "http";
|
|
7
|
+
function: Function;
|
|
8
|
+
name: string;
|
|
9
|
+
method: string;
|
|
10
|
+
paths: string[];
|
|
11
|
+
versions: Array<string | typeof VERSION_NEUTRAL> | undefined;
|
|
12
|
+
encrypted: boolean;
|
|
13
|
+
parameters: IReflectHttpOperation.IParameter[];
|
|
14
|
+
status?: number;
|
|
15
|
+
type?: string;
|
|
16
|
+
contentType: "application/json" | "text/plain";
|
|
17
|
+
security: Record<string, string[]>[];
|
|
18
|
+
exceptions: Record<
|
|
19
|
+
number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
20
|
+
IReflectHttpOperation.IException
|
|
21
|
+
>;
|
|
22
|
+
swaggerTags: string[];
|
|
23
|
+
}
|
|
24
|
+
export namespace IReflectHttpOperation {
|
|
25
|
+
export type IParameter =
|
|
26
|
+
| ICommonParameter
|
|
27
|
+
| IQueryParameter
|
|
28
|
+
| IHeadersParameter
|
|
29
|
+
| IBodyParameter
|
|
30
|
+
| IPathParameter;
|
|
31
|
+
export interface ICommonParameter {
|
|
32
|
+
custom: false;
|
|
33
|
+
category: ParamCategory;
|
|
34
|
+
index: number;
|
|
35
|
+
name: string;
|
|
36
|
+
field: string | undefined;
|
|
37
|
+
}
|
|
38
|
+
export interface IHeadersParameter {
|
|
39
|
+
custom: true;
|
|
40
|
+
category: "headers";
|
|
41
|
+
index: number;
|
|
42
|
+
name: string;
|
|
43
|
+
field: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface IQueryParameter {
|
|
46
|
+
custom: true;
|
|
47
|
+
category: "query";
|
|
48
|
+
index: number;
|
|
49
|
+
name: string;
|
|
50
|
+
field: string | undefined;
|
|
51
|
+
}
|
|
52
|
+
export interface IBodyParameter {
|
|
53
|
+
custom: true;
|
|
54
|
+
category: "body";
|
|
55
|
+
index: number;
|
|
56
|
+
name: string;
|
|
57
|
+
field: string | undefined;
|
|
58
|
+
encrypted: boolean;
|
|
59
|
+
contentType:
|
|
60
|
+
| "application/json"
|
|
61
|
+
| "application/x-www-form-urlencoded"
|
|
62
|
+
| "multipart/form-data"
|
|
63
|
+
| "text/plain";
|
|
64
|
+
}
|
|
65
|
+
export interface IPathParameter {
|
|
66
|
+
custom: true;
|
|
67
|
+
category: "param";
|
|
68
|
+
index: number;
|
|
69
|
+
name: string;
|
|
70
|
+
field: string | undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface IException {
|
|
74
|
+
type: string;
|
|
75
|
+
status: number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
76
|
+
description: string | undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VERSION_NEUTRAL } from "@nestjs/common";
|
|
2
|
+
|
|
3
|
+
export interface IReflectWebSocketOperation {
|
|
4
|
+
protocol: "websocket";
|
|
5
|
+
target: Function;
|
|
6
|
+
name: string;
|
|
7
|
+
paths: string[];
|
|
8
|
+
versions: Array<string | typeof VERSION_NEUTRAL> | undefined;
|
|
9
|
+
parameters: IReflectWebSocketOperation.IParameter[];
|
|
10
|
+
}
|
|
11
|
+
export namespace IReflectWebSocketOperation {
|
|
12
|
+
export interface IParameter {
|
|
13
|
+
category: "acceptor" | "driver" | "header" | "param" | "query";
|
|
14
|
+
field: string;
|
|
15
|
+
index: number;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { ITypedHttpRoute } from "./ITypedHttpRoute";
|
|
4
4
|
|
|
5
5
|
export interface ISwaggerError extends MetadataFactory.IError {
|
|
6
|
-
route:
|
|
6
|
+
route: ITypedHttpRoute;
|
|
7
7
|
from: string;
|
|
8
8
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { IReflectController } from "./IReflectController";
|
|
5
|
+
import { IReflectHttpOperation } from "./IReflectHttpOperation";
|
|
5
6
|
|
|
6
|
-
export interface
|
|
7
|
-
|
|
7
|
+
export interface ITypedHttpRoute {
|
|
8
|
+
protocol: "http";
|
|
9
|
+
controller: IReflectController;
|
|
10
|
+
function: Function;
|
|
8
11
|
name: string;
|
|
9
12
|
method: string;
|
|
10
13
|
path: string;
|
|
@@ -12,15 +15,11 @@ export interface IRoute {
|
|
|
12
15
|
status?: number;
|
|
13
16
|
|
|
14
17
|
accessors: string[];
|
|
15
|
-
parameters:
|
|
18
|
+
parameters: ITypedHttpRoute.IParameter[];
|
|
16
19
|
imports: [string, string[]][];
|
|
17
|
-
output:
|
|
20
|
+
output: ITypedHttpRoute.IOutput;
|
|
18
21
|
|
|
19
22
|
location: string;
|
|
20
|
-
target: {
|
|
21
|
-
class: Function;
|
|
22
|
-
function: Function;
|
|
23
|
-
};
|
|
24
23
|
description?: string;
|
|
25
24
|
operationId?: string;
|
|
26
25
|
jsDocTags: ts.JSDocTagInfo[];
|
|
@@ -29,12 +28,15 @@ export interface IRoute {
|
|
|
29
28
|
| { type: "assigner"; source: string }
|
|
30
29
|
>;
|
|
31
30
|
security: Record<string, string[]>[];
|
|
32
|
-
exceptions: Record<
|
|
31
|
+
exceptions: Record<
|
|
32
|
+
number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
33
|
+
ITypedHttpRoute.IOutput
|
|
34
|
+
>;
|
|
33
35
|
swaggerTags: string[];
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
export namespace
|
|
37
|
-
export type IParameter =
|
|
38
|
+
export namespace ITypedHttpRoute {
|
|
39
|
+
export type IParameter = IReflectHttpOperation.IParameter & {
|
|
38
40
|
optional: boolean;
|
|
39
41
|
type: ts.Type;
|
|
40
42
|
typeName: string;
|