From 892ea068a7561c18a02614522cc56239e3ed0b4e Mon Sep 17 00:00:00 2001 From: JaeHo Jang Date: Wed, 19 Feb 2025 10:12:31 +0900 Subject: [PATCH 1/3] docs(swagger): add ui/raws description, hint --- content/openapi/introduction.md | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/content/openapi/introduction.md b/content/openapi/introduction.md index 98547ca48a..abdb5dd304 100644 --- a/content/openapi/introduction.md +++ b/content/openapi/introduction.md @@ -174,12 +174,30 @@ export interface SwaggerCustomOptions { useGlobalPrefix?: boolean; /** - * If `false`, only API definitions (JSON and YAML) will be served (on `/{path}-json` and `/{path}-yaml`). - * This is particularly useful if you are already hosting a Swagger UI somewhere else and just want to serve API definitions. + * 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`. + * @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. + * If omitted or set to an empty array, no definitions (JSON or YAML) will be served. + * Use this option to control the availability of Swagger-related endpoints. + * Default: `true`. + */ + raw?: boolean | Array<'json' | 'yaml'>; + + /** * Url point the API definition to load in Swagger UI. */ @@ -270,6 +288,20 @@ export interface SwaggerCustomOptions { } ``` +> info **Hint** `ui` and `raw` are independent options. Disabling Swagger UI (`ui: false`) does not disable API definitions (JSON/YAML). +> Conversely, disabling API definitions (`raw: []`) does not disable the Swagger UI. +> +> For example, the following configuration will disable the Swagger UI but still allow access to API definitions: +> ```typescript +>const options: SwaggerCustomOptions = { +> ui: false, // Swagger UI is disabled +> raw: ['json'], // JSON API definition is still accessible (YAML is disabled) +>}; +>SwaggerModule.setup('api', app, options); +> ``` +> +> In this case, http://localhost:3000/api-json will still be accessible, but http://localhost:3000/api (Swagger UI) will not. + #### Example From c83e0a386c2964947401de6ee996be7847b94807 Mon Sep 17 00:00:00 2001 From: Kamil Mysliwiec Date: Wed, 19 Feb 2025 09:52:52 +0100 Subject: [PATCH 2/3] Update content/openapi/introduction.md --- content/openapi/introduction.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/openapi/introduction.md b/content/openapi/introduction.md index abdb5dd304..42071e5453 100644 --- a/content/openapi/introduction.md +++ b/content/openapi/introduction.md @@ -197,7 +197,6 @@ export interface SwaggerCustomOptions { */ raw?: boolean | Array<'json' | 'yaml'>; - /** * Url point the API definition to load in Swagger UI. */ From 86957d07bd0a842a6abc75060c8af21cd171c6c1 Mon Sep 17 00:00:00 2001 From: Kamil Mysliwiec Date: Wed, 19 Feb 2025 09:53:41 +0100 Subject: [PATCH 3/3] Update content/openapi/introduction.md --- content/openapi/introduction.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/content/openapi/introduction.md b/content/openapi/introduction.md index 42071e5453..5f1effa02b 100644 --- a/content/openapi/introduction.md +++ b/content/openapi/introduction.md @@ -287,8 +287,7 @@ export interface SwaggerCustomOptions { } ``` -> info **Hint** `ui` and `raw` are independent options. Disabling Swagger UI (`ui: false`) does not disable API definitions (JSON/YAML). -> Conversely, disabling API definitions (`raw: []`) does not disable the Swagger UI. +> info **Hint** `ui` and `raw` are independent options. Disabling Swagger UI (`ui: false`) does not disable API definitions (JSON/YAML). Conversely, disabling API definitions (`raw: []`) does not disable the Swagger UI. > > For example, the following configuration will disable the Swagger UI but still allow access to API definitions: > ```typescript