@moostjs/swagger 0.5.21 → 0.5.22
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 -0
- package/dist/index.cjs +609 -676
- package/dist/index.d.ts +5 -8
- package/dist/index.mjs +568 -663
- package/package.json +15 -10
package/dist/index.cjs
CHANGED
|
@@ -1,627 +1,541 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
//#region rolldown:runtime
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
2
23
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
const moost = __toESM(require("moost"));
|
|
26
|
+
const __moostjs_event_http = __toESM(require("@moostjs/event-http"));
|
|
27
|
+
const __moostjs_zod = __toESM(require("@moostjs/zod"));
|
|
28
|
+
const __wooksjs_event_http = __toESM(require("@wooksjs/event-http"));
|
|
29
|
+
const __wooksjs_http_static = __toESM(require("@wooksjs/http-static"));
|
|
30
|
+
const path = __toESM(require("path"));
|
|
31
|
+
const swagger_ui_dist = __toESM(require("swagger-ui-dist"));
|
|
32
|
+
const zod_parser = __toESM(require("zod-parser"));
|
|
11
33
|
|
|
34
|
+
//#region packages/swagger/src/swagger.mate.ts
|
|
12
35
|
function getSwaggerMate() {
|
|
13
|
-
|
|
36
|
+
return (0, moost.getMoostMate)();
|
|
14
37
|
}
|
|
15
38
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region packages/swagger/src/decorators.ts
|
|
41
|
+
const SwaggerTag = (tag) => getSwaggerMate().decorate("swaggerTags", tag, true);
|
|
42
|
+
const SwaggerExclude = () => getSwaggerMate().decorate("swaggerExclude", true);
|
|
43
|
+
const SwaggerDescription = (descr) => getSwaggerMate().decorate("swaggerDescription", descr);
|
|
19
44
|
function SwaggerResponse(code, opts, example) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
: opt);
|
|
37
|
-
meta.swaggerResponses[keyCode] = meta.swaggerResponses[keyCode] || {};
|
|
38
|
-
meta.swaggerResponses[keyCode][contentType] = { response, example: ex };
|
|
39
|
-
return meta;
|
|
40
|
-
});
|
|
45
|
+
return getSwaggerMate().decorate((meta) => {
|
|
46
|
+
let ex;
|
|
47
|
+
if (example) ex = example;
|
|
48
|
+
if (typeof code !== "number" && opts) ex = opts;
|
|
49
|
+
meta.swaggerResponses = meta.swaggerResponses || {};
|
|
50
|
+
const keyCode = typeof code === "number" ? code : 0;
|
|
51
|
+
const opt = typeof code === "number" ? opts : code;
|
|
52
|
+
const contentType = typeof opt.contentType === "string" ? opt.contentType : "*/*";
|
|
53
|
+
const response = ["object", "function"].includes(typeof opt.response) ? opt.response : opt;
|
|
54
|
+
meta.swaggerResponses[keyCode] = meta.swaggerResponses[keyCode] || {};
|
|
55
|
+
meta.swaggerResponses[keyCode][contentType] = {
|
|
56
|
+
response,
|
|
57
|
+
example: ex
|
|
58
|
+
};
|
|
59
|
+
return meta;
|
|
60
|
+
});
|
|
41
61
|
}
|
|
42
62
|
function SwaggerRequestBody(opt) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
: opt);
|
|
51
|
-
meta.swaggerRequestBody[contentType] = response;
|
|
52
|
-
return meta;
|
|
53
|
-
});
|
|
63
|
+
return getSwaggerMate().decorate((meta) => {
|
|
64
|
+
meta.swaggerRequestBody = meta.swaggerRequestBody || {};
|
|
65
|
+
const contentType = typeof opt.contentType === "string" ? opt.contentType : "application/json";
|
|
66
|
+
const response = typeof opt.contentType === "string" ? opt.response : opt;
|
|
67
|
+
meta.swaggerRequestBody[contentType] = response;
|
|
68
|
+
return meta;
|
|
69
|
+
});
|
|
54
70
|
}
|
|
55
71
|
function SwaggerParam(opts) {
|
|
56
|
-
|
|
72
|
+
return getSwaggerMate().decorate("swaggerParams", opts, true);
|
|
57
73
|
}
|
|
58
74
|
function SwaggerExample(example) {
|
|
59
|
-
|
|
75
|
+
return getSwaggerMate().decorate("swaggerExample", example);
|
|
60
76
|
}
|
|
61
77
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
66
|
-
purpose with or without fee is hereby granted.
|
|
67
|
-
|
|
68
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
69
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
70
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
71
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
72
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
73
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
74
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
75
|
-
***************************************************************************** */
|
|
76
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
function __decorate(decorators, target, key, desc) {
|
|
80
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
81
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
82
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
83
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function __param(paramIndex, decorator) {
|
|
87
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function __metadata(metadataKey, metadataValue) {
|
|
91
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
95
|
-
var e = new Error(message);
|
|
96
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
97
|
-
};
|
|
98
|
-
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region packages/swagger/src/mapping.ts
|
|
99
80
|
function mapToSwaggerSpec(metadata, options, logger) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
additionalMeta: paramMeta,
|
|
303
|
-
}, undefined, logger);
|
|
304
|
-
const parsed = myParseZod(zodType);
|
|
305
|
-
let contentType = '';
|
|
306
|
-
switch (parsed.$type) {
|
|
307
|
-
case 'ZodString':
|
|
308
|
-
case 'ZodNumber':
|
|
309
|
-
case 'ZodBigInt':
|
|
310
|
-
case 'ZodBoolean':
|
|
311
|
-
case 'ZodDate':
|
|
312
|
-
case 'ZodEnum':
|
|
313
|
-
case 'ZodNativeEnum':
|
|
314
|
-
case 'ZodLiteral': {
|
|
315
|
-
contentType = 'text/plan';
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
default: {
|
|
319
|
-
contentType = 'application/json';
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
if (!bodyConfig[contentType]) {
|
|
323
|
-
bodyConfig[contentType] = { schema: getSwaggerSchema(parsed) };
|
|
324
|
-
}
|
|
325
|
-
reqBodyRequired = !zodType.isOptional() && !paramMeta.optional;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (Object.entries(bodyConfig).some(e => !!e[1])) {
|
|
329
|
-
swaggerSpec.paths[handlerPath][handlerMethod].requestBody = {
|
|
330
|
-
content: bodyConfig,
|
|
331
|
-
required: reqBodyRequired,
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return swaggerSpec;
|
|
81
|
+
const swaggerSpec = {
|
|
82
|
+
openapi: "3.0.0",
|
|
83
|
+
info: {
|
|
84
|
+
title: options?.title || "API Documentation",
|
|
85
|
+
version: options?.version || "1.0.0"
|
|
86
|
+
},
|
|
87
|
+
paths: {},
|
|
88
|
+
tags: [],
|
|
89
|
+
components: { schemas: globalSchemas }
|
|
90
|
+
};
|
|
91
|
+
for (const controller of metadata) {
|
|
92
|
+
const cmeta = controller.meta;
|
|
93
|
+
if (cmeta?.swaggerExclude) continue;
|
|
94
|
+
const controllerTags = cmeta?.swaggerTags || [];
|
|
95
|
+
for (const handler of controller.handlers) {
|
|
96
|
+
const hmeta = handler.meta;
|
|
97
|
+
const hh = handler.handler;
|
|
98
|
+
if (hh.type !== "HTTP" || hmeta?.swaggerExclude || handler.registeredAs.length === 0) continue;
|
|
99
|
+
const uniqueParams = {};
|
|
100
|
+
const handlerPath = handler.registeredAs[0].path;
|
|
101
|
+
const handlerMethod = hh.method?.toLowerCase() || "get";
|
|
102
|
+
const handlerDescription = hmeta?.description;
|
|
103
|
+
const handlerTags = [...controllerTags, ...hmeta?.swaggerTags || []];
|
|
104
|
+
if (!swaggerSpec.paths[handlerPath]) swaggerSpec.paths[handlerPath] = {};
|
|
105
|
+
let responses;
|
|
106
|
+
if (hmeta?.swaggerResponses) for (const [code, responseConfigs] of Object.entries(hmeta.swaggerResponses)) {
|
|
107
|
+
const newCode = code === "0" ? getDefaultStatusCode(handlerMethod) : code;
|
|
108
|
+
for (const [contentType, conf] of Object.entries(responseConfigs)) {
|
|
109
|
+
const { response, example } = conf;
|
|
110
|
+
const schema = getSwaggerSchemaFromSwaggerConfigType(response);
|
|
111
|
+
if (schema) {
|
|
112
|
+
responses = responses || {};
|
|
113
|
+
responses[newCode] = { content: { [contentType]: { schema: {
|
|
114
|
+
...schema,
|
|
115
|
+
example: example || schema.example
|
|
116
|
+
} } } };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (hmeta?.returnType) {
|
|
121
|
+
const parsed = myParseZod((0, __moostjs_zod.getZodType)({ type: hmeta.returnType }));
|
|
122
|
+
if ([
|
|
123
|
+
"ZodString",
|
|
124
|
+
"ZodNumber",
|
|
125
|
+
"ZodObject",
|
|
126
|
+
"ZodArray",
|
|
127
|
+
"ZodBoolean"
|
|
128
|
+
].includes(parsed.$type)) {
|
|
129
|
+
const schema = getSwaggerSchema(parsed);
|
|
130
|
+
if (schema) {
|
|
131
|
+
responses = responses || {};
|
|
132
|
+
responses[getDefaultStatusCode(handlerMethod)] = { content: { "*/*": { schema } } };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
let reqBodyRequired = true;
|
|
137
|
+
const bodyConfig = {};
|
|
138
|
+
if (hmeta?.swaggerRequestBody) for (const [contentType, type] of Object.entries(hmeta.swaggerRequestBody)) {
|
|
139
|
+
let zt;
|
|
140
|
+
let schema;
|
|
141
|
+
if (type instanceof __moostjs_zod.z.ZodType) zt = type;
|
|
142
|
+
else if (typeof type === "function") zt = (0, __moostjs_zod.getZodType)({ type });
|
|
143
|
+
if (zt) {
|
|
144
|
+
const parsed = myParseZod(zt);
|
|
145
|
+
if ([
|
|
146
|
+
"ZodString",
|
|
147
|
+
"ZodNumber",
|
|
148
|
+
"ZodObject",
|
|
149
|
+
"ZodArray",
|
|
150
|
+
"ZodBoolean"
|
|
151
|
+
].includes(parsed.$type)) schema = getSwaggerSchema(parsed);
|
|
152
|
+
}
|
|
153
|
+
bodyConfig[contentType] = { schema };
|
|
154
|
+
}
|
|
155
|
+
swaggerSpec.paths[handlerPath][handlerMethod] = {
|
|
156
|
+
summary: handlerDescription,
|
|
157
|
+
operationId: `${handlerMethod.toUpperCase()}_${handlerPath.replace(/\//g, "_").replace(/[{}]/g, "__").replace(/[^\dA-Za-z]/g, "_")}`,
|
|
158
|
+
tags: handlerTags,
|
|
159
|
+
parameters: [],
|
|
160
|
+
responses
|
|
161
|
+
};
|
|
162
|
+
const endpointSpec = swaggerSpec.paths[handlerPath][handlerMethod];
|
|
163
|
+
function addParam(param) {
|
|
164
|
+
const key = `${param.in}//${param.name}`;
|
|
165
|
+
if (uniqueParams[key]) {
|
|
166
|
+
uniqueParams[key].description = param.description ?? uniqueParams[key].description;
|
|
167
|
+
uniqueParams[key].required = param.required;
|
|
168
|
+
uniqueParams[key].schema = param.schema ?? uniqueParams[key].schema;
|
|
169
|
+
} else {
|
|
170
|
+
uniqueParams[key] = param;
|
|
171
|
+
endpointSpec.parameters.push(param);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const param of cmeta?.swaggerParams || []) addParam({
|
|
175
|
+
name: param.name,
|
|
176
|
+
in: param.in,
|
|
177
|
+
description: param.description,
|
|
178
|
+
required: !!param.required,
|
|
179
|
+
schema: getSwaggerSchemaFromSwaggerConfigType(param.type) || { type: "string" }
|
|
180
|
+
});
|
|
181
|
+
for (const param of hmeta?.swaggerParams || []) addParam({
|
|
182
|
+
name: param.name,
|
|
183
|
+
in: param.in,
|
|
184
|
+
description: param.description,
|
|
185
|
+
required: !!param.required,
|
|
186
|
+
schema: getSwaggerSchemaFromSwaggerConfigType(param.type) || { type: "string" }
|
|
187
|
+
});
|
|
188
|
+
for (const paramName of handler.registeredAs[0].args) {
|
|
189
|
+
const paramIndex = handler.meta.params.findIndex((param) => param.paramSource === "ROUTE" && param.paramName === paramName);
|
|
190
|
+
const paramMeta = handler.meta.params[paramIndex];
|
|
191
|
+
let schema;
|
|
192
|
+
let parsed;
|
|
193
|
+
if (paramMeta) {
|
|
194
|
+
const zodType = (0, __moostjs_zod.getZodTypeForProp)({
|
|
195
|
+
type: controller.type,
|
|
196
|
+
key: handler.method,
|
|
197
|
+
index: paramIndex
|
|
198
|
+
}, {
|
|
199
|
+
type: paramMeta.type,
|
|
200
|
+
additionalMeta: paramMeta
|
|
201
|
+
}, undefined, logger);
|
|
202
|
+
parsed = myParseZod(zodType);
|
|
203
|
+
schema = getSwaggerSchema(parsed, true);
|
|
204
|
+
}
|
|
205
|
+
addParam({
|
|
206
|
+
name: paramName,
|
|
207
|
+
in: "path",
|
|
208
|
+
description: paramMeta ? paramMeta.description : undefined,
|
|
209
|
+
required: !paramMeta.optional && !parsed?.$optional,
|
|
210
|
+
schema: schema || { type: "string" }
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
for (let i = 0; i < handler.meta.params.length; i++) {
|
|
214
|
+
const paramMeta = handler.meta.params[i];
|
|
215
|
+
if (paramMeta.paramSource && ["QUERY_ITEM", "QUERY"].includes(paramMeta.paramSource)) {
|
|
216
|
+
const zodType = (0, __moostjs_zod.getZodTypeForProp)({
|
|
217
|
+
type: controller.type,
|
|
218
|
+
key: handler.method,
|
|
219
|
+
index: i
|
|
220
|
+
}, {
|
|
221
|
+
type: paramMeta.type,
|
|
222
|
+
additionalMeta: paramMeta
|
|
223
|
+
}, undefined, logger);
|
|
224
|
+
const parsed = myParseZod(zodType);
|
|
225
|
+
const schema = getSwaggerSchema(parsed, true);
|
|
226
|
+
if (paramMeta.paramSource === "QUERY_ITEM") endpointSpec.parameters.push({
|
|
227
|
+
name: paramMeta.paramName || "",
|
|
228
|
+
in: "query",
|
|
229
|
+
description: paramMeta.description,
|
|
230
|
+
required: !paramMeta.optional && !parsed.$optional,
|
|
231
|
+
schema: schema || { type: "string" }
|
|
232
|
+
});
|
|
233
|
+
else if (paramMeta.paramSource === "QUERY" && parsed.$type === "ZodObject") for (const [key, value] of Object.entries(parsed.$inner)) {
|
|
234
|
+
const schema$1 = getSwaggerSchema(value, true);
|
|
235
|
+
if (schema$1) {
|
|
236
|
+
const swaggerSchema = {
|
|
237
|
+
name: key,
|
|
238
|
+
in: "query",
|
|
239
|
+
description: value.description,
|
|
240
|
+
required: !parsed.$optional && !value.$optional,
|
|
241
|
+
schema: schema$1
|
|
242
|
+
};
|
|
243
|
+
endpointSpec.parameters.push(swaggerSchema);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (paramMeta.paramSource === "BODY") {
|
|
248
|
+
const zodType = (0, __moostjs_zod.getZodTypeForProp)({
|
|
249
|
+
type: controller.type,
|
|
250
|
+
key: handler.method,
|
|
251
|
+
index: i
|
|
252
|
+
}, {
|
|
253
|
+
type: paramMeta.type,
|
|
254
|
+
additionalMeta: paramMeta
|
|
255
|
+
}, undefined, logger);
|
|
256
|
+
const parsed = myParseZod(zodType);
|
|
257
|
+
let contentType = "";
|
|
258
|
+
switch (parsed.$type) {
|
|
259
|
+
case "ZodString":
|
|
260
|
+
case "ZodNumber":
|
|
261
|
+
case "ZodBigInt":
|
|
262
|
+
case "ZodBoolean":
|
|
263
|
+
case "ZodDate":
|
|
264
|
+
case "ZodEnum":
|
|
265
|
+
case "ZodNativeEnum":
|
|
266
|
+
case "ZodLiteral": {
|
|
267
|
+
contentType = "text/plan";
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
default: contentType = "application/json";
|
|
271
|
+
}
|
|
272
|
+
if (!bodyConfig[contentType]) bodyConfig[contentType] = { schema: getSwaggerSchema(parsed) };
|
|
273
|
+
reqBodyRequired = !zodType.isOptional() && !paramMeta.optional;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (bodyConfig && Object.entries(bodyConfig).some((e) => !!e[1])) swaggerSpec.paths[handlerPath][handlerMethod].requestBody = {
|
|
277
|
+
content: bodyConfig,
|
|
278
|
+
required: reqBodyRequired
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return swaggerSpec;
|
|
337
283
|
}
|
|
338
284
|
const globalSchemas = {};
|
|
339
285
|
function getSwaggerSchema(parsed, forParam) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
case 'ZodUnion':
|
|
524
|
-
case 'ZodDiscriminatedUnion': {
|
|
525
|
-
schema.oneOf = parsed.$inner
|
|
526
|
-
.map(t => getSwaggerSchema(t))
|
|
527
|
-
.filter(t => !!t);
|
|
528
|
-
break;
|
|
529
|
-
}
|
|
530
|
-
case 'ZodIntersection': {
|
|
531
|
-
schema.allOf = parsed.$inner
|
|
532
|
-
.map(t => getSwaggerSchema(t))
|
|
533
|
-
.filter(t => !!t);
|
|
534
|
-
break;
|
|
535
|
-
}
|
|
536
|
-
case 'ZodLazy': {
|
|
537
|
-
return getSwaggerSchema(parsed.$get());
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
if (parsed.$nullable) {
|
|
542
|
-
schema.nullable = parsed.$nullable;
|
|
543
|
-
}
|
|
544
|
-
if (parsed.$ref._def.description) {
|
|
545
|
-
schema.description = parsed.$ref._def.description;
|
|
546
|
-
}
|
|
547
|
-
if (parsed.$checks) {
|
|
548
|
-
const checks = parsed.$checks;
|
|
549
|
-
if (parsed.$type === 'ZodString') {
|
|
550
|
-
if (typeof checks.min === 'number') {
|
|
551
|
-
schema.minLength = checks.min;
|
|
552
|
-
}
|
|
553
|
-
if (typeof checks.max === 'number') {
|
|
554
|
-
schema.maxLength = checks.max;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
if (typeof checks.min === 'number') {
|
|
559
|
-
schema.minimum = checks.min;
|
|
560
|
-
}
|
|
561
|
-
if (typeof checks.max === 'number') {
|
|
562
|
-
schema.maximum = checks.max;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
if (!forParam && zodType.__type_ref) {
|
|
567
|
-
return { $ref: `#/components/schemas/${zodType.__type_ref.name}` };
|
|
568
|
-
}
|
|
569
|
-
return schema;
|
|
286
|
+
const zodType = parsed.$ref;
|
|
287
|
+
const meta = zodType.__type_ref ? getSwaggerMate().read(zodType.__type_ref) : undefined;
|
|
288
|
+
if (!forParam && zodType.__type_ref && globalSchemas[zodType.__type_ref.name]) return { $ref: `#/components/schemas/${zodType.__type_ref.name}` };
|
|
289
|
+
if (forParam && zodType.__type_ref && globalSchemas[zodType.__type_ref.name]) return globalSchemas[zodType.__type_ref.name];
|
|
290
|
+
const schema = {};
|
|
291
|
+
if (meta) {
|
|
292
|
+
if (meta.swaggerExample) schema.example = meta.swaggerExample;
|
|
293
|
+
if (meta.label || meta.id) schema.title = meta.label || meta.id;
|
|
294
|
+
if (meta.description) schema.description = meta.description;
|
|
295
|
+
}
|
|
296
|
+
if (!forParam && zodType.__type_ref) globalSchemas[zodType.__type_ref.name] = schema;
|
|
297
|
+
function asString() {
|
|
298
|
+
schema.type = "string";
|
|
299
|
+
if (parsed.$checks) {
|
|
300
|
+
const { regex } = parsed.$checks;
|
|
301
|
+
if (regex) schema.pattern = regex.source;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function asLiteral() {
|
|
305
|
+
if (parsed.$type === "ZodLiteral") {
|
|
306
|
+
schema.type = "string";
|
|
307
|
+
schema.enum = [parsed.$value];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function asEnum() {
|
|
311
|
+
if (parsed.$type === "ZodEnum") {
|
|
312
|
+
schema.type = "string";
|
|
313
|
+
schema.enum = parsed.$value;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function asNativeEnum() {
|
|
317
|
+
if (parsed.$type === "ZodNativeEnum") {
|
|
318
|
+
schema.type = "string";
|
|
319
|
+
schema.enum = Object.keys(parsed.$value);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (forParam) switch (parsed.$type) {
|
|
323
|
+
case "ZodAny":
|
|
324
|
+
case "ZodUnknown":
|
|
325
|
+
case "ZodString": {
|
|
326
|
+
asString();
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
case "ZodNumber": {
|
|
330
|
+
schema.type = "number";
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
case "ZodBigInt": {
|
|
334
|
+
schema.type = "integer";
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
case "ZodBoolean": {
|
|
338
|
+
schema.type = "boolean";
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case "ZodLiteral": {
|
|
342
|
+
asLiteral();
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
case "ZodEnum": {
|
|
346
|
+
asEnum();
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case "ZodNativeEnum": {
|
|
350
|
+
asNativeEnum();
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
case "ZodDate": {
|
|
354
|
+
schema.type = "string";
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
case "ZodNull": {
|
|
358
|
+
schema.type = "null";
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
default: return undefined;
|
|
362
|
+
}
|
|
363
|
+
else switch (parsed.$type) {
|
|
364
|
+
case "ZodString": {
|
|
365
|
+
asString();
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case "ZodNumber": {
|
|
369
|
+
schema.type = "number";
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
case "ZodBigInt": {
|
|
373
|
+
schema.type = "integer";
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case "ZodBoolean": {
|
|
377
|
+
schema.type = "boolean";
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case "ZodLiteral": {
|
|
381
|
+
asLiteral();
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
case "ZodEnum": {
|
|
385
|
+
asEnum();
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
case "ZodNativeEnum": {
|
|
389
|
+
asNativeEnum();
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
case "ZodDate": {
|
|
393
|
+
schema.type = "string";
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
case "ZodNull": {
|
|
397
|
+
schema.type = "null";
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case "ZodFunction":
|
|
401
|
+
case "ZodSymbol":
|
|
402
|
+
case "ZodUndefined":
|
|
403
|
+
case "ZodUnknown":
|
|
404
|
+
case "ZodNever":
|
|
405
|
+
case "ZodVoid":
|
|
406
|
+
case "ZodNaN": return undefined;
|
|
407
|
+
case "ZodArray": {
|
|
408
|
+
schema.type = "array";
|
|
409
|
+
schema.minItems = parsed.$checks?.minLength || undefined;
|
|
410
|
+
schema.maxItems = parsed.$checks?.maxLength || undefined;
|
|
411
|
+
schema.items = getSwaggerSchema(parsed.$inner);
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
case "ZodTuple": {
|
|
415
|
+
schema.type = "array";
|
|
416
|
+
schema.items = parsed.$inner.map((t) => getSwaggerSchema(t)).filter((t) => !!t);
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
case "ZodObject": {
|
|
420
|
+
schema.type = "object";
|
|
421
|
+
schema.properties = {};
|
|
422
|
+
schema.required = [];
|
|
423
|
+
if (zodType._def.unknownKeys === "passthrough") schema.additionalProperties = {};
|
|
424
|
+
for (const [key, val] of Object.entries(parsed.$inner)) {
|
|
425
|
+
const prop = getSwaggerSchema(val);
|
|
426
|
+
if (prop) {
|
|
427
|
+
schema.properties[key] = prop;
|
|
428
|
+
if (!val.$optional) schema.required.push(key);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
case "ZodPromise":
|
|
434
|
+
case "ZodRecord":
|
|
435
|
+
case "ZodMap":
|
|
436
|
+
case "ZodSet": {
|
|
437
|
+
schema.type = "object";
|
|
438
|
+
schema.properties = {};
|
|
439
|
+
schema.additionalProperties = parsed.$type === "ZodRecord" ? {} : undefined;
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
case "ZodUnion":
|
|
443
|
+
case "ZodDiscriminatedUnion": {
|
|
444
|
+
schema.oneOf = parsed.$inner.map((t) => getSwaggerSchema(t)).filter((t) => !!t);
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
case "ZodIntersection": {
|
|
448
|
+
schema.allOf = parsed.$inner.map((t) => getSwaggerSchema(t)).filter((t) => !!t);
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
case "ZodLazy": return getSwaggerSchema(parsed.$get());
|
|
452
|
+
}
|
|
453
|
+
if (parsed.$nullable) schema.nullable = parsed.$nullable;
|
|
454
|
+
if (parsed.$ref._def.description) schema.description = parsed.$ref._def.description;
|
|
455
|
+
if (parsed.$checks) {
|
|
456
|
+
const checks = parsed.$checks;
|
|
457
|
+
if (parsed.$type === "ZodString") {
|
|
458
|
+
if (typeof checks.min === "number") schema.minLength = checks.min;
|
|
459
|
+
if (typeof checks.max === "number") schema.maxLength = checks.max;
|
|
460
|
+
} else {
|
|
461
|
+
if (typeof checks.min === "number") schema.minimum = checks.min;
|
|
462
|
+
if (typeof checks.max === "number") schema.maximum = checks.max;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (!forParam && zodType.__type_ref) return { $ref: `#/components/schemas/${zodType.__type_ref.name}` };
|
|
466
|
+
return schema;
|
|
570
467
|
}
|
|
571
468
|
function myParseZod(schema) {
|
|
572
|
-
|
|
469
|
+
return (0, zod_parser.parseZodType)(schema);
|
|
573
470
|
}
|
|
574
471
|
function getDefaultStatusCode(httpMethod) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
472
|
+
const defaultStatusCodes = {
|
|
473
|
+
GET: 200,
|
|
474
|
+
PUT: 200,
|
|
475
|
+
POST: 201,
|
|
476
|
+
DELETE: 204
|
|
477
|
+
};
|
|
478
|
+
return defaultStatusCodes[httpMethod.toUpperCase()] || 200;
|
|
582
479
|
}
|
|
583
480
|
function getSwaggerSchemaFromSwaggerConfigType(type) {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
else if (type.type || type.$ref) {
|
|
601
|
-
schema = type;
|
|
602
|
-
}
|
|
603
|
-
return schema;
|
|
481
|
+
let schema;
|
|
482
|
+
let zt;
|
|
483
|
+
if (type instanceof __moostjs_zod.z.ZodType) zt = type;
|
|
484
|
+
else if (typeof type === "function") zt = (0, __moostjs_zod.getZodType)({ type });
|
|
485
|
+
if (zt) {
|
|
486
|
+
const parsed = myParseZod(zt);
|
|
487
|
+
if ([
|
|
488
|
+
"ZodString",
|
|
489
|
+
"ZodNumber",
|
|
490
|
+
"ZodObject",
|
|
491
|
+
"ZodArray",
|
|
492
|
+
"ZodBoolean"
|
|
493
|
+
].includes(parsed.$type)) schema = getSwaggerSchema(parsed);
|
|
494
|
+
} else if (type.type || type.$ref) schema = type;
|
|
495
|
+
return schema;
|
|
604
496
|
}
|
|
605
497
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region packages/swagger/src/swagger.controller.ts
|
|
500
|
+
function _define_property(obj, key, value) {
|
|
501
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
502
|
+
value,
|
|
503
|
+
enumerable: true,
|
|
504
|
+
configurable: true,
|
|
505
|
+
writable: true
|
|
506
|
+
});
|
|
507
|
+
else obj[key] = value;
|
|
508
|
+
return obj;
|
|
509
|
+
}
|
|
510
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
511
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
512
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
513
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
514
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
515
|
+
}
|
|
516
|
+
function _ts_metadata(k, v) {
|
|
517
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
518
|
+
}
|
|
519
|
+
function _ts_param(paramIndex, decorator) {
|
|
520
|
+
return function(target, key) {
|
|
521
|
+
decorator(target, key, paramIndex);
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
var SwaggerController = class {
|
|
525
|
+
"processCors"() {
|
|
526
|
+
if (this.opts.cors) {
|
|
527
|
+
const { enableCors } = (0, __wooksjs_event_http.useSetHeaders)();
|
|
528
|
+
enableCors(this.opts.cors === true ? undefined : this.opts.cors);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
"serveIndex"(url, location, status) {
|
|
532
|
+
this.processCors();
|
|
533
|
+
if (!url.endsWith("index.html") && !url.endsWith("/")) {
|
|
534
|
+
status.value = 302;
|
|
535
|
+
location.value = path.default.join(url, "/");
|
|
536
|
+
return "";
|
|
537
|
+
}
|
|
538
|
+
return `<!DOCTYPE html>
|
|
625
539
|
<html lang="en">
|
|
626
540
|
<head>
|
|
627
541
|
<meta charset="UTF-8">
|
|
@@ -639,10 +553,10 @@ exports.SwaggerController = class SwaggerController {
|
|
|
639
553
|
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
|
|
640
554
|
</body>
|
|
641
555
|
</html>`;
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
556
|
+
}
|
|
557
|
+
"swagger-initializer.js"() {
|
|
558
|
+
this.processCors();
|
|
559
|
+
return `window.onload = function() {
|
|
646
560
|
window.ui = SwaggerUIBundle({
|
|
647
561
|
url: "./spec.json",
|
|
648
562
|
dom_id: '#swagger-ui',
|
|
@@ -657,79 +571,98 @@ exports.SwaggerController = class SwaggerController {
|
|
|
657
571
|
layout: "BaseLayout"
|
|
658
572
|
});
|
|
659
573
|
};`;
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
574
|
+
}
|
|
575
|
+
async "spec.json"() {
|
|
576
|
+
this.processCors();
|
|
577
|
+
const logger = (0, moost.useEventLogger)("@moostjs/zod");
|
|
578
|
+
if (!this.spec) {
|
|
579
|
+
const { instantiate } = (0, moost.useControllerContext)();
|
|
580
|
+
const moost$1 = await instantiate(moost.Moost);
|
|
581
|
+
this.spec = mapToSwaggerSpec(moost$1.getControllersOverview(), this.opts, logger);
|
|
582
|
+
}
|
|
583
|
+
return this.spec;
|
|
584
|
+
}
|
|
585
|
+
"files"(url) {
|
|
586
|
+
this.processCors();
|
|
587
|
+
return this.serve(url.split("/").pop());
|
|
588
|
+
}
|
|
589
|
+
"serve"(path$1) {
|
|
590
|
+
return (0, __wooksjs_http_static.serveFile)(path$1, {
|
|
591
|
+
baseDir: this.assetPath,
|
|
592
|
+
cacheControl: {
|
|
593
|
+
public: true,
|
|
594
|
+
maxAge: "1w"
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
constructor(opts = { title: "Moost API" }) {
|
|
599
|
+
_define_property(this, "opts", void 0);
|
|
600
|
+
_define_property(this, "assetPath", void 0);
|
|
601
|
+
_define_property(this, "spec", void 0);
|
|
602
|
+
this.opts = opts;
|
|
603
|
+
this["assetPath"] = (0, swagger_ui_dist.getAbsoluteFSPath)();
|
|
604
|
+
}
|
|
684
605
|
};
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
606
|
+
_ts_decorate([
|
|
607
|
+
(0, __moostjs_event_http.Get)(""),
|
|
608
|
+
(0, __moostjs_event_http.Get)("//"),
|
|
609
|
+
(0, __moostjs_event_http.Get)("index.html"),
|
|
610
|
+
(0, __moostjs_event_http.SetHeader)("content-type", "text/html"),
|
|
611
|
+
_ts_param(0, (0, __moostjs_event_http.Url)()),
|
|
612
|
+
_ts_param(1, (0, __moostjs_event_http.HeaderHook)("location")),
|
|
613
|
+
_ts_param(2, (0, __moostjs_event_http.StatusHook)()),
|
|
614
|
+
_ts_metadata("design:type", Function),
|
|
615
|
+
_ts_metadata("design:paramtypes", [
|
|
616
|
+
String,
|
|
617
|
+
typeof __wooksjs_event_http.THeaderHook === "undefined" ? Object : __wooksjs_event_http.THeaderHook,
|
|
618
|
+
typeof TStatusHook === "undefined" ? Object : TStatusHook
|
|
619
|
+
]),
|
|
620
|
+
_ts_metadata("design:returntype", void 0)
|
|
621
|
+
], SwaggerController.prototype, "serveIndex", null);
|
|
622
|
+
_ts_decorate([
|
|
623
|
+
(0, __moostjs_event_http.Get)(),
|
|
624
|
+
(0, __moostjs_event_http.SetHeader)("content-type", "application/javascript"),
|
|
625
|
+
_ts_metadata("design:type", Function),
|
|
626
|
+
_ts_metadata("design:paramtypes", []),
|
|
627
|
+
_ts_metadata("design:returntype", void 0)
|
|
628
|
+
], SwaggerController.prototype, "swagger-initializer.js", null);
|
|
629
|
+
_ts_decorate([
|
|
630
|
+
(0, __moostjs_event_http.Get)(),
|
|
631
|
+
_ts_metadata("design:type", Function),
|
|
632
|
+
_ts_metadata("design:paramtypes", []),
|
|
633
|
+
_ts_metadata("design:returntype", Promise)
|
|
634
|
+
], SwaggerController.prototype, "spec.json", null);
|
|
635
|
+
_ts_decorate([
|
|
636
|
+
(0, __moostjs_event_http.Get)("swagger-ui-bundle.*(js|js\\.map)"),
|
|
637
|
+
(0, __moostjs_event_http.Get)("swagger-ui-standalone-preset.*(js|js\\.map)"),
|
|
638
|
+
(0, __moostjs_event_http.Get)("swagger-ui.*(css|css\\.map)"),
|
|
639
|
+
(0, __moostjs_event_http.Get)("index.*(css|css\\.map)"),
|
|
640
|
+
_ts_param(0, (0, __moostjs_event_http.Url)()),
|
|
641
|
+
_ts_metadata("design:type", Function),
|
|
642
|
+
_ts_metadata("design:paramtypes", [String]),
|
|
643
|
+
_ts_metadata("design:returntype", void 0)
|
|
644
|
+
], SwaggerController.prototype, "files", null);
|
|
645
|
+
SwaggerController = _ts_decorate([
|
|
646
|
+
SwaggerExclude(),
|
|
647
|
+
(0, __moostjs_zod.ZodSkip)(),
|
|
648
|
+
(0, moost.Controller)("api-docs"),
|
|
649
|
+
_ts_param(0, (0, moost.Const)({ title: "Moost API" })),
|
|
650
|
+
_ts_metadata("design:type", Function),
|
|
651
|
+
_ts_metadata("design:paramtypes", [typeof TSwaggerOptions === "undefined" ? Object : TSwaggerOptions])
|
|
652
|
+
], SwaggerController);
|
|
727
653
|
|
|
728
|
-
|
|
729
|
-
exports
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
exports.
|
|
654
|
+
//#endregion
|
|
655
|
+
Object.defineProperty(exports, 'SwaggerController', {
|
|
656
|
+
enumerable: true,
|
|
657
|
+
get: function () {
|
|
658
|
+
return SwaggerController;
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
exports.SwaggerDescription = SwaggerDescription
|
|
662
|
+
exports.SwaggerExample = SwaggerExample
|
|
663
|
+
exports.SwaggerExclude = SwaggerExclude
|
|
664
|
+
exports.SwaggerParam = SwaggerParam
|
|
665
|
+
exports.SwaggerRequestBody = SwaggerRequestBody
|
|
666
|
+
exports.SwaggerResponse = SwaggerResponse
|
|
667
|
+
exports.SwaggerTag = SwaggerTag
|
|
668
|
+
exports.getSwaggerMate = getSwaggerMate
|