nestia 3.0.15 → 3.0.16-dev.20220930
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/IConfiguration.d.ts +110 -110
- package/lib/IConfiguration.js +2 -2
- package/lib/NestiaApplication.d.ts +11 -11
- package/lib/NestiaApplication.js +155 -155
- package/lib/analyses/ControllerAnalyzer.d.ts +6 -6
- package/lib/analyses/ControllerAnalyzer.js +105 -105
- package/lib/analyses/GenericAnalyzer.d.ts +5 -5
- package/lib/analyses/GenericAnalyzer.js +40 -40
- package/lib/analyses/ImportAnalyzer.d.ts +13 -13
- package/lib/analyses/ImportAnalyzer.js +83 -83
- package/lib/analyses/PathAnalyzer.d.ts +5 -5
- package/lib/analyses/PathAnalyzer.js +50 -50
- package/lib/analyses/ReflectAnalyzer.d.ts +4 -4
- package/lib/analyses/ReflectAnalyzer.js +229 -229
- package/lib/analyses/SourceFinder.d.ts +4 -4
- package/lib/analyses/SourceFinder.js +69 -69
- package/lib/executable/internal/CompilerOptions.d.ts +11 -11
- package/lib/executable/internal/CompilerOptions.js +17 -17
- package/lib/executable/internal/NestiaCommand.d.ts +4 -4
- package/lib/executable/internal/NestiaCommand.js +127 -127
- package/lib/executable/internal/NestiaConfig.d.ts +4 -4
- package/lib/executable/internal/NestiaConfig.js +521 -521
- package/lib/executable/internal/nestia.config.getter.d.ts +1 -1
- package/lib/executable/internal/nestia.config.getter.js +23 -23
- package/lib/executable/nestia.d.ts +2 -2
- package/lib/executable/nestia.js +54 -54
- package/lib/generates/FileGenerator.d.ts +5 -5
- package/lib/generates/FileGenerator.js +136 -136
- package/lib/generates/FunctionGenerator.d.ts +5 -5
- package/lib/generates/FunctionGenerator.js +203 -203
- package/lib/generates/SdkGenerator.d.ts +7 -7
- package/lib/generates/SdkGenerator.js +46 -46
- package/lib/generates/SwaggerGenerator.d.ts +6 -6
- package/lib/generates/SwaggerGenerator.js +235 -235
- package/lib/index.d.ts +2 -2
- package/lib/index.js +27 -27
- package/lib/module.d.ts +2 -2
- package/lib/module.js +18 -18
- package/lib/structures/IController.d.ts +23 -23
- package/lib/structures/IController.js +2 -2
- package/lib/structures/IRoute.d.ts +24 -24
- package/lib/structures/IRoute.js +2 -2
- package/lib/structures/ISwagger.d.ts +48 -48
- package/lib/structures/ISwagger.js +2 -2
- package/lib/structures/ITypeTuple.d.ts +5 -5
- package/lib/structures/ITypeTuple.js +2 -2
- package/lib/structures/MethodType.d.ts +4 -4
- package/lib/structures/MethodType.js +13 -13
- package/lib/structures/ParamCategory.d.ts +1 -1
- package/lib/structures/ParamCategory.js +2 -2
- package/lib/structures/TypeEntry.d.ts +9 -9
- package/lib/structures/TypeEntry.js +20 -20
- package/lib/utils/ArrayUtil.d.ts +5 -5
- package/lib/utils/ArrayUtil.js +38 -38
- package/lib/utils/DirectoryUtil.d.ts +5 -5
- package/lib/utils/DirectoryUtil.js +61 -61
- package/lib/utils/ImportDictionary.d.ts +6 -6
- package/lib/utils/ImportDictionary.js +49 -49
- package/lib/utils/MapUtil.d.ts +3 -3
- package/lib/utils/MapUtil.js +15 -15
- package/lib/utils/StripEnums.d.ts +3 -3
- package/lib/utils/StripEnums.js +2 -2
- package/package.json +1 -1
- package/preliminaries/nestia.config.ts +70 -70
|
@@ -1,236 +1,236 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SwaggerGenerator = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const Singleton_1 = require("tstl/thread/Singleton");
|
|
19
|
-
const VariadicSingleton_1 = require("tstl/thread/VariadicSingleton");
|
|
20
|
-
const CommentFactory_1 = require("typescript-json/lib/factories/CommentFactory");
|
|
21
|
-
const ApplicationProgrammer_1 = require("typescript-json/lib/programmers/ApplicationProgrammer");
|
|
22
|
-
const MetadataCollection_1 = require("typescript-json/lib/factories/MetadataCollection");
|
|
23
|
-
const MetadataFactory_1 = require("typescript-json/lib/factories/MetadataFactory");
|
|
24
|
-
const MapUtil_1 = require("../utils/MapUtil");
|
|
25
|
-
var SwaggerGenerator;
|
|
26
|
-
(function (SwaggerGenerator) {
|
|
27
|
-
function generate(checker, config, routeList) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
// PREPARE ASSETS
|
|
30
|
-
const parsed = path_1.default.parse(config.output);
|
|
31
|
-
const location = !!parsed.ext
|
|
32
|
-
? path_1.default.resolve(config.output)
|
|
33
|
-
: path_1.default.join(path_1.default.resolve(config.output), "swagger.json");
|
|
34
|
-
const collection = new MetadataCollection_1.MetadataCollection({
|
|
35
|
-
replace: MetadataCollection_1.MetadataCollection.replace,
|
|
36
|
-
});
|
|
37
|
-
// CONSTRUCT SWAGGER DOCUMENTS
|
|
38
|
-
const tupleList = [];
|
|
39
|
-
const swagger = yield initialize(location);
|
|
40
|
-
const pathDict = new Map();
|
|
41
|
-
for (const route of routeList) {
|
|
42
|
-
const path = MapUtil_1.MapUtil.take(pathDict, get_path(route.path, route.parameters), () => ({}));
|
|
43
|
-
path[route.method.toLowerCase()] = generate_route(checker, collection, tupleList, route);
|
|
44
|
-
}
|
|
45
|
-
swagger.paths = {};
|
|
46
|
-
for (const [path, routes] of pathDict) {
|
|
47
|
-
swagger.paths[path] = routes;
|
|
48
|
-
}
|
|
49
|
-
// FILL JSON-SCHEMAS
|
|
50
|
-
const application = ApplicationProgrammer_1.ApplicationProgrammer.generate(tupleList.map(({ metadata }) => metadata), {
|
|
51
|
-
purpose: "swagger",
|
|
52
|
-
});
|
|
53
|
-
swagger.components = Object.assign(Object.assign({}, (swagger.components || {})), { schemas: application.components.schemas });
|
|
54
|
-
tupleList.forEach(({ schema }, index) => {
|
|
55
|
-
Object.assign(schema, application.schemas[index]);
|
|
56
|
-
});
|
|
57
|
-
// ERASE IJsonComponents.IObject.$id
|
|
58
|
-
for (const obj of Object.values(swagger.components.schemas))
|
|
59
|
-
if (obj.$id)
|
|
60
|
-
delete obj.$id;
|
|
61
|
-
// DO GENERATE
|
|
62
|
-
yield fs_1.default.promises.writeFile(location, JSON.stringify(swagger, null, 2), "utf8");
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
SwaggerGenerator.generate = generate;
|
|
66
|
-
/* ---------------------------------------------------------
|
|
67
|
-
INITIALIZERS
|
|
68
|
-
--------------------------------------------------------- */
|
|
69
|
-
function initialize(path) {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
// LOAD OR CREATE NEW SWAGGER DATA
|
|
72
|
-
const swagger = fs_1.default.existsSync(path)
|
|
73
|
-
? JSON.parse(yield fs_1.default.promises.readFile(path, "utf8"))
|
|
74
|
-
: {
|
|
75
|
-
openapi: "3.0.1",
|
|
76
|
-
servers: [
|
|
77
|
-
{
|
|
78
|
-
url: "https://github.com/samchon/nestia",
|
|
79
|
-
description: "insert your server url",
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
info: {
|
|
83
|
-
version: "0.1.0",
|
|
84
|
-
title: "Generated by nestia - https://github.com/samchon/nestia",
|
|
85
|
-
},
|
|
86
|
-
paths: {},
|
|
87
|
-
components: {},
|
|
88
|
-
};
|
|
89
|
-
// RETURNS
|
|
90
|
-
return swagger;
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
function get_path(path, parameters) {
|
|
94
|
-
const filtered = parameters.filter((param) => param.category === "param" && !!param.field);
|
|
95
|
-
for (const param of filtered)
|
|
96
|
-
path = path.replace(`:${param.field}`, `{${param.field}}`);
|
|
97
|
-
return path;
|
|
98
|
-
}
|
|
99
|
-
function generate_route(checker, collection, tupleList, route) {
|
|
100
|
-
const bodyParam = route.parameters.find((param) => param.category === "body");
|
|
101
|
-
const tags = route.tags
|
|
102
|
-
.filter((tag) => tag.name === "tag" &&
|
|
103
|
-
tag.text &&
|
|
104
|
-
tag.text.find((elem) => elem.kind === "text" && elem.text.length) !== undefined)
|
|
105
|
-
.map((tag) => tag.text.find((elem) => elem.kind === "text").text);
|
|
106
|
-
const encrypted = route.encrypted === true ||
|
|
107
|
-
!!route.parameters.find((param) => param.encrypted === true);
|
|
108
|
-
return {
|
|
109
|
-
tags,
|
|
110
|
-
summary: encrypted ? "encrypted" : undefined,
|
|
111
|
-
parameters: route.parameters
|
|
112
|
-
.filter((param) => param.category !== "body")
|
|
113
|
-
.map((param) => generate_parameter(checker, collection, tupleList, route, param)),
|
|
114
|
-
requestBody: bodyParam
|
|
115
|
-
? generate_request_body(checker, collection, tupleList, route, bodyParam)
|
|
116
|
-
: undefined,
|
|
117
|
-
responses: generate_response_body(checker, collection, tupleList, route),
|
|
118
|
-
description: CommentFactory_1.CommentFactory.generate(route.comments),
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
/* ---------------------------------------------------------
|
|
122
|
-
REQUEST & RESPONSE
|
|
123
|
-
--------------------------------------------------------- */
|
|
124
|
-
function generate_parameter(checker, collection, tupleList, route, parameter) {
|
|
125
|
-
return {
|
|
126
|
-
name: parameter.field || parameter.name,
|
|
127
|
-
in: parameter.category === "param" ? "path" : parameter.category,
|
|
128
|
-
description: get_parametric_description(route, "param", parameter.name) ||
|
|
129
|
-
"",
|
|
130
|
-
schema: generate_schema(checker, collection, tupleList, parameter.type.type),
|
|
131
|
-
required: true,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
function generate_request_body(checker, collection, tupleList, route, parameter) {
|
|
135
|
-
return {
|
|
136
|
-
description: warning.get(parameter.encrypted).get("request") +
|
|
137
|
-
(get_parametric_description(route, "param", parameter.name) ||
|
|
138
|
-
""),
|
|
139
|
-
content: {
|
|
140
|
-
"application/json": {
|
|
141
|
-
schema: generate_schema(checker, collection, tupleList, parameter.type.type),
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
required: true,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function generate_response_body(checker, collection, tupleList, route) {
|
|
148
|
-
// OUTPUT WITH SUCCESS STATUS
|
|
149
|
-
const status = route.method === "GET" || route.method === "DELETE" ? "200" : "201";
|
|
150
|
-
const schema = generate_schema(checker, collection, tupleList, route.output.type);
|
|
151
|
-
const success = {
|
|
152
|
-
[status]: {
|
|
153
|
-
description: warning.get(route.encrypted).get("response", route.method) +
|
|
154
|
-
(get_parametric_description(route, "return") ||
|
|
155
|
-
get_parametric_description(route, "returns") ||
|
|
156
|
-
""),
|
|
157
|
-
content: route.output.name === "void"
|
|
158
|
-
? undefined
|
|
159
|
-
: {
|
|
160
|
-
"application/json": {
|
|
161
|
-
schema,
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
// EXCEPTION STATUSES
|
|
167
|
-
const exceptions = Object.fromEntries(route.tags
|
|
168
|
-
.filter((tag) => tag.name === "throw" &&
|
|
169
|
-
tag.text &&
|
|
170
|
-
tag.text.find((elem) => elem.kind === "text" &&
|
|
171
|
-
isNaN(Number(elem.text
|
|
172
|
-
.split(" ")
|
|
173
|
-
.map((str) => str.trim())[0])) === false) !== undefined)
|
|
174
|
-
.map((tag) => {
|
|
175
|
-
const text = tag.text.find((elem) => elem.kind === "text").text;
|
|
176
|
-
const elements = text
|
|
177
|
-
.split(" ")
|
|
178
|
-
.map((str) => str.trim());
|
|
179
|
-
return [
|
|
180
|
-
elements[0],
|
|
181
|
-
{
|
|
182
|
-
description: elements.slice(1).join(" "),
|
|
183
|
-
},
|
|
184
|
-
];
|
|
185
|
-
}));
|
|
186
|
-
return Object.assign(Object.assign({}, exceptions), success);
|
|
187
|
-
}
|
|
188
|
-
/* ---------------------------------------------------------
|
|
189
|
-
UTILS
|
|
190
|
-
--------------------------------------------------------- */
|
|
191
|
-
function generate_schema(checker, collection, tupleList, type) {
|
|
192
|
-
const metadata = MetadataFactory_1.MetadataFactory.generate(checker, collection, type, {
|
|
193
|
-
resolve: false,
|
|
194
|
-
constant: true,
|
|
195
|
-
});
|
|
196
|
-
const schema = {};
|
|
197
|
-
tupleList.push({ metadata, schema });
|
|
198
|
-
return schema;
|
|
199
|
-
}
|
|
200
|
-
function get_parametric_description(route, tagName, parameterName) {
|
|
201
|
-
var _a;
|
|
202
|
-
const parametric = parameterName
|
|
203
|
-
? (tag) => tag.text.find((elem) => elem.kind === "parameterName" &&
|
|
204
|
-
elem.text === parameterName) !== undefined
|
|
205
|
-
: () => true;
|
|
206
|
-
const tag = route.tags.find((tag) => tag.name === tagName && tag.text && parametric(tag));
|
|
207
|
-
return tag && tag.text
|
|
208
|
-
? (_a = tag.text.find((elem) => elem.kind === "text")) === null || _a === void 0 ? void 0 : _a.text
|
|
209
|
-
: undefined;
|
|
210
|
-
}
|
|
211
|
-
})(SwaggerGenerator = exports.SwaggerGenerator || (exports.SwaggerGenerator = {}));
|
|
212
|
-
const warning = new VariadicSingleton_1.VariadicSingleton((encrypted) => {
|
|
213
|
-
if (encrypted === false)
|
|
214
|
-
return new Singleton_1.Singleton(() => "");
|
|
215
|
-
return new VariadicSingleton_1.VariadicSingleton((type, method) => {
|
|
216
|
-
const summary = type === "request"
|
|
217
|
-
? "Request body must be encrypted."
|
|
218
|
-
: "Response data have been encrypted.";
|
|
219
|
-
const component = type === "request"
|
|
220
|
-
? "[EncryptedBody](https://github.com/samchon/nestia-helper#encryptedbody)"
|
|
221
|
-
: `[EncryptedRoute.${method[0].toUpperCase()}.${method
|
|
222
|
-
.substring(1)
|
|
223
|
-
.toLowerCase()}](https://github.com/samchon/nestia-helper#encryptedroute)`;
|
|
224
|
-
return `## Warning
|
|
225
|
-
${summary}
|
|
226
|
-
|
|
227
|
-
The ${type} body data would be encrypted as "AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding", through the ${component} component.
|
|
228
|
-
|
|
229
|
-
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.
|
|
230
|
-
|
|
231
|
-
-----------------
|
|
232
|
-
|
|
233
|
-
`;
|
|
234
|
-
});
|
|
235
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SwaggerGenerator = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const Singleton_1 = require("tstl/thread/Singleton");
|
|
19
|
+
const VariadicSingleton_1 = require("tstl/thread/VariadicSingleton");
|
|
20
|
+
const CommentFactory_1 = require("typescript-json/lib/factories/CommentFactory");
|
|
21
|
+
const ApplicationProgrammer_1 = require("typescript-json/lib/programmers/ApplicationProgrammer");
|
|
22
|
+
const MetadataCollection_1 = require("typescript-json/lib/factories/MetadataCollection");
|
|
23
|
+
const MetadataFactory_1 = require("typescript-json/lib/factories/MetadataFactory");
|
|
24
|
+
const MapUtil_1 = require("../utils/MapUtil");
|
|
25
|
+
var SwaggerGenerator;
|
|
26
|
+
(function (SwaggerGenerator) {
|
|
27
|
+
function generate(checker, config, routeList) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
// PREPARE ASSETS
|
|
30
|
+
const parsed = path_1.default.parse(config.output);
|
|
31
|
+
const location = !!parsed.ext
|
|
32
|
+
? path_1.default.resolve(config.output)
|
|
33
|
+
: path_1.default.join(path_1.default.resolve(config.output), "swagger.json");
|
|
34
|
+
const collection = new MetadataCollection_1.MetadataCollection({
|
|
35
|
+
replace: MetadataCollection_1.MetadataCollection.replace,
|
|
36
|
+
});
|
|
37
|
+
// CONSTRUCT SWAGGER DOCUMENTS
|
|
38
|
+
const tupleList = [];
|
|
39
|
+
const swagger = yield initialize(location);
|
|
40
|
+
const pathDict = new Map();
|
|
41
|
+
for (const route of routeList) {
|
|
42
|
+
const path = MapUtil_1.MapUtil.take(pathDict, get_path(route.path, route.parameters), () => ({}));
|
|
43
|
+
path[route.method.toLowerCase()] = generate_route(checker, collection, tupleList, route);
|
|
44
|
+
}
|
|
45
|
+
swagger.paths = {};
|
|
46
|
+
for (const [path, routes] of pathDict) {
|
|
47
|
+
swagger.paths[path] = routes;
|
|
48
|
+
}
|
|
49
|
+
// FILL JSON-SCHEMAS
|
|
50
|
+
const application = ApplicationProgrammer_1.ApplicationProgrammer.generate(tupleList.map(({ metadata }) => metadata), {
|
|
51
|
+
purpose: "swagger",
|
|
52
|
+
});
|
|
53
|
+
swagger.components = Object.assign(Object.assign({}, (swagger.components || {})), { schemas: application.components.schemas });
|
|
54
|
+
tupleList.forEach(({ schema }, index) => {
|
|
55
|
+
Object.assign(schema, application.schemas[index]);
|
|
56
|
+
});
|
|
57
|
+
// ERASE IJsonComponents.IObject.$id
|
|
58
|
+
for (const obj of Object.values(swagger.components.schemas))
|
|
59
|
+
if (obj.$id)
|
|
60
|
+
delete obj.$id;
|
|
61
|
+
// DO GENERATE
|
|
62
|
+
yield fs_1.default.promises.writeFile(location, JSON.stringify(swagger, null, 2), "utf8");
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
SwaggerGenerator.generate = generate;
|
|
66
|
+
/* ---------------------------------------------------------
|
|
67
|
+
INITIALIZERS
|
|
68
|
+
--------------------------------------------------------- */
|
|
69
|
+
function initialize(path) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
// LOAD OR CREATE NEW SWAGGER DATA
|
|
72
|
+
const swagger = fs_1.default.existsSync(path)
|
|
73
|
+
? JSON.parse(yield fs_1.default.promises.readFile(path, "utf8"))
|
|
74
|
+
: {
|
|
75
|
+
openapi: "3.0.1",
|
|
76
|
+
servers: [
|
|
77
|
+
{
|
|
78
|
+
url: "https://github.com/samchon/nestia",
|
|
79
|
+
description: "insert your server url",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
info: {
|
|
83
|
+
version: "0.1.0",
|
|
84
|
+
title: "Generated by nestia - https://github.com/samchon/nestia",
|
|
85
|
+
},
|
|
86
|
+
paths: {},
|
|
87
|
+
components: {},
|
|
88
|
+
};
|
|
89
|
+
// RETURNS
|
|
90
|
+
return swagger;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function get_path(path, parameters) {
|
|
94
|
+
const filtered = parameters.filter((param) => param.category === "param" && !!param.field);
|
|
95
|
+
for (const param of filtered)
|
|
96
|
+
path = path.replace(`:${param.field}`, `{${param.field}}`);
|
|
97
|
+
return path;
|
|
98
|
+
}
|
|
99
|
+
function generate_route(checker, collection, tupleList, route) {
|
|
100
|
+
const bodyParam = route.parameters.find((param) => param.category === "body");
|
|
101
|
+
const tags = route.tags
|
|
102
|
+
.filter((tag) => tag.name === "tag" &&
|
|
103
|
+
tag.text &&
|
|
104
|
+
tag.text.find((elem) => elem.kind === "text" && elem.text.length) !== undefined)
|
|
105
|
+
.map((tag) => tag.text.find((elem) => elem.kind === "text").text);
|
|
106
|
+
const encrypted = route.encrypted === true ||
|
|
107
|
+
!!route.parameters.find((param) => param.encrypted === true);
|
|
108
|
+
return {
|
|
109
|
+
tags,
|
|
110
|
+
summary: encrypted ? "encrypted" : undefined,
|
|
111
|
+
parameters: route.parameters
|
|
112
|
+
.filter((param) => param.category !== "body")
|
|
113
|
+
.map((param) => generate_parameter(checker, collection, tupleList, route, param)),
|
|
114
|
+
requestBody: bodyParam
|
|
115
|
+
? generate_request_body(checker, collection, tupleList, route, bodyParam)
|
|
116
|
+
: undefined,
|
|
117
|
+
responses: generate_response_body(checker, collection, tupleList, route),
|
|
118
|
+
description: CommentFactory_1.CommentFactory.generate(route.comments),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/* ---------------------------------------------------------
|
|
122
|
+
REQUEST & RESPONSE
|
|
123
|
+
--------------------------------------------------------- */
|
|
124
|
+
function generate_parameter(checker, collection, tupleList, route, parameter) {
|
|
125
|
+
return {
|
|
126
|
+
name: parameter.field || parameter.name,
|
|
127
|
+
in: parameter.category === "param" ? "path" : parameter.category,
|
|
128
|
+
description: get_parametric_description(route, "param", parameter.name) ||
|
|
129
|
+
"",
|
|
130
|
+
schema: generate_schema(checker, collection, tupleList, parameter.type.type),
|
|
131
|
+
required: true,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function generate_request_body(checker, collection, tupleList, route, parameter) {
|
|
135
|
+
return {
|
|
136
|
+
description: warning.get(parameter.encrypted).get("request") +
|
|
137
|
+
(get_parametric_description(route, "param", parameter.name) ||
|
|
138
|
+
""),
|
|
139
|
+
content: {
|
|
140
|
+
"application/json": {
|
|
141
|
+
schema: generate_schema(checker, collection, tupleList, parameter.type.type),
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
required: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function generate_response_body(checker, collection, tupleList, route) {
|
|
148
|
+
// OUTPUT WITH SUCCESS STATUS
|
|
149
|
+
const status = route.method === "GET" || route.method === "DELETE" ? "200" : "201";
|
|
150
|
+
const schema = generate_schema(checker, collection, tupleList, route.output.type);
|
|
151
|
+
const success = {
|
|
152
|
+
[status]: {
|
|
153
|
+
description: warning.get(route.encrypted).get("response", route.method) +
|
|
154
|
+
(get_parametric_description(route, "return") ||
|
|
155
|
+
get_parametric_description(route, "returns") ||
|
|
156
|
+
""),
|
|
157
|
+
content: route.output.name === "void"
|
|
158
|
+
? undefined
|
|
159
|
+
: {
|
|
160
|
+
"application/json": {
|
|
161
|
+
schema,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
// EXCEPTION STATUSES
|
|
167
|
+
const exceptions = Object.fromEntries(route.tags
|
|
168
|
+
.filter((tag) => tag.name === "throw" &&
|
|
169
|
+
tag.text &&
|
|
170
|
+
tag.text.find((elem) => elem.kind === "text" &&
|
|
171
|
+
isNaN(Number(elem.text
|
|
172
|
+
.split(" ")
|
|
173
|
+
.map((str) => str.trim())[0])) === false) !== undefined)
|
|
174
|
+
.map((tag) => {
|
|
175
|
+
const text = tag.text.find((elem) => elem.kind === "text").text;
|
|
176
|
+
const elements = text
|
|
177
|
+
.split(" ")
|
|
178
|
+
.map((str) => str.trim());
|
|
179
|
+
return [
|
|
180
|
+
elements[0],
|
|
181
|
+
{
|
|
182
|
+
description: elements.slice(1).join(" "),
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
}));
|
|
186
|
+
return Object.assign(Object.assign({}, exceptions), success);
|
|
187
|
+
}
|
|
188
|
+
/* ---------------------------------------------------------
|
|
189
|
+
UTILS
|
|
190
|
+
--------------------------------------------------------- */
|
|
191
|
+
function generate_schema(checker, collection, tupleList, type) {
|
|
192
|
+
const metadata = MetadataFactory_1.MetadataFactory.generate(checker, collection, type, {
|
|
193
|
+
resolve: false,
|
|
194
|
+
constant: true,
|
|
195
|
+
});
|
|
196
|
+
const schema = {};
|
|
197
|
+
tupleList.push({ metadata, schema });
|
|
198
|
+
return schema;
|
|
199
|
+
}
|
|
200
|
+
function get_parametric_description(route, tagName, parameterName) {
|
|
201
|
+
var _a;
|
|
202
|
+
const parametric = parameterName
|
|
203
|
+
? (tag) => tag.text.find((elem) => elem.kind === "parameterName" &&
|
|
204
|
+
elem.text === parameterName) !== undefined
|
|
205
|
+
: () => true;
|
|
206
|
+
const tag = route.tags.find((tag) => tag.name === tagName && tag.text && parametric(tag));
|
|
207
|
+
return tag && tag.text
|
|
208
|
+
? (_a = tag.text.find((elem) => elem.kind === "text")) === null || _a === void 0 ? void 0 : _a.text
|
|
209
|
+
: undefined;
|
|
210
|
+
}
|
|
211
|
+
})(SwaggerGenerator = exports.SwaggerGenerator || (exports.SwaggerGenerator = {}));
|
|
212
|
+
const warning = new VariadicSingleton_1.VariadicSingleton((encrypted) => {
|
|
213
|
+
if (encrypted === false)
|
|
214
|
+
return new Singleton_1.Singleton(() => "");
|
|
215
|
+
return new VariadicSingleton_1.VariadicSingleton((type, method) => {
|
|
216
|
+
const summary = type === "request"
|
|
217
|
+
? "Request body must be encrypted."
|
|
218
|
+
: "Response data have been encrypted.";
|
|
219
|
+
const component = type === "request"
|
|
220
|
+
? "[EncryptedBody](https://github.com/samchon/nestia-helper#encryptedbody)"
|
|
221
|
+
: `[EncryptedRoute.${method[0].toUpperCase()}.${method
|
|
222
|
+
.substring(1)
|
|
223
|
+
.toLowerCase()}](https://github.com/samchon/nestia-helper#encryptedroute)`;
|
|
224
|
+
return `## Warning
|
|
225
|
+
${summary}
|
|
226
|
+
|
|
227
|
+
The ${type} body data would be encrypted as "AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding", through the ${component} component.
|
|
228
|
+
|
|
229
|
+
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.
|
|
230
|
+
|
|
231
|
+
-----------------
|
|
232
|
+
|
|
233
|
+
`;
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
236
|
//# sourceMappingURL=SwaggerGenerator.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as nestia from "./module";
|
|
2
|
-
export default nestia;
|
|
1
|
+
import * as nestia from "./module";
|
|
2
|
+
export default nestia;
|
package/lib/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const nestia = __importStar(require("./module"));
|
|
27
|
-
exports.default = nestia;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const nestia = __importStar(require("./module"));
|
|
27
|
+
exports.default = nestia;
|
|
28
28
|
//# sourceMappingURL=index.js.map
|
package/lib/module.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./IConfiguration";
|
|
2
|
-
export * from "./NestiaApplication";
|
|
1
|
+
export * from "./IConfiguration";
|
|
2
|
+
export * from "./NestiaApplication";
|
package/lib/module.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./IConfiguration"), exports);
|
|
18
|
-
__exportStar(require("./NestiaApplication"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./IConfiguration"), exports);
|
|
18
|
+
__exportStar(require("./NestiaApplication"), exports);
|
|
19
19
|
//# sourceMappingURL=module.js.map
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { ParamCategory } from "./ParamCategory";
|
|
2
|
-
export interface IController {
|
|
3
|
-
file: string;
|
|
4
|
-
name: string;
|
|
5
|
-
paths: string[];
|
|
6
|
-
functions: IController.IFunction[];
|
|
7
|
-
}
|
|
8
|
-
export declare namespace IController {
|
|
9
|
-
interface IFunction {
|
|
10
|
-
name: string;
|
|
11
|
-
method: string;
|
|
12
|
-
paths: string[];
|
|
13
|
-
encrypted: boolean;
|
|
14
|
-
parameters: IParameter[];
|
|
15
|
-
}
|
|
16
|
-
interface IParameter {
|
|
17
|
-
name: string;
|
|
18
|
-
index: number;
|
|
19
|
-
field: string | undefined;
|
|
20
|
-
category: ParamCategory;
|
|
21
|
-
encrypted: boolean;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
import { ParamCategory } from "./ParamCategory";
|
|
2
|
+
export interface IController {
|
|
3
|
+
file: string;
|
|
4
|
+
name: string;
|
|
5
|
+
paths: string[];
|
|
6
|
+
functions: IController.IFunction[];
|
|
7
|
+
}
|
|
8
|
+
export declare namespace IController {
|
|
9
|
+
interface IFunction {
|
|
10
|
+
name: string;
|
|
11
|
+
method: string;
|
|
12
|
+
paths: string[];
|
|
13
|
+
encrypted: boolean;
|
|
14
|
+
parameters: IParameter[];
|
|
15
|
+
}
|
|
16
|
+
interface IParameter {
|
|
17
|
+
name: string;
|
|
18
|
+
index: number;
|
|
19
|
+
field: string | undefined;
|
|
20
|
+
category: ParamCategory;
|
|
21
|
+
encrypted: boolean;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=IController.js.map
|