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