@tsed/openapi-utils 8.11.1 → 8.12.0-rc.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/lib/esm/decorators/docs.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/interfaces/OpenApiSettings.js +0 -1
- package/lib/esm/middlewares/cssMiddleware.js +0 -1
- package/lib/esm/middlewares/jsMiddleware.js +0 -1
- package/lib/esm/middlewares/openApiMiddleware.js +0 -1
- package/lib/esm/middlewares/redirectMiddleware.js +0 -1
- package/lib/esm/services/OpenAPIBaseModule.js +0 -1
- package/lib/esm/services/OpenAPIService.js +0 -1
- package/lib/esm/utils/includeRoute.js +0 -1
- package/lib/esm/utils/matchPath.js +0 -1
- package/lib/esm/utils/readSpec.js +0 -1
- package/package.json +14 -11
- package/lib/esm/decorators/docs.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/interfaces/OpenApiSettings.js.map +0 -1
- package/lib/esm/middlewares/cssMiddleware.js.map +0 -1
- package/lib/esm/middlewares/jsMiddleware.js.map +0 -1
- package/lib/esm/middlewares/openApiMiddleware.js.map +0 -1
- package/lib/esm/middlewares/redirectMiddleware.js.map +0 -1
- package/lib/esm/services/OpenAPIBaseModule.js.map +0 -1
- package/lib/esm/services/OpenAPIService.js.map +0 -1
- package/lib/esm/utils/includeRoute.js.map +0 -1
- package/lib/esm/utils/matchPath.js.map +0 -1
- package/lib/esm/utils/readSpec.js.map +0 -1
- package/src/decorators/docs.ts +0 -14
- package/src/index.ts +0 -14
- package/src/interfaces/OpenApiSettings.ts +0 -98
- package/src/middlewares/cssMiddleware.spec.ts +0 -26
- package/src/middlewares/cssMiddleware.ts +0 -23
- package/src/middlewares/jsMiddleware.spec.ts +0 -26
- package/src/middlewares/jsMiddleware.ts +0 -17
- package/src/middlewares/openApiMiddleware.spec.ts +0 -32
- package/src/middlewares/openApiMiddleware.ts +0 -16
- package/src/middlewares/redirectMiddleware.spec.ts +0 -32
- package/src/middlewares/redirectMiddleware.ts +0 -15
- package/src/services/OpenAPIBaseModule.ts +0 -91
- package/src/services/OpenAPIService.spec.ts +0 -35
- package/src/services/OpenAPIService.ts +0 -68
- package/src/services/__snapshots__/OpenAPIService.spec.ts.snap +0 -11
- package/src/services/__snapshots__/SwaggerService.spec.ts.snap +0 -11
- package/src/utils/includeRoute.spec.ts +0 -111
- package/src/utils/includeRoute.ts +0 -22
- package/src/utils/matchPath.ts +0 -5
- package/src/utils/readSpec.ts +0 -15
- package/vitest.config.mts +0 -21
package/lib/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/openapi-utils",
|
|
3
3
|
"description": "OpenAPI utils to build @tsed/swagger package or @tsed/scalar",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.12.0-rc.1",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tsed/openspec": "8.
|
|
27
|
+
"@tsed/openspec": "8.12.0-rc.1",
|
|
28
28
|
"micromatch": "4.0.8",
|
|
29
29
|
"tslib": "2.7.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsed/barrels": "8.
|
|
33
|
-
"@tsed/core": "8.
|
|
34
|
-
"@tsed/di": "8.
|
|
35
|
-
"@tsed/json-mapper": "8.
|
|
36
|
-
"@tsed/openspec": "8.
|
|
37
|
-
"@tsed/platform-http": "8.
|
|
38
|
-
"@tsed/schema": "8.
|
|
39
|
-
"@tsed/typescript": "8.
|
|
32
|
+
"@tsed/barrels": "8.12.0-rc.1",
|
|
33
|
+
"@tsed/core": "8.12.0-rc.1",
|
|
34
|
+
"@tsed/di": "8.12.0-rc.1",
|
|
35
|
+
"@tsed/json-mapper": "8.12.0-rc.1",
|
|
36
|
+
"@tsed/openspec": "8.12.0-rc.1",
|
|
37
|
+
"@tsed/platform-http": "8.12.0-rc.1",
|
|
38
|
+
"@tsed/schema": "8.12.0-rc.1",
|
|
39
|
+
"@tsed/typescript": "8.12.0-rc.1",
|
|
40
40
|
"eslint": "9.12.0",
|
|
41
41
|
"typescript": "5.4.5",
|
|
42
42
|
"vitest": "3.1.4"
|
|
@@ -55,5 +55,8 @@
|
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/openapi-utils",
|
|
57
57
|
"author": "Romain Lenzotti",
|
|
58
|
-
"license": "MIT"
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"tag": "rc"
|
|
61
|
+
}
|
|
59
62
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/decorators/docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAC,GAAG,IAAc;IACpC,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
package/lib/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiSettings.js","sourceRoot":"","sources":["../../../src/interfaces/OpenApiSettings.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cssMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/cssMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,OAAO,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEjC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,GAAG,EAAE;QACV,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QAEtB,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;QAEnE,GAAG,CAAC,QAAQ;aACT,UAAU,CAAC;YACV,cAAc,EAAE,UAAU;SAC3B,CAAC;aACD,MAAM,CAAC,GAAG,CAAC;aACX,IAAI,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/jsMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,OAAO,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEjC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,GAAG,EAAE;QACV,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QAEtB,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;QACnE,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAC,cAAc,EAAE,wBAAwB,EAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChG,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openApiMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/openApiMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAC;AAG3C,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAE7D;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAqB;IACrD,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,MAAM,QAAQ,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEvE,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redirectMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/redirectMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEjC;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,GAAG,EAAE;QACV,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QAEtB,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,KAAK,IAAI,GAAG,CAAC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appings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAEzC,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,QAAkB,EAAE,IAAqB;IACnF,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9C,MAAM,EAAC,GAAG,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IACjC,MAAM,KAAK,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,YAAY,IAAI,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAExE,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,gBAAgB,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"matchPath.js","sourceRoot":"","sources":["../../../src/utils/matchPath.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,QAAmB;IACzD,OAAO,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readSpec.js","sourceRoot":"","sources":["../../../src/utils/readSpec.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAY;IACzC,MAAM,EAAC,QAAQ,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACpD,MAAM,EAAC,UAAU,EAAC,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IAE7C,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;YAE1D,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IAChB,CAAC;IAED,0BAA0B;IAC1B,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/src/decorators/docs.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {StoreMerge} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Set the type documentation for this class.
|
|
5
|
-
*
|
|
6
|
-
* See [swagger documentation](/tutorials/swagger.html)
|
|
7
|
-
*
|
|
8
|
-
* @decorator
|
|
9
|
-
* @swagger
|
|
10
|
-
* @param docs
|
|
11
|
-
*/
|
|
12
|
-
export function Docs(...docs: string[]) {
|
|
13
|
-
return StoreMerge("docs", docs);
|
|
14
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Automatically generated by @tsed/barrels.
|
|
3
|
-
*/
|
|
4
|
-
export * from "./decorators/docs.js";
|
|
5
|
-
export * from "./interfaces/OpenApiSettings.js";
|
|
6
|
-
export * from "./middlewares/cssMiddleware.js";
|
|
7
|
-
export * from "./middlewares/jsMiddleware.js";
|
|
8
|
-
export * from "./middlewares/openApiMiddleware.js";
|
|
9
|
-
export * from "./middlewares/redirectMiddleware.js";
|
|
10
|
-
export * from "./services/OpenAPIBaseModule.js";
|
|
11
|
-
export * from "./services/OpenAPIService.js";
|
|
12
|
-
export * from "./utils/includeRoute.js";
|
|
13
|
-
export * from "./utils/matchPath.js";
|
|
14
|
-
export * from "./utils/readSpec.js";
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import {OpenSpec2, OpenSpec3, OpenSpecVersions, OS2Versions, OS3Versions} from "@tsed/openspec";
|
|
2
|
-
|
|
3
|
-
export interface SwaggerUIOptions {
|
|
4
|
-
configUrl?: string;
|
|
5
|
-
url?: string;
|
|
6
|
-
urls?: {url: string; name: string; primaryName?: string}[];
|
|
7
|
-
layout?: string;
|
|
8
|
-
validatorUrl?: string;
|
|
9
|
-
oauth?: any;
|
|
10
|
-
authorize?: any;
|
|
11
|
-
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface OpenApiSettingsBase {
|
|
16
|
-
/**
|
|
17
|
-
* The url subpath to access to the documentation.
|
|
18
|
-
*/
|
|
19
|
-
path: string;
|
|
20
|
-
/**
|
|
21
|
-
* Specify the spec version you want to generate.
|
|
22
|
-
*/
|
|
23
|
-
specVersion?: OpenSpecVersions;
|
|
24
|
-
/**
|
|
25
|
-
* Swagger file name. By default swagger.json
|
|
26
|
-
*/
|
|
27
|
-
fileName?: string;
|
|
28
|
-
/**
|
|
29
|
-
* The documentation key used by `@Docs` decorator to create several swagger documentations.
|
|
30
|
-
*/
|
|
31
|
-
doc?: string;
|
|
32
|
-
/**
|
|
33
|
-
* The path to the CSS file.
|
|
34
|
-
*/
|
|
35
|
-
cssPath?: string;
|
|
36
|
-
/**
|
|
37
|
-
* The path to the JS file.
|
|
38
|
-
*/
|
|
39
|
-
jsPath?: string;
|
|
40
|
-
/**
|
|
41
|
-
* The path to the ejs file to create html page.
|
|
42
|
-
*/
|
|
43
|
-
viewPath?: string | false;
|
|
44
|
-
/**
|
|
45
|
-
* Display the search field in the navbar.
|
|
46
|
-
*/
|
|
47
|
-
showExplorer?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Load the base spec documentation from the specified path.
|
|
50
|
-
*/
|
|
51
|
-
specPath?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Write the `swagger.json` spec documentation on the specified path.
|
|
54
|
-
*/
|
|
55
|
-
outFile?: string;
|
|
56
|
-
/**
|
|
57
|
-
* Display the documentation in the browser.
|
|
58
|
-
*/
|
|
59
|
-
hidden?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Sort paths by alphabetical order
|
|
62
|
-
*/
|
|
63
|
-
sortPaths?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* A function to generate the operationId.
|
|
66
|
-
*/
|
|
67
|
-
operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;
|
|
68
|
-
/**
|
|
69
|
-
* A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name).
|
|
70
|
-
*/
|
|
71
|
-
operationIdPattern?: string;
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
*/
|
|
75
|
-
disableSpec?: boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Include only controllers whose paths match the pattern list provided.
|
|
78
|
-
*/
|
|
79
|
-
pathPatterns?: string[];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface Swagger2Settings extends OpenApiSettingsBase {
|
|
83
|
-
specVersion?: OS2Versions;
|
|
84
|
-
/**
|
|
85
|
-
* OpenSpec 2
|
|
86
|
-
*/
|
|
87
|
-
spec?: Partial<OpenSpec2>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface OpenAPI3Settings extends OpenApiSettingsBase {
|
|
91
|
-
specVersion?: OS3Versions;
|
|
92
|
-
/**
|
|
93
|
-
* OpenSpec 3
|
|
94
|
-
*/
|
|
95
|
-
spec?: Partial<OpenSpec3>;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export type OpenApiSettings = Swagger2Settings | OpenAPI3Settings;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import Fs from "node:fs";
|
|
2
|
-
|
|
3
|
-
import {runInContext} from "@tsed/di";
|
|
4
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
5
|
-
|
|
6
|
-
import {cssMiddleware} from "./cssMiddleware.js";
|
|
7
|
-
|
|
8
|
-
describe("cssMiddleware", () => {
|
|
9
|
-
beforeEach(PlatformTest.create);
|
|
10
|
-
afterEach(PlatformTest.reset);
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
vi.spyOn(Fs, "readFileSync").mockReturnValue(".css{}");
|
|
13
|
-
});
|
|
14
|
-
it("should create a middleware", async () => {
|
|
15
|
-
const ctx = PlatformTest.createRequestContext();
|
|
16
|
-
|
|
17
|
-
await runInContext(ctx, () => cssMiddleware("/path")());
|
|
18
|
-
|
|
19
|
-
expect(ctx.response.raw.headers).toEqual({
|
|
20
|
-
"content-type": "text/css",
|
|
21
|
-
"x-request-id": "id"
|
|
22
|
-
});
|
|
23
|
-
expect(ctx.response.raw.statusCode).toEqual(200);
|
|
24
|
-
expect(ctx.response.raw.data).toEqual(".css{}");
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import Fs from "node:fs";
|
|
2
|
-
import {resolve} from "node:path";
|
|
3
|
-
|
|
4
|
-
import {context} from "@tsed/di";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Expose a css file.
|
|
8
|
-
* @param path
|
|
9
|
-
*/
|
|
10
|
-
export function cssMiddleware(path: string) {
|
|
11
|
-
return () => {
|
|
12
|
-
const ctx = context();
|
|
13
|
-
|
|
14
|
-
const content = Fs.readFileSync(resolve(path), {encoding: "utf8"});
|
|
15
|
-
|
|
16
|
-
ctx.response
|
|
17
|
-
.setHeaders({
|
|
18
|
-
"Content-Type": "text/css"
|
|
19
|
-
})
|
|
20
|
-
.status(200)
|
|
21
|
-
.body(content);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import Fs from "node:fs";
|
|
2
|
-
|
|
3
|
-
import {runInContext} from "@tsed/di";
|
|
4
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
5
|
-
|
|
6
|
-
import {jsMiddleware} from "./jsMiddleware.js";
|
|
7
|
-
|
|
8
|
-
describe("jsMiddleware", () => {
|
|
9
|
-
beforeEach(PlatformTest.create);
|
|
10
|
-
afterEach(PlatformTest.reset);
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
vi.spyOn(Fs, "readFileSync").mockReturnValue("var test=1");
|
|
13
|
-
});
|
|
14
|
-
it("should create a middleware", async () => {
|
|
15
|
-
const ctx = PlatformTest.createRequestContext();
|
|
16
|
-
|
|
17
|
-
await runInContext(ctx, () => jsMiddleware("/path")());
|
|
18
|
-
|
|
19
|
-
expect(ctx.response.raw.headers).toEqual({
|
|
20
|
-
"content-type": "application/javascript",
|
|
21
|
-
"x-request-id": "id"
|
|
22
|
-
});
|
|
23
|
-
expect(ctx.response.raw.statusCode).toBe(200);
|
|
24
|
-
expect(ctx.response.raw.data).toBe("var test=1");
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import Fs from "node:fs";
|
|
2
|
-
import {resolve} from "node:path";
|
|
3
|
-
|
|
4
|
-
import {context} from "@tsed/di";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Expose a js file.
|
|
8
|
-
* @param path
|
|
9
|
-
*/
|
|
10
|
-
export function jsMiddleware(path: string) {
|
|
11
|
-
return () => {
|
|
12
|
-
const ctx = context();
|
|
13
|
-
|
|
14
|
-
const content = Fs.readFileSync(resolve(path), {encoding: "utf8"});
|
|
15
|
-
ctx.response.setHeaders({"Content-Type": "application/javascript"}).status(200).body(content);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Fs from "node:fs";
|
|
2
|
-
|
|
3
|
-
import {runInContext} from "@tsed/di";
|
|
4
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
5
|
-
|
|
6
|
-
import {openApiMiddleware} from "./openApiMiddleware.js";
|
|
7
|
-
|
|
8
|
-
describe("openApiMiddleware", () => {
|
|
9
|
-
beforeEach(PlatformTest.create);
|
|
10
|
-
afterEach(PlatformTest.reset);
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
vi.spyOn(Fs, "readFileSync").mockReturnValue("var test=1");
|
|
13
|
-
});
|
|
14
|
-
it("should create a middleware", async () => {
|
|
15
|
-
const ctx = PlatformTest.createRequestContext();
|
|
16
|
-
const conf = {specVersion: "3.0.1"};
|
|
17
|
-
|
|
18
|
-
await runInContext(ctx, () => openApiMiddleware(conf as never)());
|
|
19
|
-
|
|
20
|
-
expect(ctx.response.raw.headers).toEqual({
|
|
21
|
-
"x-request-id": "id"
|
|
22
|
-
});
|
|
23
|
-
expect(ctx.response.raw.statusCode).toBe(200);
|
|
24
|
-
expect(ctx.response.raw.data).toEqual({
|
|
25
|
-
info: {
|
|
26
|
-
title: "Api documentation",
|
|
27
|
-
version: "1.0.0"
|
|
28
|
-
},
|
|
29
|
-
openapi: "3.0.1"
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {context, injector} from "@tsed/di";
|
|
2
|
-
|
|
3
|
-
import type {OpenApiSettings} from "../interfaces/OpenApiSettings.js";
|
|
4
|
-
import {OpenAPIService} from "../services/OpenAPIService.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Return a middleware to expose the OpenAPI spec.
|
|
8
|
-
*/
|
|
9
|
-
export function openApiMiddleware(conf: OpenApiSettings) {
|
|
10
|
-
return async () => {
|
|
11
|
-
const ctx = context();
|
|
12
|
-
const spec = await injector().get(OpenAPIService).getOpenAPISpec(conf);
|
|
13
|
-
|
|
14
|
-
ctx.response.status(200).body(spec);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {runInContext} from "@tsed/di";
|
|
2
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
3
|
-
|
|
4
|
-
import {redirectMiddleware} from "./redirectMiddleware.js";
|
|
5
|
-
|
|
6
|
-
describe("redirectMiddleware and redirect", () => {
|
|
7
|
-
beforeEach(PlatformTest.create);
|
|
8
|
-
afterEach(PlatformTest.reset);
|
|
9
|
-
it("should create a middleware", async () => {
|
|
10
|
-
const ctx = PlatformTest.createRequestContext();
|
|
11
|
-
vi.spyOn(ctx.response, "redirect").mockReturnValue(undefined as never);
|
|
12
|
-
|
|
13
|
-
ctx.request.raw.url = "/path";
|
|
14
|
-
ctx.request.raw.originalUrl = "/path";
|
|
15
|
-
ctx.request.raw.method = "GET";
|
|
16
|
-
|
|
17
|
-
await runInContext(ctx, () => redirectMiddleware("/path")());
|
|
18
|
-
|
|
19
|
-
expect(ctx.response.redirect).toHaveBeenCalledWith(302, "/path/");
|
|
20
|
-
});
|
|
21
|
-
it("should create a middleware and call next", async () => {
|
|
22
|
-
const ctx = PlatformTest.createRequestContext();
|
|
23
|
-
vi.spyOn(ctx.response, "redirect");
|
|
24
|
-
ctx.request.raw.url = "/path/";
|
|
25
|
-
ctx.request.raw.method = "GET";
|
|
26
|
-
ctx.request.raw.originalUrl = "/path/";
|
|
27
|
-
|
|
28
|
-
await runInContext(ctx, () => redirectMiddleware("/path")());
|
|
29
|
-
|
|
30
|
-
expect(ctx.response.redirect).not.toHaveBeenCalled();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {context} from "@tsed/di";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Redirect to the same path with a trailing slash
|
|
5
|
-
* @param path
|
|
6
|
-
*/
|
|
7
|
-
export function redirectMiddleware(path: string) {
|
|
8
|
-
return () => {
|
|
9
|
-
const ctx = context();
|
|
10
|
-
|
|
11
|
-
if (ctx.request.method?.toUpperCase() === "GET" && ctx.request.url === path && !ctx.request.url.match(/\/$/)) {
|
|
12
|
-
ctx.response.redirect(302, `${path}/`);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import {basename} from "node:path";
|
|
2
|
-
|
|
3
|
-
import {Env} from "@tsed/core";
|
|
4
|
-
import {configuration, constant, inject, logger} from "@tsed/di";
|
|
5
|
-
import {normalizePath} from "@tsed/normalize-path";
|
|
6
|
-
import {application, OnReady, OnRoutesInit} from "@tsed/platform-http";
|
|
7
|
-
import {PlatformRouter, useContextHandler} from "@tsed/platform-router";
|
|
8
|
-
|
|
9
|
-
import type {OpenApiSettings} from "../interfaces/OpenApiSettings.js";
|
|
10
|
-
import {cssMiddleware} from "../middlewares/cssMiddleware.js";
|
|
11
|
-
import {jsMiddleware} from "../middlewares/jsMiddleware.js";
|
|
12
|
-
import {openApiMiddleware} from "../middlewares/openApiMiddleware.js";
|
|
13
|
-
import {redirectMiddleware} from "../middlewares/redirectMiddleware.js";
|
|
14
|
-
import {OpenAPIService} from "../services/OpenAPIService.js";
|
|
15
|
-
|
|
16
|
-
export abstract class OpenAPIBaseModule implements OnRoutesInit, OnReady {
|
|
17
|
-
abstract name: string;
|
|
18
|
-
abstract rootDir: string;
|
|
19
|
-
abstract settings: OpenApiSettings[];
|
|
20
|
-
protected openAPIService = inject(OpenAPIService);
|
|
21
|
-
protected env = constant<Env>("env");
|
|
22
|
-
protected disableRoutesSummary = constant<boolean>("logger.disableRoutesSummary");
|
|
23
|
-
private loaded = false;
|
|
24
|
-
|
|
25
|
-
$onRoutesInit() {
|
|
26
|
-
if (this.loaded) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.settings.forEach((conf: OpenApiSettings) => {
|
|
31
|
-
const {path = "/"} = conf;
|
|
32
|
-
|
|
33
|
-
application().use(path, useContextHandler(redirectMiddleware(path)));
|
|
34
|
-
application().use(path, this.createRouter(conf));
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
this.loaded = true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
$onReady() {
|
|
41
|
-
// istanbul ignore next
|
|
42
|
-
if (configuration().getBestHost && !this.disableRoutesSummary) {
|
|
43
|
-
const host = configuration().getBestHost();
|
|
44
|
-
const url = host.toString();
|
|
45
|
-
|
|
46
|
-
const displayLog = (conf: OpenApiSettings) => {
|
|
47
|
-
const {path, fileName, doc, specVersion} = conf;
|
|
48
|
-
|
|
49
|
-
logger().info(
|
|
50
|
-
`[${doc || "default"}] ${specVersion === "2.0" ? "Swagger" : "OpenAPI"} JSON is available on ${url}${normalizePath(path, fileName!)}`
|
|
51
|
-
);
|
|
52
|
-
logger().info(`[${doc || "default"}] ${this.name} UI is available on ${url}${path}/`);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
this.settings.forEach((conf) => {
|
|
56
|
-
displayLog(conf);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.generateSpecFiles();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
generateSpecFiles() {
|
|
64
|
-
return Promise.all(
|
|
65
|
-
this.settings.map(async (conf) => {
|
|
66
|
-
this.openAPIService.writeOpenAPISpec(conf);
|
|
67
|
-
})
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
protected createRouter(conf: OpenApiSettings) {
|
|
72
|
-
const {disableSpec, fileName, cssPath, jsPath, viewPath} = conf;
|
|
73
|
-
const router = new PlatformRouter();
|
|
74
|
-
|
|
75
|
-
if (!disableSpec) {
|
|
76
|
-
router.get(normalizePath("/", fileName!), useContextHandler(openApiMiddleware(conf)));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (viewPath) {
|
|
80
|
-
if (cssPath) {
|
|
81
|
-
router.get(`/${basename(cssPath)}`, useContextHandler(cssMiddleware(cssPath)));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (jsPath) {
|
|
85
|
-
router.get(`/${basename(jsPath)}`, useContextHandler(jsMiddleware(jsPath)));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return router;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {writeFile} from "node:fs/promises";
|
|
2
|
-
|
|
3
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
4
|
-
|
|
5
|
-
import {OpenAPIService} from "../index.js";
|
|
6
|
-
|
|
7
|
-
vi.mock("node:fs/promises");
|
|
8
|
-
|
|
9
|
-
describe("SwaggerService", () => {
|
|
10
|
-
beforeEach(() => PlatformTest.create());
|
|
11
|
-
afterEach(() => PlatformTest.reset());
|
|
12
|
-
|
|
13
|
-
describe("getOpenAPISpec()", () => {
|
|
14
|
-
it("should compile spec only once time", async () => {
|
|
15
|
-
const service = await PlatformTest.invoke<OpenAPIService>(OpenAPIService);
|
|
16
|
-
const result1 = await service.getOpenAPISpec({specVersion: "3.0.1"} as any);
|
|
17
|
-
const result2 = await service.getOpenAPISpec({specVersion: "3.0.1"} as any);
|
|
18
|
-
|
|
19
|
-
expect(result1).toEqual(result2);
|
|
20
|
-
expect(result1).toMatchSnapshot();
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("writeOpenAPISpec()", () => {
|
|
25
|
-
it("should write spec only once time", async () => {
|
|
26
|
-
const service = await PlatformTest.invoke<OpenAPIService>(OpenAPIService);
|
|
27
|
-
|
|
28
|
-
await service.writeOpenAPISpec({specVersion: "3.0.1", outFile: "/path"} as any);
|
|
29
|
-
|
|
30
|
-
expect(writeFile).toHaveBeenCalledWith("/path", expect.any(String), {
|
|
31
|
-
encoding: "utf8"
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {writeFile} from "node:fs/promises";
|
|
2
|
-
|
|
3
|
-
import {Env, type Type} from "@tsed/core";
|
|
4
|
-
import {constant, inject, injectable} from "@tsed/di";
|
|
5
|
-
import {$asyncAlter} from "@tsed/hooks";
|
|
6
|
-
import {OpenSpec2, OpenSpec3} from "@tsed/openspec";
|
|
7
|
-
import {Platform} from "@tsed/platform-http";
|
|
8
|
-
import {generateSpec} from "@tsed/schema";
|
|
9
|
-
|
|
10
|
-
import {OpenAPI3Settings, OpenApiSettings, Swagger2Settings} from "../interfaces/OpenApiSettings.js";
|
|
11
|
-
import {includeRoute} from "../utils/includeRoute.js";
|
|
12
|
-
import {readSpec} from "../utils/readSpec.js";
|
|
13
|
-
|
|
14
|
-
export class OpenAPIService {
|
|
15
|
-
protected platform = inject(Platform);
|
|
16
|
-
|
|
17
|
-
#specs: Map<string, OpenSpec3 | OpenSpec2> = new Map();
|
|
18
|
-
|
|
19
|
-
constructor() {}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Generate Spec for the given configuration
|
|
23
|
-
*/
|
|
24
|
-
public async getOpenAPISpec(conf: OpenAPI3Settings): Promise<OpenSpec3>;
|
|
25
|
-
public async getOpenAPISpec(conf: Swagger2Settings): Promise<OpenSpec2>;
|
|
26
|
-
public async getOpenAPISpec(conf: OpenApiSettings): Promise<OpenSpec2>;
|
|
27
|
-
public async getOpenAPISpec(conf: OpenApiSettings) {
|
|
28
|
-
if (!this.#specs.has(conf.path)) {
|
|
29
|
-
const version = constant("version", "1.0.0");
|
|
30
|
-
const acceptMimes = constant<string>("acceptMimes");
|
|
31
|
-
const specPath = conf.specPath;
|
|
32
|
-
|
|
33
|
-
const tokens = this.platform
|
|
34
|
-
.getMountedControllers()
|
|
35
|
-
.filter(({routes, provider}) => [...routes.values()].some((route) => includeRoute(route, provider, conf)))
|
|
36
|
-
.map(({route, provider}) => ({token: provider.token as Type, rootPath: route}));
|
|
37
|
-
|
|
38
|
-
let spec = generateSpec({
|
|
39
|
-
tokens,
|
|
40
|
-
...conf,
|
|
41
|
-
fileSpec: specPath ? await readSpec(specPath) : {},
|
|
42
|
-
version,
|
|
43
|
-
acceptMimes
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
spec = await $asyncAlter("$alterOpenSpec", spec, [conf]);
|
|
47
|
-
|
|
48
|
-
this.#specs.set(conf.path, spec);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return this.#specs.get(conf.path);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async writeOpenAPISpec(conf: OpenApiSettings) {
|
|
55
|
-
const {outFile} = conf;
|
|
56
|
-
const env = constant<Env>("env");
|
|
57
|
-
|
|
58
|
-
if (env === Env.PROD || outFile) {
|
|
59
|
-
const spec = await this.getOpenAPISpec(conf);
|
|
60
|
-
|
|
61
|
-
if (outFile) {
|
|
62
|
-
return writeFile(outFile, JSON.stringify(spec, null, 2), {encoding: "utf8"});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
injectable(OpenAPIService);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`SwaggerService > getOpenAPISpec() > should compile spec only once time 1`] = `
|
|
4
|
-
{
|
|
5
|
-
"info": {
|
|
6
|
-
"title": "Api documentation",
|
|
7
|
-
"version": "1.0.0",
|
|
8
|
-
},
|
|
9
|
-
"openapi": "3.0.1",
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`SwaggerService > getOpenAPISpec() > should compile spec only once time 1`] = `
|
|
4
|
-
{
|
|
5
|
-
"info": {
|
|
6
|
-
"title": "Api documentation",
|
|
7
|
-
"version": "1.0.0",
|
|
8
|
-
},
|
|
9
|
-
"openapi": "3.0.1",
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import {ControllerProvider} from "@tsed/di";
|
|
2
|
-
import {Hidden} from "@tsed/schema";
|
|
3
|
-
|
|
4
|
-
import {Docs} from "../decorators/docs.js";
|
|
5
|
-
import {includeRoute} from "./includeRoute.js";
|
|
6
|
-
|
|
7
|
-
@Hidden()
|
|
8
|
-
class HiddenCtrl {}
|
|
9
|
-
|
|
10
|
-
@Docs("test")
|
|
11
|
-
class DocsCtrl {}
|
|
12
|
-
|
|
13
|
-
class PlainCtrl {}
|
|
14
|
-
|
|
15
|
-
describe("includeRoute", () => {
|
|
16
|
-
it.each([
|
|
17
|
-
{
|
|
18
|
-
label: "a simple configuration + HiddenCtrl are given",
|
|
19
|
-
expected: false,
|
|
20
|
-
route: "/test",
|
|
21
|
-
conf: {
|
|
22
|
-
path: "/swagger"
|
|
23
|
-
},
|
|
24
|
-
controller: HiddenCtrl
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
label: "a simple configuration + PlainCtrl are given",
|
|
28
|
-
expected: true,
|
|
29
|
-
route: "/test",
|
|
30
|
-
conf: {
|
|
31
|
-
path: "/swagger"
|
|
32
|
-
},
|
|
33
|
-
controller: PlainCtrl
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
label: "a given configuration with doc property doesn't match route",
|
|
37
|
-
expected: false,
|
|
38
|
-
route: "/test",
|
|
39
|
-
conf: {
|
|
40
|
-
path: "/swagger",
|
|
41
|
-
doc: "notmatch"
|
|
42
|
-
},
|
|
43
|
-
controller: DocsCtrl
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
label: "a given configuration with doc property matching route",
|
|
47
|
-
expected: true,
|
|
48
|
-
route: "/test",
|
|
49
|
-
conf: {
|
|
50
|
-
path: "/swagger",
|
|
51
|
-
doc: "test"
|
|
52
|
-
},
|
|
53
|
-
controller: DocsCtrl
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
label: "a given configuration with pathPatterns property matching route",
|
|
57
|
-
expected: true,
|
|
58
|
-
route: "/should/match",
|
|
59
|
-
conf: {
|
|
60
|
-
path: "/swagger",
|
|
61
|
-
pathPatterns: ["/should/**"]
|
|
62
|
-
},
|
|
63
|
-
controller: PlainCtrl
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
label: "a given configuration with pathPatterns property doesn't match route",
|
|
67
|
-
expected: false,
|
|
68
|
-
route: "/shouldnot/match",
|
|
69
|
-
conf: {
|
|
70
|
-
path: "/swagger",
|
|
71
|
-
pathPatterns: ["/notmatch/**"]
|
|
72
|
-
},
|
|
73
|
-
controller: PlainCtrl
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
label: "a given configuration with pathPatterns property doesn't match route - negation on pathPatterns",
|
|
77
|
-
expected: false,
|
|
78
|
-
route: "/should/match",
|
|
79
|
-
conf: {
|
|
80
|
-
path: "/swagger",
|
|
81
|
-
pathPatterns: ["!/should/**"]
|
|
82
|
-
},
|
|
83
|
-
controller: PlainCtrl
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
label: "a given configuration with pathPatterns/doc properties but only doc match",
|
|
87
|
-
expected: true,
|
|
88
|
-
route: "/shouldnot/match",
|
|
89
|
-
conf: {
|
|
90
|
-
path: "/swagger",
|
|
91
|
-
doc: "test",
|
|
92
|
-
pathPatterns: ["/notmatch/**"]
|
|
93
|
-
},
|
|
94
|
-
controller: DocsCtrl
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
label: "a given configuration with pathPatterns/doc properties but only pathPattern match",
|
|
98
|
-
expected: true,
|
|
99
|
-
route: "/should/match",
|
|
100
|
-
conf: {
|
|
101
|
-
path: "/swagger",
|
|
102
|
-
doc: "nomatch",
|
|
103
|
-
pathPatterns: ["/should/**"]
|
|
104
|
-
},
|
|
105
|
-
controller: DocsCtrl
|
|
106
|
-
}
|
|
107
|
-
])("should return $expected when $label ($route)", ({expected, conf, route, controller}) => {
|
|
108
|
-
const provider = new ControllerProvider(controller);
|
|
109
|
-
expect(includeRoute(route, provider, conf as any)).toBe(expected);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {Provider} from "@tsed/di";
|
|
2
|
-
|
|
3
|
-
import {OpenApiSettings} from "../interfaces/OpenApiSettings.js";
|
|
4
|
-
import {matchPath} from "./matchPath.js";
|
|
5
|
-
|
|
6
|
-
export function includeRoute(route: string, provider: Provider, conf: OpenApiSettings): boolean {
|
|
7
|
-
const hidden = provider.store.get("hidden");
|
|
8
|
-
const docs = provider.store.get("docs") || [];
|
|
9
|
-
const {doc, pathPatterns} = conf;
|
|
10
|
-
const inDoc = doc && docs.indexOf(doc) > -1;
|
|
11
|
-
const pathPatternMatch = pathPatterns && matchPath(route, pathPatterns);
|
|
12
|
-
|
|
13
|
-
if (hidden) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (!doc && !pathPatterns) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return !!(inDoc || pathPatternMatch);
|
|
22
|
-
}
|
package/src/utils/matchPath.ts
DELETED
package/src/utils/readSpec.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export async function readSpec(path: string) {
|
|
2
|
-
const {readFile} = await import("node:fs/promises");
|
|
3
|
-
const {existsSync} = await import("node:fs");
|
|
4
|
-
|
|
5
|
-
if (existsSync(path)) {
|
|
6
|
-
try {
|
|
7
|
-
const response = await readFile(path, {encoding: "utf8"});
|
|
8
|
-
|
|
9
|
-
return JSON.parse(response);
|
|
10
|
-
} catch (e) {}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/* istanbul ignore next */
|
|
14
|
-
return {};
|
|
15
|
-
}
|
package/vitest.config.mts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import {presets} from "@tsed/vitest/presets";
|
|
3
|
-
import {defineConfig} from "vitest/config";
|
|
4
|
-
|
|
5
|
-
export default defineConfig(
|
|
6
|
-
{
|
|
7
|
-
...presets,
|
|
8
|
-
test: {
|
|
9
|
-
...presets.test,
|
|
10
|
-
coverage: {
|
|
11
|
-
...presets.test.coverage,
|
|
12
|
-
thresholds: {
|
|
13
|
-
statements: 0,
|
|
14
|
-
branches: 0,
|
|
15
|
-
functions: 0,
|
|
16
|
-
lines: 0
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
);
|