@nestia/sdk 4.4.2-dev.20241217 → 4.4.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/LICENSE +21 -21
- package/README.md +87 -87
- package/assets/bundle/api/HttpError.ts +1 -1
- package/assets/bundle/api/IConnection.ts +1 -1
- package/assets/bundle/api/Primitive.ts +1 -1
- package/assets/bundle/api/Resolved.ts +1 -1
- package/assets/bundle/api/index.ts +4 -4
- package/assets/bundle/api/module.ts +6 -6
- package/assets/bundle/distribute/README.md +37 -37
- package/assets/bundle/distribute/package.json +28 -28
- package/assets/bundle/distribute/tsconfig.json +109 -109
- package/assets/bundle/e2e/index.ts +42 -42
- package/assets/config/nestia.config.ts +97 -97
- package/lib/executable/internal/NestiaConfigLoader.js +4 -4
- package/lib/executable/sdk.js +12 -12
- package/package.json +5 -5
- package/src/INestiaConfig.ts +271 -271
- package/src/NestiaSdkApplication.ts +307 -307
- package/src/NestiaSwaggerComposer.ts +138 -138
- package/src/analyses/AccessorAnalyzer.ts +67 -67
- package/src/analyses/ConfigAnalyzer.ts +155 -155
- package/src/analyses/ExceptionAnalyzer.ts +154 -154
- package/src/analyses/GenericAnalyzer.ts +49 -49
- package/src/analyses/ImportAnalyzer.ts +171 -171
- package/src/analyses/PathAnalyzer.ts +69 -69
- package/src/analyses/ReflectControllerAnalyzer.ts +105 -105
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
- package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +71 -71
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +348 -348
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +127 -127
- package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +172 -172
- package/src/analyses/SecurityAnalyzer.ts +25 -25
- package/src/analyses/TypedHttpRouteAnalyzer.ts +186 -186
- package/src/analyses/TypedWebSocketRouteAnalyzer.ts +18 -18
- package/src/decorators/OperationMetadata.ts +15 -15
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigLoader.ts +78 -78
- package/src/executable/internal/NestiaSdkCommand.ts +103 -103
- package/src/executable/sdk.ts +75 -75
- package/src/generates/CloneGenerator.ts +66 -66
- package/src/generates/E2eGenerator.ts +32 -32
- package/src/generates/SdkGenerator.ts +159 -159
- package/src/generates/SwaggerGenerator.ts +292 -292
- package/src/generates/internal/E2eFileProgrammer.ts +183 -183
- package/src/generates/internal/FilePrinter.ts +53 -53
- package/src/generates/internal/ImportDictionary.ts +147 -147
- package/src/generates/internal/SdkAliasCollection.ts +185 -185
- package/src/generates/internal/SdkDistributionComposer.ts +103 -103
- package/src/generates/internal/SdkFileProgrammer.ts +116 -116
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +124 -124
- package/src/generates/internal/SdkHttpCloneReferencer.ts +71 -71
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +301 -301
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +529 -529
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +117 -117
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +362 -362
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkRouteDirectory.ts +18 -18
- package/src/generates/internal/SdkTypeProgrammer.ts +377 -377
- package/src/generates/internal/SdkTypeTagProgrammer.ts +120 -120
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +363 -363
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +265 -265
- package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
- package/src/generates/internal/SwaggerOperationComposer.ts +117 -117
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +177 -177
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
- package/src/index.ts +4 -4
- package/src/module.ts +3 -3
- package/src/structures/INestiaProject.ts +13 -13
- package/src/structures/INestiaSdkInput.ts +20 -20
- package/src/structures/IReflectApplication.ts +8 -8
- package/src/structures/IReflectController.ts +15 -15
- package/src/structures/IReflectHttpOperation.ts +26 -26
- package/src/structures/IReflectHttpOperationException.ts +19 -19
- package/src/structures/IReflectHttpOperationParameter.ts +81 -81
- package/src/structures/IReflectHttpOperationSuccess.ts +22 -22
- package/src/structures/IReflectOperationError.ts +26 -26
- package/src/structures/IReflectType.ts +4 -4
- package/src/structures/IReflectTypeImport.ts +4 -4
- package/src/structures/IReflectWebSocketOperation.ts +17 -17
- package/src/structures/IReflectWebSocketOperationParameter.ts +38 -38
- package/src/structures/ITypedApplication.ts +11 -11
- package/src/structures/ITypedHttpRoute.ts +30 -30
- package/src/structures/ITypedHttpRouteException.ts +15 -15
- package/src/structures/ITypedHttpRouteParameter.ts +41 -41
- package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
- package/src/structures/ITypedWebSocketRoute.ts +20 -20
- package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
- package/src/structures/MethodType.ts +5 -5
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +22 -22
- package/src/transform.ts +9 -9
- package/src/transformers/IOperationMetadata.ts +44 -44
- package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
- package/src/transformers/SdkOperationProgrammer.ts +209 -209
- package/src/transformers/SdkOperationTransformer.ts +253 -253
- package/src/transformers/TextPlainValidator.ts +17 -17
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/FileRetriever.ts +22 -22
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/MetadataUtil.ts +26 -26
- package/src/utils/PathUtil.ts +10 -10
- package/src/utils/SourceFinder.ts +66 -66
- package/src/utils/StringUtil.ts +17 -17
- package/src/utils/StripEnums.ts +5 -5
- package/src/utils/VersioningStrategy.ts +28 -28
- package/src/validators/HttpHeadersValidator.ts +34 -34
- package/src/validators/HttpQueryValidator.ts +34 -34
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
|
2
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
-
|
|
4
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
5
|
-
import { SecurityAnalyzer } from "../../analyses/SecurityAnalyzer";
|
|
6
|
-
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
7
|
-
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
8
|
-
import { SwaggerDescriptionComposer } from "./SwaggerDescriptionComposer";
|
|
9
|
-
import { SwaggerOperationParameterComposer } from "./SwaggerOperationParameterComposer";
|
|
10
|
-
import { SwaggerOperationResponseComposer } from "./SwaggerOperationResponseComposer";
|
|
11
|
-
|
|
12
|
-
export namespace SwaggerOperationComposer {
|
|
13
|
-
export const compose = (props: {
|
|
14
|
-
config: Omit<INestiaConfig.ISwaggerConfig, "output">;
|
|
15
|
-
document: OpenApi.IDocument;
|
|
16
|
-
schema: (metadata: Metadata) => OpenApi.IJsonSchema | undefined;
|
|
17
|
-
route: ITypedHttpRoute;
|
|
18
|
-
}): OpenApi.IOperation => {
|
|
19
|
-
// FIND REQUEST BODY
|
|
20
|
-
const body: ITypedHttpRouteParameter.IBody | undefined =
|
|
21
|
-
props.route.parameters.find((param) => param.category === "body");
|
|
22
|
-
|
|
23
|
-
// COMPOSE TAGS
|
|
24
|
-
const tags: Set<string> = new Set([
|
|
25
|
-
...props.route.controller.tags,
|
|
26
|
-
...props.route.tags,
|
|
27
|
-
...SwaggerDescriptionComposer.getJsDocTexts({
|
|
28
|
-
jsDocTags: props.route.jsDocTags,
|
|
29
|
-
name: "tag",
|
|
30
|
-
}).map((t) => t.split(" ")[0]),
|
|
31
|
-
]);
|
|
32
|
-
if (tags.size) {
|
|
33
|
-
props.document.tags ??= [];
|
|
34
|
-
for (const t of tags)
|
|
35
|
-
if (props.document.tags.find((elem) => elem.name === t) === undefined)
|
|
36
|
-
props.document.tags.push({ name: t });
|
|
37
|
-
for (const texts of SwaggerDescriptionComposer.getJsDocTexts({
|
|
38
|
-
jsDocTags: props.route.jsDocTags,
|
|
39
|
-
name: "tag",
|
|
40
|
-
})) {
|
|
41
|
-
const [name, ...description] = texts.split(" ");
|
|
42
|
-
if (description.length)
|
|
43
|
-
props.document.tags.find(
|
|
44
|
-
(elem) => elem.name === name,
|
|
45
|
-
)!.description ??= description.join(" ");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// SECURITY
|
|
50
|
-
const security: Record<string, string[]>[] = SecurityAnalyzer.merge(
|
|
51
|
-
...props.route.controller.security,
|
|
52
|
-
...props.route.security,
|
|
53
|
-
...props.route.jsDocTags
|
|
54
|
-
.filter((tag) => tag.name === "security")
|
|
55
|
-
.map((tag) =>
|
|
56
|
-
tag.text === undefined
|
|
57
|
-
? [{}]
|
|
58
|
-
: tag.text.map((text) => {
|
|
59
|
-
const line: string[] = text.text
|
|
60
|
-
.split(" ")
|
|
61
|
-
.filter((s) => s.trim())
|
|
62
|
-
.filter((s) => !!s.length);
|
|
63
|
-
if (line.length === 0) return {};
|
|
64
|
-
return {
|
|
65
|
-
[line[0]]: line.slice(1),
|
|
66
|
-
};
|
|
67
|
-
}),
|
|
68
|
-
)
|
|
69
|
-
.flat(),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
// FINALIZE
|
|
73
|
-
return {
|
|
74
|
-
...SwaggerDescriptionComposer.compose({
|
|
75
|
-
description: props.route.description,
|
|
76
|
-
jsDocTags: props.route.jsDocTags,
|
|
77
|
-
kind: "summary",
|
|
78
|
-
}),
|
|
79
|
-
deprecated: props.route.jsDocTags.some((tag) => tag.name === "deprecated")
|
|
80
|
-
? true
|
|
81
|
-
: undefined,
|
|
82
|
-
tags: Array.from(tags),
|
|
83
|
-
operationId:
|
|
84
|
-
props.route.operationId ??
|
|
85
|
-
props.config.operationId?.({
|
|
86
|
-
class: props.route.controller.class.name,
|
|
87
|
-
function: props.route.name,
|
|
88
|
-
method: props.route.method as "GET",
|
|
89
|
-
path: props.route.path,
|
|
90
|
-
}),
|
|
91
|
-
parameters: props.route.parameters
|
|
92
|
-
.map((p) =>
|
|
93
|
-
SwaggerOperationParameterComposer.compose({
|
|
94
|
-
config: props.config,
|
|
95
|
-
document: props.document,
|
|
96
|
-
schema: props.schema(p.metadata)!,
|
|
97
|
-
parameter: p,
|
|
98
|
-
jsDocTags: props.route.jsDocTags,
|
|
99
|
-
}),
|
|
100
|
-
)
|
|
101
|
-
.flat(),
|
|
102
|
-
requestBody: body
|
|
103
|
-
? SwaggerOperationParameterComposer.body({
|
|
104
|
-
schema: props.schema(body.metadata)!,
|
|
105
|
-
jsDocTags: props.route.jsDocTags,
|
|
106
|
-
parameter: body,
|
|
107
|
-
})
|
|
108
|
-
: undefined,
|
|
109
|
-
responses: SwaggerOperationResponseComposer.compose({
|
|
110
|
-
schema: props.schema,
|
|
111
|
-
route: props.route,
|
|
112
|
-
}),
|
|
113
|
-
security: security.length ? security : undefined,
|
|
114
|
-
...(props.route.extensions ?? {}),
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
}
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
|
2
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
+
|
|
4
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
5
|
+
import { SecurityAnalyzer } from "../../analyses/SecurityAnalyzer";
|
|
6
|
+
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
7
|
+
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
8
|
+
import { SwaggerDescriptionComposer } from "./SwaggerDescriptionComposer";
|
|
9
|
+
import { SwaggerOperationParameterComposer } from "./SwaggerOperationParameterComposer";
|
|
10
|
+
import { SwaggerOperationResponseComposer } from "./SwaggerOperationResponseComposer";
|
|
11
|
+
|
|
12
|
+
export namespace SwaggerOperationComposer {
|
|
13
|
+
export const compose = (props: {
|
|
14
|
+
config: Omit<INestiaConfig.ISwaggerConfig, "output">;
|
|
15
|
+
document: OpenApi.IDocument;
|
|
16
|
+
schema: (metadata: Metadata) => OpenApi.IJsonSchema | undefined;
|
|
17
|
+
route: ITypedHttpRoute;
|
|
18
|
+
}): OpenApi.IOperation => {
|
|
19
|
+
// FIND REQUEST BODY
|
|
20
|
+
const body: ITypedHttpRouteParameter.IBody | undefined =
|
|
21
|
+
props.route.parameters.find((param) => param.category === "body");
|
|
22
|
+
|
|
23
|
+
// COMPOSE TAGS
|
|
24
|
+
const tags: Set<string> = new Set([
|
|
25
|
+
...props.route.controller.tags,
|
|
26
|
+
...props.route.tags,
|
|
27
|
+
...SwaggerDescriptionComposer.getJsDocTexts({
|
|
28
|
+
jsDocTags: props.route.jsDocTags,
|
|
29
|
+
name: "tag",
|
|
30
|
+
}).map((t) => t.split(" ")[0]),
|
|
31
|
+
]);
|
|
32
|
+
if (tags.size) {
|
|
33
|
+
props.document.tags ??= [];
|
|
34
|
+
for (const t of tags)
|
|
35
|
+
if (props.document.tags.find((elem) => elem.name === t) === undefined)
|
|
36
|
+
props.document.tags.push({ name: t });
|
|
37
|
+
for (const texts of SwaggerDescriptionComposer.getJsDocTexts({
|
|
38
|
+
jsDocTags: props.route.jsDocTags,
|
|
39
|
+
name: "tag",
|
|
40
|
+
})) {
|
|
41
|
+
const [name, ...description] = texts.split(" ");
|
|
42
|
+
if (description.length)
|
|
43
|
+
props.document.tags.find(
|
|
44
|
+
(elem) => elem.name === name,
|
|
45
|
+
)!.description ??= description.join(" ");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// SECURITY
|
|
50
|
+
const security: Record<string, string[]>[] = SecurityAnalyzer.merge(
|
|
51
|
+
...props.route.controller.security,
|
|
52
|
+
...props.route.security,
|
|
53
|
+
...props.route.jsDocTags
|
|
54
|
+
.filter((tag) => tag.name === "security")
|
|
55
|
+
.map((tag) =>
|
|
56
|
+
tag.text === undefined
|
|
57
|
+
? [{}]
|
|
58
|
+
: tag.text.map((text) => {
|
|
59
|
+
const line: string[] = text.text
|
|
60
|
+
.split(" ")
|
|
61
|
+
.filter((s) => s.trim())
|
|
62
|
+
.filter((s) => !!s.length);
|
|
63
|
+
if (line.length === 0) return {};
|
|
64
|
+
return {
|
|
65
|
+
[line[0]]: line.slice(1),
|
|
66
|
+
};
|
|
67
|
+
}),
|
|
68
|
+
)
|
|
69
|
+
.flat(),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// FINALIZE
|
|
73
|
+
return {
|
|
74
|
+
...SwaggerDescriptionComposer.compose({
|
|
75
|
+
description: props.route.description,
|
|
76
|
+
jsDocTags: props.route.jsDocTags,
|
|
77
|
+
kind: "summary",
|
|
78
|
+
}),
|
|
79
|
+
deprecated: props.route.jsDocTags.some((tag) => tag.name === "deprecated")
|
|
80
|
+
? true
|
|
81
|
+
: undefined,
|
|
82
|
+
tags: Array.from(tags),
|
|
83
|
+
operationId:
|
|
84
|
+
props.route.operationId ??
|
|
85
|
+
props.config.operationId?.({
|
|
86
|
+
class: props.route.controller.class.name,
|
|
87
|
+
function: props.route.name,
|
|
88
|
+
method: props.route.method as "GET",
|
|
89
|
+
path: props.route.path,
|
|
90
|
+
}),
|
|
91
|
+
parameters: props.route.parameters
|
|
92
|
+
.map((p) =>
|
|
93
|
+
SwaggerOperationParameterComposer.compose({
|
|
94
|
+
config: props.config,
|
|
95
|
+
document: props.document,
|
|
96
|
+
schema: props.schema(p.metadata)!,
|
|
97
|
+
parameter: p,
|
|
98
|
+
jsDocTags: props.route.jsDocTags,
|
|
99
|
+
}),
|
|
100
|
+
)
|
|
101
|
+
.flat(),
|
|
102
|
+
requestBody: body
|
|
103
|
+
? SwaggerOperationParameterComposer.body({
|
|
104
|
+
schema: props.schema(body.metadata)!,
|
|
105
|
+
jsDocTags: props.route.jsDocTags,
|
|
106
|
+
parameter: body,
|
|
107
|
+
})
|
|
108
|
+
: undefined,
|
|
109
|
+
responses: SwaggerOperationResponseComposer.compose({
|
|
110
|
+
schema: props.schema,
|
|
111
|
+
route: props.route,
|
|
112
|
+
}),
|
|
113
|
+
security: security.length ? security : undefined,
|
|
114
|
+
...(props.route.extensions ?? {}),
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
|
2
|
-
import { VariadicSingleton } from "tstl";
|
|
3
|
-
import { IJsDocTagInfo, IJsonSchemaCollection } from "typia";
|
|
4
|
-
import { JsonSchemasProgrammer } from "typia/lib/programmers/json/JsonSchemasProgrammer";
|
|
5
|
-
|
|
6
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
7
|
-
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
8
|
-
import { SwaggerDescriptionComposer } from "./SwaggerDescriptionComposer";
|
|
9
|
-
|
|
10
|
-
export namespace SwaggerOperationParameterComposer {
|
|
11
|
-
export interface IProps<Parameter extends ITypedHttpRouteParameter> {
|
|
12
|
-
config: Omit<INestiaConfig.ISwaggerConfig, "output">;
|
|
13
|
-
document: OpenApi.IDocument;
|
|
14
|
-
schema: OpenApi.IJsonSchema;
|
|
15
|
-
jsDocTags: IJsDocTagInfo[];
|
|
16
|
-
parameter: Parameter;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const compose = (
|
|
20
|
-
props: IProps<ITypedHttpRouteParameter>,
|
|
21
|
-
): OpenApi.IOperation.IParameter[] =>
|
|
22
|
-
props.parameter.category === "body"
|
|
23
|
-
? []
|
|
24
|
-
: props.parameter.category === "param"
|
|
25
|
-
? [path({ ...props, parameter: props.parameter })]
|
|
26
|
-
: props.parameter.category === "query"
|
|
27
|
-
? query({ ...props, parameter: props.parameter })
|
|
28
|
-
: header({ ...props, parameter: props.parameter });
|
|
29
|
-
|
|
30
|
-
export const body = (
|
|
31
|
-
props: Omit<IProps<ITypedHttpRouteParameter.IBody>, "config" | "document">,
|
|
32
|
-
): OpenApi.IOperation.IRequestBody => {
|
|
33
|
-
const description: string | undefined =
|
|
34
|
-
SwaggerDescriptionComposer.descriptionFromJsDocTag({
|
|
35
|
-
jsDocTags: props.jsDocTags,
|
|
36
|
-
tag: "param",
|
|
37
|
-
parameter: props.parameter.name,
|
|
38
|
-
});
|
|
39
|
-
return {
|
|
40
|
-
description: props.parameter.encrypted
|
|
41
|
-
? `${warning.get(!!description)}${description ?? ""}`
|
|
42
|
-
: description,
|
|
43
|
-
content: {
|
|
44
|
-
[props.parameter.contentType]: {
|
|
45
|
-
schema: props.schema,
|
|
46
|
-
example: props.parameter.example,
|
|
47
|
-
examples: props.parameter.examples,
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
required: props.parameter.metadata.isRequired(),
|
|
51
|
-
...(props.parameter.encrypted ? { "x-nestia-encrypted": true } : {}),
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const path = (
|
|
56
|
-
props: Omit<IProps<ITypedHttpRouteParameter.IParam>, "config" | "document">,
|
|
57
|
-
): OpenApi.IOperation.IParameter => ({
|
|
58
|
-
name: props.parameter.field,
|
|
59
|
-
in: "path",
|
|
60
|
-
schema: props.schema,
|
|
61
|
-
required: props.parameter.metadata.isRequired(),
|
|
62
|
-
...SwaggerDescriptionComposer.compose({
|
|
63
|
-
description:
|
|
64
|
-
props.parameter.description ??
|
|
65
|
-
props.parameter.jsDocTags.find((tag) => tag.name === "description")
|
|
66
|
-
?.text?.[0].text ??
|
|
67
|
-
props.jsDocTags
|
|
68
|
-
.find(
|
|
69
|
-
(tag) =>
|
|
70
|
-
tag.name === "param" &&
|
|
71
|
-
tag.text?.[0].text === props.parameter.name,
|
|
72
|
-
)
|
|
73
|
-
?.text?.map((e) => e.text)
|
|
74
|
-
.join("")
|
|
75
|
-
.substring(props.parameter.name.length) ??
|
|
76
|
-
null,
|
|
77
|
-
jsDocTags: props.parameter.jsDocTags,
|
|
78
|
-
kind: "title",
|
|
79
|
-
}),
|
|
80
|
-
example: props.parameter.example,
|
|
81
|
-
examples: props.parameter.examples,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
export const query = (
|
|
85
|
-
props: IProps<ITypedHttpRouteParameter.IQuery>,
|
|
86
|
-
): OpenApi.IOperation.IParameter[] => decomposible(props);
|
|
87
|
-
|
|
88
|
-
export const header = (
|
|
89
|
-
props: IProps<ITypedHttpRouteParameter.IHeaders>,
|
|
90
|
-
): OpenApi.IOperation.IParameter[] => decomposible(props);
|
|
91
|
-
|
|
92
|
-
const decomposible = (
|
|
93
|
-
props: IProps<
|
|
94
|
-
ITypedHttpRouteParameter.IHeaders | ITypedHttpRouteParameter.IQuery
|
|
95
|
-
>,
|
|
96
|
-
): OpenApi.IOperation.IParameter[] => {
|
|
97
|
-
const param: OpenApi.IOperation.IParameter = {
|
|
98
|
-
name: props.parameter.field ?? props.parameter.name,
|
|
99
|
-
in: props.parameter.category === "query" ? "query" : "header",
|
|
100
|
-
schema: props.schema,
|
|
101
|
-
...SwaggerDescriptionComposer.compose({
|
|
102
|
-
description:
|
|
103
|
-
props.parameter.description ??
|
|
104
|
-
props.parameter.jsDocTags.find((tag) => tag.name === "description")
|
|
105
|
-
?.text?.[0].text ??
|
|
106
|
-
props.jsDocTags
|
|
107
|
-
.find(
|
|
108
|
-
(tag) =>
|
|
109
|
-
tag.name === "param" &&
|
|
110
|
-
tag.text?.[0].text === props.parameter.name,
|
|
111
|
-
)
|
|
112
|
-
?.text?.map((e) => e.text)
|
|
113
|
-
.join("")
|
|
114
|
-
.substring(props.parameter.name.length) ??
|
|
115
|
-
null,
|
|
116
|
-
jsDocTags: props.jsDocTags,
|
|
117
|
-
kind: "title",
|
|
118
|
-
}),
|
|
119
|
-
required: props.parameter.metadata.isRequired(),
|
|
120
|
-
example: props.parameter.example,
|
|
121
|
-
examples: props.parameter.examples,
|
|
122
|
-
};
|
|
123
|
-
if (
|
|
124
|
-
props.config.decompose === false ||
|
|
125
|
-
props.parameter.metadata.objects.length === 0
|
|
126
|
-
)
|
|
127
|
-
return [param];
|
|
128
|
-
return props.parameter.metadata.objects[0].type.properties
|
|
129
|
-
.filter((p) =>
|
|
130
|
-
p.jsDocTags.every(
|
|
131
|
-
(tag) => tag.name !== "hidden" && tag.name !== "ignore",
|
|
132
|
-
),
|
|
133
|
-
)
|
|
134
|
-
.map((p) => {
|
|
135
|
-
const json: IJsonSchemaCollection = JsonSchemasProgrammer.write({
|
|
136
|
-
version: "3.1",
|
|
137
|
-
metadatas: [p.value],
|
|
138
|
-
}) as IJsonSchemaCollection;
|
|
139
|
-
if (Object.keys(json.components.schemas ?? {}).length !== 0) {
|
|
140
|
-
props.document.components ??= {};
|
|
141
|
-
props.document.components.schemas ??= {};
|
|
142
|
-
Object.assign(
|
|
143
|
-
props.document.components.schemas,
|
|
144
|
-
json.components.schemas,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
name: p.key.constants[0].values[0].value as string,
|
|
149
|
-
in: props.parameter.category === "query" ? "query" : "header",
|
|
150
|
-
schema: json.schemas[0],
|
|
151
|
-
required: p.value.isRequired(),
|
|
152
|
-
...SwaggerDescriptionComposer.compose({
|
|
153
|
-
description: p.description ?? null,
|
|
154
|
-
jsDocTags: p.jsDocTags,
|
|
155
|
-
kind: "title",
|
|
156
|
-
}),
|
|
157
|
-
};
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const warning = new VariadicSingleton((described: boolean): string => {
|
|
163
|
-
const summary = "Request body must be encrypted.";
|
|
164
|
-
const component =
|
|
165
|
-
"[EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody)";
|
|
166
|
-
const content: string[] = [
|
|
167
|
-
"## Warning",
|
|
168
|
-
"",
|
|
169
|
-
summary,
|
|
170
|
-
"",
|
|
171
|
-
`The request body data would be encrypted as "AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding", through the ${component} component.`,
|
|
172
|
-
"",
|
|
173
|
-
`Therefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.`,
|
|
174
|
-
];
|
|
175
|
-
if (described === true) content.push("", "----------------", "", "");
|
|
176
|
-
return content.join("\n");
|
|
177
|
-
});
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
|
2
|
+
import { VariadicSingleton } from "tstl";
|
|
3
|
+
import { IJsDocTagInfo, IJsonSchemaCollection } from "typia";
|
|
4
|
+
import { JsonSchemasProgrammer } from "typia/lib/programmers/json/JsonSchemasProgrammer";
|
|
5
|
+
|
|
6
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
7
|
+
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
8
|
+
import { SwaggerDescriptionComposer } from "./SwaggerDescriptionComposer";
|
|
9
|
+
|
|
10
|
+
export namespace SwaggerOperationParameterComposer {
|
|
11
|
+
export interface IProps<Parameter extends ITypedHttpRouteParameter> {
|
|
12
|
+
config: Omit<INestiaConfig.ISwaggerConfig, "output">;
|
|
13
|
+
document: OpenApi.IDocument;
|
|
14
|
+
schema: OpenApi.IJsonSchema;
|
|
15
|
+
jsDocTags: IJsDocTagInfo[];
|
|
16
|
+
parameter: Parameter;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const compose = (
|
|
20
|
+
props: IProps<ITypedHttpRouteParameter>,
|
|
21
|
+
): OpenApi.IOperation.IParameter[] =>
|
|
22
|
+
props.parameter.category === "body"
|
|
23
|
+
? []
|
|
24
|
+
: props.parameter.category === "param"
|
|
25
|
+
? [path({ ...props, parameter: props.parameter })]
|
|
26
|
+
: props.parameter.category === "query"
|
|
27
|
+
? query({ ...props, parameter: props.parameter })
|
|
28
|
+
: header({ ...props, parameter: props.parameter });
|
|
29
|
+
|
|
30
|
+
export const body = (
|
|
31
|
+
props: Omit<IProps<ITypedHttpRouteParameter.IBody>, "config" | "document">,
|
|
32
|
+
): OpenApi.IOperation.IRequestBody => {
|
|
33
|
+
const description: string | undefined =
|
|
34
|
+
SwaggerDescriptionComposer.descriptionFromJsDocTag({
|
|
35
|
+
jsDocTags: props.jsDocTags,
|
|
36
|
+
tag: "param",
|
|
37
|
+
parameter: props.parameter.name,
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
description: props.parameter.encrypted
|
|
41
|
+
? `${warning.get(!!description)}${description ?? ""}`
|
|
42
|
+
: description,
|
|
43
|
+
content: {
|
|
44
|
+
[props.parameter.contentType]: {
|
|
45
|
+
schema: props.schema,
|
|
46
|
+
example: props.parameter.example,
|
|
47
|
+
examples: props.parameter.examples,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: props.parameter.metadata.isRequired(),
|
|
51
|
+
...(props.parameter.encrypted ? { "x-nestia-encrypted": true } : {}),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const path = (
|
|
56
|
+
props: Omit<IProps<ITypedHttpRouteParameter.IParam>, "config" | "document">,
|
|
57
|
+
): OpenApi.IOperation.IParameter => ({
|
|
58
|
+
name: props.parameter.field,
|
|
59
|
+
in: "path",
|
|
60
|
+
schema: props.schema,
|
|
61
|
+
required: props.parameter.metadata.isRequired(),
|
|
62
|
+
...SwaggerDescriptionComposer.compose({
|
|
63
|
+
description:
|
|
64
|
+
props.parameter.description ??
|
|
65
|
+
props.parameter.jsDocTags.find((tag) => tag.name === "description")
|
|
66
|
+
?.text?.[0].text ??
|
|
67
|
+
props.jsDocTags
|
|
68
|
+
.find(
|
|
69
|
+
(tag) =>
|
|
70
|
+
tag.name === "param" &&
|
|
71
|
+
tag.text?.[0].text === props.parameter.name,
|
|
72
|
+
)
|
|
73
|
+
?.text?.map((e) => e.text)
|
|
74
|
+
.join("")
|
|
75
|
+
.substring(props.parameter.name.length) ??
|
|
76
|
+
null,
|
|
77
|
+
jsDocTags: props.parameter.jsDocTags,
|
|
78
|
+
kind: "title",
|
|
79
|
+
}),
|
|
80
|
+
example: props.parameter.example,
|
|
81
|
+
examples: props.parameter.examples,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const query = (
|
|
85
|
+
props: IProps<ITypedHttpRouteParameter.IQuery>,
|
|
86
|
+
): OpenApi.IOperation.IParameter[] => decomposible(props);
|
|
87
|
+
|
|
88
|
+
export const header = (
|
|
89
|
+
props: IProps<ITypedHttpRouteParameter.IHeaders>,
|
|
90
|
+
): OpenApi.IOperation.IParameter[] => decomposible(props);
|
|
91
|
+
|
|
92
|
+
const decomposible = (
|
|
93
|
+
props: IProps<
|
|
94
|
+
ITypedHttpRouteParameter.IHeaders | ITypedHttpRouteParameter.IQuery
|
|
95
|
+
>,
|
|
96
|
+
): OpenApi.IOperation.IParameter[] => {
|
|
97
|
+
const param: OpenApi.IOperation.IParameter = {
|
|
98
|
+
name: props.parameter.field ?? props.parameter.name,
|
|
99
|
+
in: props.parameter.category === "query" ? "query" : "header",
|
|
100
|
+
schema: props.schema,
|
|
101
|
+
...SwaggerDescriptionComposer.compose({
|
|
102
|
+
description:
|
|
103
|
+
props.parameter.description ??
|
|
104
|
+
props.parameter.jsDocTags.find((tag) => tag.name === "description")
|
|
105
|
+
?.text?.[0].text ??
|
|
106
|
+
props.jsDocTags
|
|
107
|
+
.find(
|
|
108
|
+
(tag) =>
|
|
109
|
+
tag.name === "param" &&
|
|
110
|
+
tag.text?.[0].text === props.parameter.name,
|
|
111
|
+
)
|
|
112
|
+
?.text?.map((e) => e.text)
|
|
113
|
+
.join("")
|
|
114
|
+
.substring(props.parameter.name.length) ??
|
|
115
|
+
null,
|
|
116
|
+
jsDocTags: props.jsDocTags,
|
|
117
|
+
kind: "title",
|
|
118
|
+
}),
|
|
119
|
+
required: props.parameter.metadata.isRequired(),
|
|
120
|
+
example: props.parameter.example,
|
|
121
|
+
examples: props.parameter.examples,
|
|
122
|
+
};
|
|
123
|
+
if (
|
|
124
|
+
props.config.decompose === false ||
|
|
125
|
+
props.parameter.metadata.objects.length === 0
|
|
126
|
+
)
|
|
127
|
+
return [param];
|
|
128
|
+
return props.parameter.metadata.objects[0].type.properties
|
|
129
|
+
.filter((p) =>
|
|
130
|
+
p.jsDocTags.every(
|
|
131
|
+
(tag) => tag.name !== "hidden" && tag.name !== "ignore",
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
.map((p) => {
|
|
135
|
+
const json: IJsonSchemaCollection = JsonSchemasProgrammer.write({
|
|
136
|
+
version: "3.1",
|
|
137
|
+
metadatas: [p.value],
|
|
138
|
+
}) as IJsonSchemaCollection;
|
|
139
|
+
if (Object.keys(json.components.schemas ?? {}).length !== 0) {
|
|
140
|
+
props.document.components ??= {};
|
|
141
|
+
props.document.components.schemas ??= {};
|
|
142
|
+
Object.assign(
|
|
143
|
+
props.document.components.schemas,
|
|
144
|
+
json.components.schemas,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
name: p.key.constants[0].values[0].value as string,
|
|
149
|
+
in: props.parameter.category === "query" ? "query" : "header",
|
|
150
|
+
schema: json.schemas[0],
|
|
151
|
+
required: p.value.isRequired(),
|
|
152
|
+
...SwaggerDescriptionComposer.compose({
|
|
153
|
+
description: p.description ?? null,
|
|
154
|
+
jsDocTags: p.jsDocTags,
|
|
155
|
+
kind: "title",
|
|
156
|
+
}),
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const warning = new VariadicSingleton((described: boolean): string => {
|
|
163
|
+
const summary = "Request body must be encrypted.";
|
|
164
|
+
const component =
|
|
165
|
+
"[EncryptedBody](https://github.com/samchon/@nestia/core#encryptedbody)";
|
|
166
|
+
const content: string[] = [
|
|
167
|
+
"## Warning",
|
|
168
|
+
"",
|
|
169
|
+
summary,
|
|
170
|
+
"",
|
|
171
|
+
`The request body data would be encrypted as "AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding", through the ${component} component.`,
|
|
172
|
+
"",
|
|
173
|
+
`Therefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.`,
|
|
174
|
+
];
|
|
175
|
+
if (described === true) content.push("", "----------------", "", "");
|
|
176
|
+
return content.join("\n");
|
|
177
|
+
});
|