@moostjs/swagger 0.3.44 → 0.4.1
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 +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +11 -0
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var moost = require('moost');
|
|
4
4
|
var eventHttp = require('@moostjs/event-http');
|
|
5
5
|
var zod = require('@moostjs/zod');
|
|
6
|
+
var eventHttp$1 = require('@wooksjs/event-http');
|
|
6
7
|
var httpStatic = require('@wooksjs/http-static');
|
|
7
8
|
var Path = require('path');
|
|
8
9
|
var swaggerUiDist = require('swagger-ui-dist');
|
|
@@ -607,7 +608,14 @@ exports.SwaggerController = class SwaggerController {
|
|
|
607
608
|
this.opts = opts;
|
|
608
609
|
this['assetPath'] = swaggerUiDist.getAbsoluteFSPath();
|
|
609
610
|
}
|
|
611
|
+
'processCors'() {
|
|
612
|
+
if (this.opts.cors) {
|
|
613
|
+
const { enableCors } = eventHttp$1.useSetHeaders();
|
|
614
|
+
enableCors(this.opts.cors === true ? undefined : this.opts.cors);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
610
617
|
'serveIndex'(url, location, status) {
|
|
618
|
+
this.processCors();
|
|
611
619
|
if (!url.endsWith('index.html') && !url.endsWith('/')) {
|
|
612
620
|
status.value = 302;
|
|
613
621
|
location.value = Path.join(url, '/');
|
|
@@ -633,6 +641,7 @@ exports.SwaggerController = class SwaggerController {
|
|
|
633
641
|
</html>`;
|
|
634
642
|
}
|
|
635
643
|
'swagger-initializer.js'() {
|
|
644
|
+
this.processCors();
|
|
636
645
|
return `window.onload = function() {
|
|
637
646
|
window.ui = SwaggerUIBundle({
|
|
638
647
|
url: "./spec.json",
|
|
@@ -650,6 +659,7 @@ exports.SwaggerController = class SwaggerController {
|
|
|
650
659
|
};`;
|
|
651
660
|
}
|
|
652
661
|
async 'spec.json'() {
|
|
662
|
+
this.processCors();
|
|
653
663
|
const logger = moost.useEventLogger('@moostjs/zod');
|
|
654
664
|
if (!this.spec) {
|
|
655
665
|
const { instantiate } = moost.useControllerContext();
|
|
@@ -659,6 +669,7 @@ exports.SwaggerController = class SwaggerController {
|
|
|
659
669
|
return this.spec;
|
|
660
670
|
}
|
|
661
671
|
'files'(url) {
|
|
672
|
+
this.processCors();
|
|
662
673
|
return this.serve(url.split('/').pop());
|
|
663
674
|
}
|
|
664
675
|
'serve'(path) {
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface TSwaggerOptions {
|
|
|
11
11
|
title?: string;
|
|
12
12
|
description?: string;
|
|
13
13
|
version?: string;
|
|
14
|
+
cors?: boolean | string;
|
|
14
15
|
}
|
|
15
16
|
interface TSwaggerSchema {
|
|
16
17
|
type?: string;
|
|
@@ -89,6 +90,7 @@ declare class SwaggerController {
|
|
|
89
90
|
protected opts: TSwaggerOptions;
|
|
90
91
|
constructor(opts?: TSwaggerOptions);
|
|
91
92
|
'assetPath': string;
|
|
93
|
+
protected 'processCors'(): void;
|
|
92
94
|
'serveIndex'(url: string, location: THeaderHook, status: TStatusHook): string;
|
|
93
95
|
'swagger-initializer.js'(): string;
|
|
94
96
|
'spec'?: Record<string, unknown>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getMoostMate, Controller, Const, useEventLogger, useControllerContext, Moost } from 'moost';
|
|
2
2
|
import { Get, SetHeader, Url, HeaderHook, StatusHook } from '@moostjs/event-http';
|
|
3
3
|
import { getZodType, z, getZodTypeForProp, ZodSkip } from '@moostjs/zod';
|
|
4
|
+
import { useSetHeaders } from '@wooksjs/event-http';
|
|
4
5
|
import { serveFile } from '@wooksjs/http-static';
|
|
5
6
|
import Path from 'path';
|
|
6
7
|
import { getAbsoluteFSPath } from 'swagger-ui-dist';
|
|
@@ -605,7 +606,14 @@ let SwaggerController = class SwaggerController {
|
|
|
605
606
|
this.opts = opts;
|
|
606
607
|
this['assetPath'] = getAbsoluteFSPath();
|
|
607
608
|
}
|
|
609
|
+
'processCors'() {
|
|
610
|
+
if (this.opts.cors) {
|
|
611
|
+
const { enableCors } = useSetHeaders();
|
|
612
|
+
enableCors(this.opts.cors === true ? undefined : this.opts.cors);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
608
615
|
'serveIndex'(url, location, status) {
|
|
616
|
+
this.processCors();
|
|
609
617
|
if (!url.endsWith('index.html') && !url.endsWith('/')) {
|
|
610
618
|
status.value = 302;
|
|
611
619
|
location.value = Path.join(url, '/');
|
|
@@ -631,6 +639,7 @@ let SwaggerController = class SwaggerController {
|
|
|
631
639
|
</html>`;
|
|
632
640
|
}
|
|
633
641
|
'swagger-initializer.js'() {
|
|
642
|
+
this.processCors();
|
|
634
643
|
return `window.onload = function() {
|
|
635
644
|
window.ui = SwaggerUIBundle({
|
|
636
645
|
url: "./spec.json",
|
|
@@ -648,6 +657,7 @@ let SwaggerController = class SwaggerController {
|
|
|
648
657
|
};`;
|
|
649
658
|
}
|
|
650
659
|
async 'spec.json'() {
|
|
660
|
+
this.processCors();
|
|
651
661
|
const logger = useEventLogger('@moostjs/zod');
|
|
652
662
|
if (!this.spec) {
|
|
653
663
|
const { instantiate } = useControllerContext();
|
|
@@ -657,6 +667,7 @@ let SwaggerController = class SwaggerController {
|
|
|
657
667
|
return this.spec;
|
|
658
668
|
}
|
|
659
669
|
'files'(url) {
|
|
670
|
+
this.processCors();
|
|
660
671
|
return this.serve(url.split('/').pop());
|
|
661
672
|
}
|
|
662
673
|
'serve'(path) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/swagger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "@moostjs/swagger",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/swagger#readme",
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"moost": "0.
|
|
41
|
-
"@moostjs/event-http": "0.
|
|
40
|
+
"moost": "0.4.1",
|
|
41
|
+
"@moostjs/event-http": "0.4.1"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@wooksjs/event-http": "^0.
|
|
44
|
+
"@wooksjs/event-http": "^0.5.1",
|
|
45
45
|
"swagger-ui-dist": "^5.10.5",
|
|
46
46
|
"zod-parser": "^0.0.3",
|
|
47
|
-
"@moostjs/zod": "0.
|
|
48
|
-
"@wooksjs/http-static": "^0.
|
|
47
|
+
"@moostjs/zod": "0.4.1",
|
|
48
|
+
"@wooksjs/http-static": "^0.5.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/swagger-ui-dist": ""
|