In NestJS, setting ui to false in SwaggerModule.setup hides the Swagger UI page but leaves the JSON and YAML definitions reachable. Setting raw to false removes the definitions. To hide everything, use raw false, which the NestJS docs say disables both the UI and the definitions.
The trap
Many teams switch off the interface and assume the job is done. The NestJS documentation states that ui and raw are independent options. If you set only ui to false, a scanner or an attacker can still read the full description from the raw path.
With a mount path of api, the defaults are:
| Output | Default location |
|---|---|
| Swagger UI | /api |
| JSON definition | /api-json |
| YAML definition | /api-yaml |
You can move the JSON location with jsonDocumentUrl.
Options compared
| Setting | UI served | JSON and YAML served |
|---|---|---|
| defaults | yes | yes |
| ui: false | no | yes |
| ui: false, raw: ['json'] | no | JSON only |
| raw: false | no | no |
SwaggerModule.setup('api', app, document, {
ui: false,
raw: false,
});
The older swaggerUiEnabled option is deprecated in favor of ui, so check your code for it on upgrade.
Steps
- Find every SwaggerModule.setup call. Large apps sometimes register more than one.
- Gate the options with an environment check so production passes raw false.
- Deploy and request /api, /api-json and /api-yaml from outside.
- Expect failures on all three.
- Add a test to your pipeline that asserts those paths do not return 200.
- If you need the spec for tooling, generate it at build time and store the file, instead of serving it from the running app.
How to confirm which option you used
Open the browser, request the mount path and then request the JSON path separately. The two answers tell you which of the independent options you set. A page that loads on the first and a file that downloads on the second means both are on. A blank on the first and a file on the second means only ui is off, which is the common half fix.
Related details worth knowing
The package that powers this, @nestjs/swagger, is a dependency like any other. It should appear in your software inventory and be kept current. Also, the NestJS note on content security policy means turning the UI on over plain HTTP outside local development may need CSP changes, another reason to leave it off in production.
For the bigger decision of whether public docs make sense for you, read should Swagger UI be exposed in production.
Try it yourself
Click through it at your own pace, or open it full screen. See how a scan treats each documented route.
Safeguard's SBOM and dependency scanning covers npm packages such as @nestjs/swagger, and a free scan is available.
Quick check
I set ui to false. Can people still read my API description?
Yes, unless you also restrict raw. The definitions at the JSON and YAML paths stay available.
What is the one setting that hides everything?
raw set to false, according to the NestJS reference, disables both the UI and the definitions.
Sources
Last reviewed: 19 October 2026.