@moostjs/swagger 0.3.43 → 0.3.44
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/dist/index.cjs +29 -7
- package/dist/index.d.ts +7 -2
- package/dist/index.mjs +29 -7
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -120,6 +120,7 @@ function mapToSwaggerSpec(metadata, options, logger) {
|
|
|
120
120
|
if (hh.type !== 'HTTP' || hmeta?.swaggerExclude || handler.registeredAs.length === 0) {
|
|
121
121
|
continue;
|
|
122
122
|
}
|
|
123
|
+
const uniqueParams = {};
|
|
123
124
|
const handlerPath = handler.registeredAs[0].path;
|
|
124
125
|
const handlerMethod = hh.method?.toLowerCase() || 'get';
|
|
125
126
|
const handlerDescription = hmeta?.description;
|
|
@@ -197,8 +198,29 @@ function mapToSwaggerSpec(metadata, options, logger) {
|
|
|
197
198
|
responses,
|
|
198
199
|
};
|
|
199
200
|
const endpointSpec = swaggerSpec.paths[handlerPath][handlerMethod];
|
|
201
|
+
function addParam(param) {
|
|
202
|
+
const key = `${param.in}//${param.name}`;
|
|
203
|
+
if (uniqueParams[key]) {
|
|
204
|
+
uniqueParams[key].description = param.description ?? uniqueParams[key].description;
|
|
205
|
+
uniqueParams[key].required = param.required;
|
|
206
|
+
uniqueParams[key].schema = param.schema ?? uniqueParams[key].schema;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
uniqueParams[key] = param;
|
|
210
|
+
endpointSpec.parameters.push(param);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const param of cmeta?.swaggerParams || []) {
|
|
214
|
+
addParam({
|
|
215
|
+
name: param.name,
|
|
216
|
+
in: param.in,
|
|
217
|
+
description: param.description,
|
|
218
|
+
required: !!param.required,
|
|
219
|
+
schema: getSwaggerSchemaFromSwaggerConfigType(param.type) || { type: 'string' },
|
|
220
|
+
});
|
|
221
|
+
}
|
|
200
222
|
for (const param of hmeta?.swaggerParams || []) {
|
|
201
|
-
|
|
223
|
+
addParam({
|
|
202
224
|
name: param.name,
|
|
203
225
|
in: param.in,
|
|
204
226
|
description: param.description,
|
|
@@ -223,7 +245,7 @@ function mapToSwaggerSpec(metadata, options, logger) {
|
|
|
223
245
|
parsed = myParseZod(zodType);
|
|
224
246
|
schema = getSwaggerSchema(parsed, true);
|
|
225
247
|
}
|
|
226
|
-
|
|
248
|
+
addParam({
|
|
227
249
|
name: paramName,
|
|
228
250
|
in: 'path',
|
|
229
251
|
description: paramMeta ? paramMeta.description : undefined,
|
|
@@ -581,8 +603,8 @@ function getSwaggerSchemaFromSwaggerConfigType(type) {
|
|
|
581
603
|
}
|
|
582
604
|
|
|
583
605
|
exports.SwaggerController = class SwaggerController {
|
|
584
|
-
constructor(
|
|
585
|
-
this.
|
|
606
|
+
constructor(opts = { title: 'Moost API' }) {
|
|
607
|
+
this.opts = opts;
|
|
586
608
|
this['assetPath'] = swaggerUiDist.getAbsoluteFSPath();
|
|
587
609
|
}
|
|
588
610
|
'serveIndex'(url, location, status) {
|
|
@@ -595,7 +617,7 @@ exports.SwaggerController = class SwaggerController {
|
|
|
595
617
|
<html lang="en">
|
|
596
618
|
<head>
|
|
597
619
|
<meta charset="UTF-8">
|
|
598
|
-
<title>${this.title}</title>
|
|
620
|
+
<title>${this.opts.title}</title>
|
|
599
621
|
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
|
|
600
622
|
<link rel="stylesheet" type="text/css" href="index.css" />
|
|
601
623
|
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
|
@@ -632,7 +654,7 @@ exports.SwaggerController = class SwaggerController {
|
|
|
632
654
|
if (!this.spec) {
|
|
633
655
|
const { instantiate } = moost.useControllerContext();
|
|
634
656
|
const moost$1 = await instantiate(moost.Moost);
|
|
635
|
-
this.spec = mapToSwaggerSpec(moost$1.getControllersOverview(),
|
|
657
|
+
this.spec = mapToSwaggerSpec(moost$1.getControllersOverview(), this.opts, logger);
|
|
636
658
|
}
|
|
637
659
|
return this.spec;
|
|
638
660
|
}
|
|
@@ -688,7 +710,7 @@ exports.SwaggerController = __decorate([
|
|
|
688
710
|
SwaggerExclude(),
|
|
689
711
|
zod.ZodSkip(),
|
|
690
712
|
moost.Controller('api-docs'),
|
|
691
|
-
__param(0, moost.Const('Moost API')),
|
|
713
|
+
__param(0, moost.Const({ title: 'Moost API' })),
|
|
692
714
|
__metadata("design:paramtypes", [Object])
|
|
693
715
|
], exports.SwaggerController);
|
|
694
716
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ type TFunction = Function;
|
|
|
7
7
|
interface TEmpty {
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
interface TSwaggerOptions {
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
version?: string;
|
|
14
|
+
}
|
|
10
15
|
interface TSwaggerSchema {
|
|
11
16
|
type?: string;
|
|
12
17
|
$ref?: string;
|
|
@@ -81,8 +86,8 @@ declare function SwaggerParam(opts: TSwaggerMate['swaggerParams'][number]): Meth
|
|
|
81
86
|
declare function SwaggerExample(example: unknown): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
82
87
|
|
|
83
88
|
declare class SwaggerController {
|
|
84
|
-
protected
|
|
85
|
-
constructor(
|
|
89
|
+
protected opts: TSwaggerOptions;
|
|
90
|
+
constructor(opts?: TSwaggerOptions);
|
|
86
91
|
'assetPath': string;
|
|
87
92
|
'serveIndex'(url: string, location: THeaderHook, status: TStatusHook): string;
|
|
88
93
|
'swagger-initializer.js'(): string;
|
package/dist/index.mjs
CHANGED
|
@@ -118,6 +118,7 @@ function mapToSwaggerSpec(metadata, options, logger) {
|
|
|
118
118
|
if (hh.type !== 'HTTP' || hmeta?.swaggerExclude || handler.registeredAs.length === 0) {
|
|
119
119
|
continue;
|
|
120
120
|
}
|
|
121
|
+
const uniqueParams = {};
|
|
121
122
|
const handlerPath = handler.registeredAs[0].path;
|
|
122
123
|
const handlerMethod = hh.method?.toLowerCase() || 'get';
|
|
123
124
|
const handlerDescription = hmeta?.description;
|
|
@@ -195,8 +196,29 @@ function mapToSwaggerSpec(metadata, options, logger) {
|
|
|
195
196
|
responses,
|
|
196
197
|
};
|
|
197
198
|
const endpointSpec = swaggerSpec.paths[handlerPath][handlerMethod];
|
|
199
|
+
function addParam(param) {
|
|
200
|
+
const key = `${param.in}//${param.name}`;
|
|
201
|
+
if (uniqueParams[key]) {
|
|
202
|
+
uniqueParams[key].description = param.description ?? uniqueParams[key].description;
|
|
203
|
+
uniqueParams[key].required = param.required;
|
|
204
|
+
uniqueParams[key].schema = param.schema ?? uniqueParams[key].schema;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
uniqueParams[key] = param;
|
|
208
|
+
endpointSpec.parameters.push(param);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (const param of cmeta?.swaggerParams || []) {
|
|
212
|
+
addParam({
|
|
213
|
+
name: param.name,
|
|
214
|
+
in: param.in,
|
|
215
|
+
description: param.description,
|
|
216
|
+
required: !!param.required,
|
|
217
|
+
schema: getSwaggerSchemaFromSwaggerConfigType(param.type) || { type: 'string' },
|
|
218
|
+
});
|
|
219
|
+
}
|
|
198
220
|
for (const param of hmeta?.swaggerParams || []) {
|
|
199
|
-
|
|
221
|
+
addParam({
|
|
200
222
|
name: param.name,
|
|
201
223
|
in: param.in,
|
|
202
224
|
description: param.description,
|
|
@@ -221,7 +243,7 @@ function mapToSwaggerSpec(metadata, options, logger) {
|
|
|
221
243
|
parsed = myParseZod(zodType);
|
|
222
244
|
schema = getSwaggerSchema(parsed, true);
|
|
223
245
|
}
|
|
224
|
-
|
|
246
|
+
addParam({
|
|
225
247
|
name: paramName,
|
|
226
248
|
in: 'path',
|
|
227
249
|
description: paramMeta ? paramMeta.description : undefined,
|
|
@@ -579,8 +601,8 @@ function getSwaggerSchemaFromSwaggerConfigType(type) {
|
|
|
579
601
|
}
|
|
580
602
|
|
|
581
603
|
let SwaggerController = class SwaggerController {
|
|
582
|
-
constructor(
|
|
583
|
-
this.
|
|
604
|
+
constructor(opts = { title: 'Moost API' }) {
|
|
605
|
+
this.opts = opts;
|
|
584
606
|
this['assetPath'] = getAbsoluteFSPath();
|
|
585
607
|
}
|
|
586
608
|
'serveIndex'(url, location, status) {
|
|
@@ -593,7 +615,7 @@ let SwaggerController = class SwaggerController {
|
|
|
593
615
|
<html lang="en">
|
|
594
616
|
<head>
|
|
595
617
|
<meta charset="UTF-8">
|
|
596
|
-
<title>${this.title}</title>
|
|
618
|
+
<title>${this.opts.title}</title>
|
|
597
619
|
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
|
|
598
620
|
<link rel="stylesheet" type="text/css" href="index.css" />
|
|
599
621
|
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
|
@@ -630,7 +652,7 @@ let SwaggerController = class SwaggerController {
|
|
|
630
652
|
if (!this.spec) {
|
|
631
653
|
const { instantiate } = useControllerContext();
|
|
632
654
|
const moost = await instantiate(Moost);
|
|
633
|
-
this.spec = mapToSwaggerSpec(moost.getControllersOverview(),
|
|
655
|
+
this.spec = mapToSwaggerSpec(moost.getControllersOverview(), this.opts, logger);
|
|
634
656
|
}
|
|
635
657
|
return this.spec;
|
|
636
658
|
}
|
|
@@ -686,7 +708,7 @@ SwaggerController = __decorate([
|
|
|
686
708
|
SwaggerExclude(),
|
|
687
709
|
ZodSkip(),
|
|
688
710
|
Controller('api-docs'),
|
|
689
|
-
__param(0, Const('Moost API')),
|
|
711
|
+
__param(0, Const({ title: 'Moost API' })),
|
|
690
712
|
__metadata("design:paramtypes", [Object])
|
|
691
713
|
], SwaggerController);
|
|
692
714
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/swagger",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.44",
|
|
4
4
|
"description": "@moostjs/swagger",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/swagger#readme",
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"moost": "0.3.
|
|
41
|
-
"@moostjs/event-http": "0.3.
|
|
40
|
+
"moost": "0.3.44",
|
|
41
|
+
"@moostjs/event-http": "0.3.44"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@wooksjs/event-http": "^0.4.35",
|
|
45
45
|
"swagger-ui-dist": "^5.10.5",
|
|
46
46
|
"zod-parser": "^0.0.3",
|
|
47
|
-
"@moostjs/zod": "0.3.
|
|
47
|
+
"@moostjs/zod": "0.3.44",
|
|
48
48
|
"@wooksjs/http-static": "^0.4.35"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|