nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.7k stars 477 forks source link

Add option sto disable json and yaml API definition serving #3157

Open wiliamsouza opened 6 days ago

wiliamsouza commented 6 days ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

There is no way to disable json and yaml API definition endpoints.

Describe the solution you'd like

An option like exist for enable or disable swagger UI.

Teachability, documentation, adoption, migration strategy

Some times you do not want to make your API public available for any reason.

What is the motivation / use case for changing the behavior?

I need to create a work around to disable those endpoint:

  const enable = false;

  SwaggerModule.setup("api", app, swaggerDocument(app), {
    swaggerUiEnabled: enable,
    patchDocumentOnRequest: (_req, _res, document) => {
      if (enable) {
        return document;
      }
      return {
        openapi: "3.0.0",
        info: {
          title: "You shall not pass! Just kidding, not found ;D",
          version: "1.0",
        },
        paths: {},
      };
    }
  });
kamilmysliwiec commented 6 days ago

Would you like to create a PR for this issue?