@tsed/swagger 8.11.1 → 8.11.2-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.
@@ -46,4 +46,3 @@ export class SwaggerModule extends OpenAPIBaseModule {
46
46
  }
47
47
  }
48
48
  injectable(SwaggerModule).type(ProviderType.MODULE);
49
- //# sourceMappingURL=SwaggerModule.js.map
@@ -3,4 +3,3 @@ import { getValue } from "@tsed/core";
3
3
  import getAbsoluteFSPath from "swagger-ui-dist/absolute-path.js";
4
4
  export const SWAGGER_UI_DIST = getAbsoluteFSPath();
5
5
  export const ROOT_DIR = join(getValue(import.meta, "dirname", ""), "..");
6
- //# sourceMappingURL=constants.js.map
@@ -1,2 +1 @@
1
1
  export { Docs, OpenAPIService as SwaggerService } from "@tsed/openapi-utils";
2
- //# sourceMappingURL=exports.js.map
package/lib/esm/index.js CHANGED
@@ -7,4 +7,3 @@ export * from "./interfaces/interfaces.js";
7
7
  export * from "./interfaces/SwaggerSettings.js";
8
8
  export * from "./middlewares/indexMiddleware.js";
9
9
  export * from "./SwaggerModule.js";
10
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=SwaggerSettings.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=interfaces.js.map
@@ -20,4 +20,3 @@ export function indexMiddleware(viewPath, conf) {
20
20
  }));
21
21
  };
22
22
  }
23
- //# sourceMappingURL=indexMiddleware.js.map
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/swagger",
3
3
  "description": "Swagger package for Ts.ED framework",
4
4
  "type": "module",
5
- "version": "8.11.1",
5
+ "version": "8.11.2-rc.1",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -26,22 +26,22 @@
26
26
  "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
27
27
  },
28
28
  "dependencies": {
29
- "@tsed/normalize-path": "8.11.1",
30
- "@tsed/openapi-utils": "8.11.1",
31
- "@tsed/openspec": "8.11.1",
29
+ "@tsed/normalize-path": "8.11.2-rc.1",
30
+ "@tsed/openapi-utils": "8.11.2-rc.1",
31
+ "@tsed/openspec": "8.11.2-rc.1",
32
32
  "swagger-ui-dist": ">=5.17.14",
33
33
  "tslib": "2.7.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@tsed/barrels": "8.11.1",
37
- "@tsed/core": "8.11.1",
38
- "@tsed/di": "8.11.1",
39
- "@tsed/json-mapper": "8.11.1",
40
- "@tsed/openapi-utils": "8.11.1",
41
- "@tsed/openspec": "8.11.1",
42
- "@tsed/platform-http": "8.11.1",
43
- "@tsed/schema": "8.11.1",
44
- "@tsed/typescript": "8.11.1",
36
+ "@tsed/barrels": "8.11.2-rc.1",
37
+ "@tsed/core": "8.11.2-rc.1",
38
+ "@tsed/di": "8.11.2-rc.1",
39
+ "@tsed/json-mapper": "8.11.2-rc.1",
40
+ "@tsed/openapi-utils": "8.11.2-rc.1",
41
+ "@tsed/openspec": "8.11.2-rc.1",
42
+ "@tsed/platform-http": "8.11.2-rc.1",
43
+ "@tsed/schema": "8.11.2-rc.1",
44
+ "@tsed/typescript": "8.11.2-rc.1",
45
45
  "@types/swagger-ui-dist": "3.30.5",
46
46
  "eslint": "9.12.0",
47
47
  "typescript": "5.4.5",
@@ -61,5 +61,8 @@
61
61
  },
62
62
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/swagger",
63
63
  "author": "Romain Lenzotti",
