From 675a0272ca3d60db716ee97bf17012dddfe38637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Wed, 4 Dec 2024 10:31:04 +0100 Subject: [PATCH] chore: deprecate swagger ui enabled, use ui instead --- e2e/express.e2e-spec.ts | 4 ++-- e2e/fastify.e2e-spec.ts | 2 +- lib/interfaces/swagger-custom-options.interface.ts | 11 +++++++++-- lib/swagger-module.ts | 10 +++++----- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/e2e/express.e2e-spec.ts b/e2e/express.e2e-spec.ts index 235a0a718..b7576d3c6 100644 --- a/e2e/express.e2e-spec.ts +++ b/e2e/express.e2e-spec.ts @@ -123,7 +123,7 @@ describe('Express Swagger', () => { builder.build() ); SwaggerModule.setup(SWAGGER_RELATIVE_URL, app, swaggerDocument, { - swaggerUiEnabled: false + ui: false }); await app.init(); @@ -216,7 +216,7 @@ describe('Express Swagger', () => { builder.build() ); SwaggerModule.setup(SWAGGER_RELATIVE_URL, app, swaggerDocument, { - swaggerUiEnabled: false, + ui: false, raw: false }); diff --git a/e2e/fastify.e2e-spec.ts b/e2e/fastify.e2e-spec.ts index 675c8f47f..69cb084f9 100644 --- a/e2e/fastify.e2e-spec.ts +++ b/e2e/fastify.e2e-spec.ts @@ -169,7 +169,7 @@ describe('Fastify Swagger', () => { builder.build() ); SwaggerModule.setup(SWAGGER_RELATIVE_URL, app, swaggerDocument, { - swaggerUiEnabled: false, + ui: false, raw: false }); diff --git a/lib/interfaces/swagger-custom-options.interface.ts b/lib/interfaces/swagger-custom-options.interface.ts index 7fcea3afb..803d9851f 100644 --- a/lib/interfaces/swagger-custom-options.interface.ts +++ b/lib/interfaces/swagger-custom-options.interface.ts @@ -11,12 +11,19 @@ export interface SwaggerCustomOptions { /** * If `false`, the Swagger UI will not be served. Only API definitions (JSON and YAML) - * will be accessible (on `/{path}-json` and `/{path}-yaml`). - * To fully disable both the Swagger UI and API definitions, use `raw: false`. + * will be accessible (on `/{path}-json` and `/{path}-yaml`). To fully disable both the Swagger UI and API definitions, use `raw: false`. * Default: `true`. + * @deprecated Use `ui` instead. */ swaggerUiEnabled?: boolean; + /** + * If `false`, the Swagger UI will not be served. Only API definitions (JSON and YAML) + * will be accessible (on `/{path}-json` and `/{path}-yaml`). To fully disable both the Swagger UI and API definitions, use `raw: false`. + * Default: `true`. + */ + ui?: boolean; + /** * If `true`, raw definitions for all formats will be served. * Alternatively, you can pass an array to specify the formats to be served, e.g., `raw: ['json']` to serve only JSON definitions. diff --git a/lib/swagger-module.ts b/lib/swagger-module.ts index 3926b3ecd..f13433dec 100644 --- a/lib/swagger-module.ts +++ b/lib/swagger-module.ts @@ -85,7 +85,7 @@ export class SwaggerModule { httpAdapter: HttpServer, documentOrFactory: OpenAPIObject | (() => OpenAPIObject), options: { - swaggerUiEnabled: boolean; + ui: boolean; raw: boolean | Array<'json' | 'yaml'>; jsonDocumentUrl: string; yamlDocumentUrl: string; @@ -104,7 +104,7 @@ export class SwaggerModule { return document; }; - if (options.swaggerUiEnabled) { + if (options.ui) { this.serveSwaggerUi( finalPath, urlLastSubdirectory, @@ -308,7 +308,7 @@ export class SwaggerModule { ? `${validatedGlobalPrefix}${validatePath(options.yamlDocumentUrl)}` : `${finalPath}-yaml`; - const swaggerUiEnabled = options?.swaggerUiEnabled ?? true; + const ui = options?.ui ?? options?.swaggerUiEnabled ?? true; const raw = options?.raw ?? true; const httpAdapter = app.getHttpAdapter(); @@ -319,7 +319,7 @@ export class SwaggerModule { httpAdapter, documentOrFactory, { - swaggerUiEnabled, + ui, raw, jsonDocumentUrl: finalJSONDocumentPath, yamlDocumentUrl: finalYAMLDocumentPath, @@ -327,7 +327,7 @@ export class SwaggerModule { } ); - if (swaggerUiEnabled) { + if (ui) { SwaggerModule.serveStatic(finalPath, app, options?.customSwaggerUiPath); /** * Covers assets fetched through a relative path when Swagger url ends with a slash '/'.