@nestia/sdk 3.11.0-dev.20240813-11 → 3.11.0-dev.20240814
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 +20 -7
- 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 +15 -7
- 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 +10 -4
- 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 +28 -9
- 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 +248 -229
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +2 -2
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +6 -3
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +12 -8
- 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
|
@@ -77,6 +77,8 @@ export namespace SwaggerOperationParameterComposer {
|
|
|
77
77
|
jsDocTags: props.parameter.jsDocTags,
|
|
78
78
|
kind: "title",
|
|
79
79
|
}),
|
|
80
|
+
example: props.parameter.example,
|
|
81
|
+
examples: props.parameter.examples,
|
|
80
82
|
});
|
|
81
83
|
|
|
82
84
|
export const query = (
|
|
@@ -114,6 +116,7 @@ export namespace SwaggerOperationParameterComposer {
|
|
|
114
116
|
jsDocTags: props.jsDocTags,
|
|
115
117
|
kind: "title",
|
|
116
118
|
}),
|
|
119
|
+
required: props.parameter.metadata.isRequired(),
|
|
117
120
|
example: props.parameter.example,
|
|
118
121
|
examples: props.parameter.examples,
|
|
119
122
|
};
|
package/src/transform.ts
CHANGED
|
@@ -5,5 +5,5 @@ import { SdkOperationTransformer } from "./transformers/SdkOperationTransformer"
|
|
|
5
5
|
export const transform = (
|
|
6
6
|
program: ts.Program,
|
|
7
7
|
): ts.TransformerFactory<ts.SourceFile> =>
|
|
8
|
-
SdkOperationTransformer.
|
|
8
|
+
SdkOperationTransformer.iterateFile(program.getTypeChecker());
|
|
9
9
|
export default transform;
|
|
@@ -21,35 +21,37 @@ export namespace SdkOperationProgrammer {
|
|
|
21
21
|
symbol: ts.Symbol | undefined;
|
|
22
22
|
exceptions: ts.TypeNode[];
|
|
23
23
|
}
|
|
24
|
-
export const write = (p: IProps): IOperationMetadata =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
generics: p.generics,
|
|
36
|
-
type: getReturnType({
|
|
37
|
-
checker: p.context.checker,
|
|
38
|
-
type: p.node.type
|
|
39
|
-
? p.context.checker.getTypeFromTypeNode(p.node.type)
|
|
40
|
-
: null,
|
|
41
|
-
}),
|
|
42
|
-
}),
|
|
43
|
-
exceptions: p.exceptions.map((e) =>
|
|
44
|
-
writeResponse({
|
|
24
|
+
export const write = (p: IProps): IOperationMetadata => {
|
|
25
|
+
return {
|
|
26
|
+
parameters: p.node.parameters.map((parameter, index) =>
|
|
27
|
+
writeParameter({
|
|
28
|
+
context: p.context,
|
|
29
|
+
generics: p.generics,
|
|
30
|
+
parameter,
|
|
31
|
+
index,
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
success: writeResponse({
|
|
45
35
|
context: p.context,
|
|
46
36
|
generics: p.generics,
|
|
47
|
-
type:
|
|
37
|
+
type: getReturnType({
|
|
38
|
+
checker: p.context.checker,
|
|
39
|
+
signature: p.context.checker.getSignatureFromDeclaration(p.node),
|
|
40
|
+
}),
|
|
48
41
|
}),
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
exceptions: p.exceptions.map((e) =>
|
|
43
|
+
writeResponse({
|
|
44
|
+
context: p.context,
|
|
45
|
+
generics: p.generics,
|
|
46
|
+
type: p.context.checker.getTypeFromTypeNode(e),
|
|
47
|
+
}),
|
|
48
|
+
),
|
|
49
|
+
jsDocTags: p.symbol?.getJsDocTags() ?? [],
|
|
50
|
+
description: p.symbol
|
|
51
|
+
? CommentFactory.description(p.symbol) ?? null
|
|
52
|
+
: null,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
53
55
|
|
|
54
56
|
const writeParameter = (props: {
|
|
55
57
|
context: ISdkOperationTransformerContext;
|
|
@@ -59,15 +61,17 @@ export namespace SdkOperationProgrammer {
|
|
|
59
61
|
}): IOperationMetadata.IParameter => {
|
|
60
62
|
const symbol: ts.Symbol | undefined =
|
|
61
63
|
props.context.checker.getSymbolAtLocation(props.parameter);
|
|
64
|
+
const common: IOperationMetadata.IResponse = writeType({
|
|
65
|
+
context: props.context,
|
|
66
|
+
generics: props.generics,
|
|
67
|
+
type:
|
|
68
|
+
props.context.checker.getTypeFromTypeNode(
|
|
69
|
+
props.parameter.type ?? TypeFactory.keyword("any"),
|
|
70
|
+
) ?? null,
|
|
71
|
+
required: props.parameter.questionToken === undefined,
|
|
72
|
+
});
|
|
62
73
|
return {
|
|
63
|
-
...
|
|
64
|
-
...props,
|
|
65
|
-
type:
|
|
66
|
-
props.context.checker.getTypeFromTypeNode(
|
|
67
|
-
props.parameter.type ?? TypeFactory.keyword("any"),
|
|
68
|
-
) ?? null,
|
|
69
|
-
required: props.parameter.questionToken === undefined,
|
|
70
|
-
}),
|
|
74
|
+
...common,
|
|
71
75
|
name: props.parameter.name.getText(),
|
|
72
76
|
index: props.index,
|
|
73
77
|
description: (symbol && CommentFactory.description(symbol)) ?? null,
|
|
@@ -168,9 +172,10 @@ export namespace SdkOperationProgrammer {
|
|
|
168
172
|
|
|
169
173
|
const getReturnType = (p: {
|
|
170
174
|
checker: ts.TypeChecker;
|
|
171
|
-
|
|
175
|
+
signature: ts.Signature | undefined;
|
|
172
176
|
}): ts.Type | null => {
|
|
173
|
-
const type: ts.Type | null =
|
|
177
|
+
const type: ts.Type | null =
|
|
178
|
+
(p.signature && p.checker.getReturnTypeOfSignature(p.signature)) ?? null;
|
|
174
179
|
if (type === null) return null;
|
|
175
180
|
else if (type.symbol?.name === "Promise") {
|
|
176
181
|
const generic: readonly ts.Type[] = p.checker.getTypeArguments(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { HashSet, hash } from "tstl";
|
|
2
|
+
import { HashSet, Singleton, hash } from "tstl";
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
|
|
5
5
|
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
@@ -11,14 +11,12 @@ import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerConte
|
|
|
11
11
|
import { SdkOperationProgrammer } from "./SdkOperationProgrammer";
|
|
12
12
|
|
|
13
13
|
export namespace SdkOperationTransformer {
|
|
14
|
-
export const
|
|
14
|
+
export const iterateFile =
|
|
15
15
|
(checker: ts.TypeChecker) => (api: ts.TransformationContext) => {
|
|
16
16
|
const context: ISdkOperationTransformerContext = {
|
|
17
17
|
checker,
|
|
18
18
|
api,
|
|
19
|
-
collection:
|
|
20
|
-
replace: MetadataCollection.replace,
|
|
21
|
-
}),
|
|
19
|
+
collection: collection.get(),
|
|
22
20
|
};
|
|
23
21
|
return (file: ts.SourceFile): ts.SourceFile => {
|
|
24
22
|
if (file.isDeclarationFile === true) return file;
|
|
@@ -29,7 +27,7 @@ export namespace SdkOperationTransformer {
|
|
|
29
27
|
file = ts.visitEachChild(
|
|
30
28
|
file,
|
|
31
29
|
(node) =>
|
|
32
|
-
|
|
30
|
+
iterateNode({
|
|
33
31
|
context,
|
|
34
32
|
visitor,
|
|
35
33
|
node,
|
|
@@ -62,17 +60,33 @@ export namespace SdkOperationTransformer {
|
|
|
62
60
|
visited: HashSet<MethodKey>;
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
const
|
|
63
|
+
const iterateNode = (props: {
|
|
66
64
|
context: ISdkOperationTransformerContext;
|
|
67
65
|
visitor: IVisitor;
|
|
68
66
|
node: ts.Node;
|
|
69
67
|
}): ts.Node =>
|
|
70
|
-
ts.
|
|
68
|
+
ts.visitEachChild(
|
|
69
|
+
transformNode(props),
|
|
70
|
+
(child) =>
|
|
71
|
+
iterateNode({
|
|
72
|
+
...props,
|
|
73
|
+
node: child,
|
|
74
|
+
}),
|
|
75
|
+
props.context.api,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const transformNode = (props: {
|
|
79
|
+
context: ISdkOperationTransformerContext;
|
|
80
|
+
visitor: IVisitor;
|
|
81
|
+
node: ts.Node;
|
|
82
|
+
}): ts.Node => {
|
|
83
|
+
return ts.isClassDeclaration(props.node)
|
|
71
84
|
? transformClass({
|
|
72
85
|
...props,
|
|
73
86
|
node: props.node,
|
|
74
87
|
})
|
|
75
88
|
: props.node;
|
|
89
|
+
};
|
|
76
90
|
|
|
77
91
|
const transformClass = (props: {
|
|
78
92
|
context: ISdkOperationTransformerContext;
|
|
@@ -217,3 +231,10 @@ const TYPED_EXCEPTION_PATH = path.join(
|
|
|
217
231
|
"decorators",
|
|
218
232
|
`TypedException.d.ts`,
|
|
219
233
|
);
|
|
234
|
+
|
|
235
|
+
const collection = new Singleton(
|
|
236
|
+
() =>
|
|
237
|
+
new MetadataCollection({
|
|
238
|
+
replace: MetadataCollection.replace,
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
2
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
+
import { MetadataArrayType } from "typia/lib/schemas/metadata/MetadataArrayType";
|
|
4
|
+
|
|
5
|
+
export namespace HttpHeadersValidator {
|
|
6
|
+
export const validate = (
|
|
7
|
+
meta: Metadata,
|
|
8
|
+
explore: MetadataFactory.IExplore,
|
|
9
|
+
): string[] => {
|
|
10
|
+
const errors: string[] = [];
|
|
11
|
+
const insert = (msg: string) => errors.push(msg);
|
|
12
|
+
|
|
13
|
+
if (explore.top === true) {
|
|
14
|
+
const expected: number =
|
|
15
|
+
meta.atomics.length +
|
|
16
|
+
meta.templates.length +
|
|
17
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0) +
|
|
18
|
+
meta.arrays.length;
|
|
19
|
+
if (meta.size() !== expected)
|
|
20
|
+
insert("Only atomic or array of atomic types are allowed.");
|
|
21
|
+
} else if (
|
|
22
|
+
explore.nested !== null &&
|
|
23
|
+
explore.nested instanceof MetadataArrayType
|
|
24
|
+
) {
|
|
25
|
+
const expected: number =
|
|
26
|
+
meta.atomics.length +
|
|
27
|
+
meta.templates.length +
|
|
28
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
29
|
+
if (meta.size() !== expected)
|
|
30
|
+
insert("Only atomic types are allowed in array.");
|
|
31
|
+
}
|
|
32
|
+
return errors;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
2
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
+
import { MetadataArrayType } from "typia/lib/schemas/metadata/MetadataArrayType";
|
|
4
|
+
|
|
5
|
+
export namespace HttpQueryValidator {
|
|
6
|
+
export const validate = (
|
|
7
|
+
meta: Metadata,
|
|
8
|
+
explore: MetadataFactory.IExplore,
|
|
9
|
+
): string[] => {
|
|
10
|
+
const errors: string[] = [];
|
|
11
|
+
const insert = (msg: string) => errors.push(msg);
|
|
12
|
+
|
|
13
|
+
if (explore.top === true) {
|
|
14
|
+
const expected: number =
|
|
15
|
+
meta.atomics.length +
|
|
16
|
+
meta.templates.length +
|
|
17
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0) +
|
|
18
|
+
meta.arrays.length;
|
|
19
|
+
if (meta.size() !== expected)
|
|
20
|
+
insert("Only atomic or array of atomic types are allowed.");
|
|
21
|
+
} else if (
|
|
22
|
+
explore.nested !== null &&
|
|
23
|
+
explore.nested instanceof MetadataArrayType
|
|
24
|
+
) {
|
|
25
|
+
const expected: number =
|
|
26
|
+
meta.atomics.length +
|
|
27
|
+
meta.templates.length +
|
|
28
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
29
|
+
if (meta.size() !== expected)
|
|
30
|
+
insert("Only atomic types are allowed in array.");
|
|
31
|
+
}
|
|
32
|
+
return errors;
|
|
33
|
+
};
|
|
34
|
+
}
|