Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swagger): add documentsEnabled option to disable JSON/YAML #3185

Merged

Conversation

mag123c
Copy link
Contributor

@mag123c mag123c commented Nov 24, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Currently, the Swagger module always serves both Swagger UI and JSON/YAML API definitions. There is no way to selectively disable one or the other.

Issue Number: #3157

What is the new behavior?

This PR introduces two new options to provide greater control over Swagger endpoints:

swaggerUiEnabled: If false, the Swagger UI will not be served.
documentsEnabled: If false, JSON and YAML API definitions will not be served.

Developers can now:

  1. Disable the Swagger UI but retain JSON/YAML definitions.
  2. Disable JSON/YAML definitions but retain the Swagger UI.
  3. Completely disable all Swagger-related endpoints.

These changes enhance the flexibility and security of Swagger integration, enabling better alignment with deployment needs.

JSON/YAML is not provided as below when documentEnabled is set to FALSE.

image
image

Does this PR introduce a breaking change?

  • Yes
  • No

* Use this option when you want to completely hide all Swagger-related endpoints.
* Default: `true`.
*/
documentsEnabled?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
documentsEnabled?: boolean;
raw?: boolean | Array<'json' | 'yaml'>;

could we rename it to "raw"? raw: true means, @nestjs/swagger will serve raw definitions. We could also allow passing an array that determines what formats should be served, e.g. raw: ['json'] (meaning, no yaml).

@kamilmysliwiec kamilmysliwiec merged commit 3b51f1d into nestjs:master Dec 4, 2024
1 check passed
@kamilmysliwiec
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants