Skip to content

Commit 812a455

Browse files
authored
docs: improve changing Swagger UI location (#1604)
1 parent 4e126dc commit 812a455

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

core/openapi.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,30 +420,58 @@ resources:
420420

421421
![Impact on Swagger UI](../distribution/images/swagger-ui-2.png)
422422

423-
## Changing the Location of Swagger UI
424-
425-
Sometimes you may want to have the API at one location, and the Swagger UI at a different location. This can be done by disabling the Swagger UI from the API Platform configuration file and manually adding the Swagger UI controller.
423+
## Disabling Swagger UI or ReDoc
426424

427-
### Disabling Swagger UI or ReDoc
425+
To disable Swagger UI (ReDoc will be shown by default):
428426

429427
```yaml
430428
# api/config/packages/api_platform.yaml
431429
api_platform:
432430
# ...
433431
enable_swagger_ui: false
432+
```
433+
434+
To disable ReDoc:
435+
436+
```yaml
437+
# api/config/packages/api_platform.yaml
438+
api_platform:
439+
# ...
434440
enable_re_doc: false
435441
```
436442
437-
### Manually Registering the Swagger UI Controller
443+
## Changing the Location of Swagger UI
444+
445+
By default, the Swagger UI is available at the API location (when the HTML format is asked) and at the route `/docs`.
446+
447+
You may want to change its route and/or disable it at the API location.
448+
449+
### Changing the Route
450+
451+
Manually register the Swagger UI controller:
438452

439453
```yaml
440454
# app/config/routes.yaml
441-
swagger_ui:
442-
path: /docs
455+
api_doc:
456+
path: /api_documentation
443457
controller: api_platform.swagger.action.ui
444458
```
445459

446-
Change `/docs` to the URI you wish Swagger to be accessible on.
460+
Change `/api_documentation` to the URI you wish Swagger UI to be accessible on.
461+
462+
### Disabling Swagger UI at the API Location
463+
464+
To disable the Swagger UI at the API location, disable both Swagger UI and ReDoc:
465+
466+
```yaml
467+
# api/config/packages/api_platform.yaml
468+
api_platform:
469+
# ...
470+
enable_swagger_ui: false
471+
enable_re_doc: false
472+
```
473+
474+
If you have manually registered the Swagger UI controller, the Swagger UI will still be accessible at the route you have chosen.
447475

448476
## Using a custom Asset Package in Swagger UI
449477

0 commit comments

Comments
 (0)