64
- "license": "MIT"
64
+ "license": "MIT",
65
+ "publishConfig": {
66
+ "tag": "rc"
67
+ }
65
68
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"SwaggerModule.js","sourceRoot":"","sources":["../../src/SwaggerModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAE,YAAY,EA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pB,GAAG,IAAI;aACR,CAAC,CACH,CACF,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAC,IAAI,EAAE,eAAe,EAAC,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAES,OAAO;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAU,EAAE,IAAI,EAAE,EAAE;YAC/C,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAC,GAAG,IAAI,CAAC;YAE3C,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,GAAG,CAAC,IAAI,CAAC,EAAC,GAAG,EAAE,aAAa,CAAC,IAAI,EAAE,QAAS,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,IAAI,EAAC,CAAC,CAAC;YACrE,CAAC;YAED,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF;AAED,UAAU,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,iBAAiB,MAAM,kCAAkC,CAAC;AAEjE,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,EAAE,CAAC;AACnD,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,cAAc,IAAI,cAAc,EAAC,MAAM,qBAAqB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,oBAAoB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SwaggerSettings.js","sourceRoot":"","sources":["../../../src/interfaces/SwaggerSettings.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"indexMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/indexMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,IAAI,EAAC,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAIjC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,IAAwC;IACxF,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QACtB,MAAM,EAAC,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC;QAEjF,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,IAAI,CACxC,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE;YAClC,IAAI,EAAE,EAAE;YACR,GAAG,EAAE,GAAG,IAAI,IAAI,QAAQ,EAAE;YAC1B,IAAI;YACJ,YAAY;YACZ,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;YACjD,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC9C,cAAc,EAAE,OAAO;SACxB,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -1,64 +0,0 @@
1
- import {logger} from "@tsed/di";
2
- import {application} from "@tsed/platform-http";
3
- import {PlatformTest} from "@tsed/platform-http/testing";
4
- import {PlatformRouter} from "@tsed/platform-router";
5
- import {absolutePath} from "swagger-ui-dist";
6
-
7
- import {SwaggerModule} from "./SwaggerModule.js";
8
-
9
- vi.mock("node:fs/promises");
10
-
11
- describe("SwaggerModule", () => {
12
- beforeEach(() =>
13
- PlatformTest.create({
14
- httpPort: 8080,
15
- httpsPort: 8081,
16
- swagger: [
17
- {
18
- path: "/doc",
19
- cssPath: "/cssPath/style.css",
20
- jsPath: "/jsPath/script.js",
21
- viewPath: "/viewsPath",
22
- outFile: "/spec.json"
23
- }
24
- ]
25
- })
26
- );
27
- afterEach(PlatformTest.reset);
28
-
29
- describe("$onRoutesInit", () => {
30
- it("should add middlewares", async () => {
31
- const mod = await PlatformTest.invoke<SwaggerModule>(SwaggerModule);
32
-
33
- vi.spyOn(application(), "get").mockReturnValue(undefined as never);
34
- vi.spyOn(application(), "use").mockReturnValue(undefined as never);
35
- vi.spyOn(PlatformRouter.prototype as any, "get").mockReturnValue(undefined);
36
- vi.spyOn(PlatformRouter.prototype as any, "statics").mockReturnValue(undefined);
37
-
38
- mod.$onRoutesInit();
39
- mod.$onRoutesInit();
40
-
41
- expect(application().use).toHaveBeenCalledWith("/doc", expect.any(Function));
42
- expect(application().use).toHaveBeenCalledWith("/doc", expect.any(PlatformRouter));
43
- expect(PlatformRouter.prototype.get).toHaveBeenCalledWith("/swagger.json", expect.any(Function));
44
- expect(PlatformRouter.prototype.get).toHaveBeenCalledWith("/style.css", expect.any(Function));
45
- expect(PlatformRouter.prototype.get).toHaveBeenCalledWith("/script.js", expect.any(Function));
46
- expect(PlatformRouter.prototype.statics).toHaveBeenCalledWith("/", {
47
- root: absolutePath()
48
- });
49
- });
50
- });
51
-
52
- describe("$onReady", () => {
53
- it("should display the right log", async () => {
54
- const mod = await PlatformTest.invoke<SwaggerModule>(SwaggerModule);
55
-
56
- vi.spyOn(logger(), "info");
57
-
58
- mod.$onReady();
59
-
60
- expect(logger().info).toHaveBeenCalledWith("[default] OpenAPI JSON is available on https://0.0.0.0:8081/doc/swagger.json");
61
- expect(logger().info).toHaveBeenCalledWith("[default] Swagger UI is available on https://0.0.0.0:8081/doc/");
62
- });
63
- });
64
- });
@@ -1,66 +0,0 @@
1
- import {join} from "node:path";
2
-
3
- import {constant, injectable, ProviderType} from "@tsed/di";
4
- import {normalizePath} from "@tsed/normalize-path";
5
- import {OpenAPIBaseModule} from "@tsed/openapi-utils";
6
- import {useContextHandler} from "@tsed/platform-router";
7
-
8
- import {ROOT_DIR, SWAGGER_UI_DIST} from "./constants.js";
9
- import {SwaggerSettings} from "./interfaces/SwaggerSettings.js";
10
- import {indexMiddleware} from "./middlewares/indexMiddleware.js";
11
-
12
- export class SwaggerModule extends OpenAPIBaseModule {
13
- readonly name = "Swagger";
14
- readonly rootDir = ROOT_DIR;
15
-
16
- get settings() {
17
- const settings = constant<SwaggerSettings[]>("swagger", []).filter((o) => !!o);
18
-
19
- return settings.map((conf) => {
20
- return Object.assign(
21
- {
22
- disableSpec: false,
23
- path: "/",
24
- fileName: "swagger.json",
25
- cssPath: join(ROOT_DIR, "views/assets/swagger.css"),
26
- viewPath: join(ROOT_DIR, "views/index.ejs")
27
- },
28
- conf
29
- );
30
- });
31
- }
32
-
33
- protected createRouter(conf: SwaggerSettings) {
34
- const {viewPath} = conf;
35
- const router = super.createRouter(conf);
36
-
37
- if (viewPath) {
38
- router.get(
39
- "/",
40
- useContextHandler(
41
- indexMiddleware(viewPath, {
42
- urls: this.getUrls(),
43
- ...conf
44
- })
45
- )
46
- );
47
- router.statics("/", {root: SWAGGER_UI_DIST});
48
- }
49
-
50
- return router;
51
- }
52
-
53
- protected getUrls() {
54
- return this.settings.reduce((acc: any[], conf) => {
55
- const {path, fileName, doc, hidden} = conf;
56
-
57
- if (!hidden) {
58
- acc.push({url: normalizePath(path, fileName!), name: doc || path});
59
- }
60
-
61
- return acc;
62
- }, []);
63
- }
64
- }
65
-
66
- injectable(SwaggerModule).type(ProviderType.MODULE);
package/src/constants.ts DELETED
@@ -1,7 +0,0 @@
1
- import {join} from "node:path";
2
-
3
- import {getValue} from "@tsed/core";
4
- import getAbsoluteFSPath from "swagger-ui-dist/absolute-path.js";
5
-
6
- export const SWAGGER_UI_DIST = getAbsoluteFSPath();
7
- export const ROOT_DIR = join(getValue(import.meta, "dirname", ""), "..");
package/src/exports.ts DELETED
@@ -1 +0,0 @@
1
- export {Docs, OpenAPIService as SwaggerService} from "@tsed/openapi-utils";
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./constants.js";
5
- export * from "./exports.js";
6
- export * from "./interfaces/interfaces.js";
7
- export * from "./interfaces/SwaggerSettings.js";
8
- export * from "./middlewares/indexMiddleware.js";
9
- export * from "./SwaggerModule.js";
@@ -1,23 +0,0 @@
1
- import type {OpenAPI3Settings, OpenApiSettings, Swagger2Settings} from "@tsed/openapi-utils";
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 type SwaggerOS2Settings = Swagger2Settings;
16
- export type SwaggerOS3Settings = OpenAPI3Settings;
17
- export type SwaggerSettings = OpenApiSettings & {
18
- showExplorer?: boolean;
19
- /**
20
- * SwaggerUI options. See (https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md)
21
- */
22
- options?: SwaggerUIOptions;
23
- };
@@ -1,9 +0,0 @@
1
- import {SwaggerSettings} from "./SwaggerSettings.js";
2
-
3
- declare global {
4
- namespace TsED {
5
- interface Configuration {
6
- swagger: SwaggerSettings[];
7
- }
8
- }
9
- }
@@ -1,36 +0,0 @@
1
- import {runInContext} from "@tsed/di";
2
- import {PlatformTest} from "@tsed/platform-http/testing";
3
-
4
- import {indexMiddleware} from "./indexMiddleware.js";
5
-
6
- describe("indexMiddleware 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, "render").mockResolvedValue("");
12
-
13
- const viewPath = "/swagger.ejs";
14
- const conf = {
15
- path: "/doc",
16
- options: {},
17
- fileName: "swagger.json",
18
- showExplorer: false,
19
- cssPath: "/path.css",
20
- jsPath: "/path.js",
21
- urls: []
22
- };
23
-
24
- await runInContext(ctx, () => indexMiddleware(viewPath, conf)());
25
-
26
- expect(ctx.response.render).toHaveBeenCalledWith(viewPath, {
27
- spec: {},
28
- cssPath: "/doc/path.css",
29
- jsPath: "/doc/path.js",
30
- showExplorer: false,
31
- swaggerOptions: {},
32
- url: "/doc/swagger.json",
33
- urls: []
34
- });
35
- });
36
- });
@@ -1,29 +0,0 @@
1
- import {basename, join} from "node:path";
2
-
3
- import {context} from "@tsed/di";
4
-
5
- import {SwaggerSettings} from "../interfaces/SwaggerSettings.js";
6
-
7
- /**
8
- * @ignore
9
- * @param viewPath
10
- * @param conf
11
- */
12
- export function indexMiddleware(viewPath: string, conf: SwaggerSettings & {urls: string[]}) {
13
- return async () => {
14
- const ctx = context();
15
- const {path, options = {}, fileName, showExplorer, cssPath, jsPath, urls} = conf;
16
-
17
- ctx.response.contentType("text/html").body(
18
- await ctx.response.render(viewPath, {
19
- spec: {},
20
- url: `${path}/${fileName}`,
21
- urls,
22
- showExplorer,
23
- cssPath: cssPath && join(path, basename(cssPath)),
24
- jsPath: jsPath && join(path, basename(jsPath)),
25
- swaggerOptions: options
26
- })
27
- );
28
- };
29
- }
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
- );