Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(symfony): disable Swagger UI and keep openapi.json #7549

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

Open
Maxcastel wants to merge 7 commits into api-platform:4.2
base: 4.2
Choose a base branch
Loading
from Maxcastel:fix/disable-swagger-ui

Conversation

@Maxcastel
Copy link

@Maxcastel Maxcastel commented Nov 20, 2025
edited
Loading

Q A
Branch? 4.2
Tickets Closes #7544
License MIT
Doc PR na

Descripton

This PR fixes an issue where enable_swagger_ui: false did not actually disable the Swagger UI HTML interface.

Currently, when configuring enable_swagger: true and enable_swagger_ui: false, accessing the documentation route (/api/docs), still displays the Swagger UI HTML interface, ignoring the configuration (enable_swagger_ui: false) to disable it.

The goal is to fully disable the Swagger UI HTML interface while keeping the JSON documentation (/api/docs.jsonopenapi) accessible.

Changes

  • Modified ApiPlatformExtension to load Swagger UI services (definitions, listeners, providers) only if enable_swagger_ui is true.
  • Updated src/Symfony/Action/DocumentationAction.php to throw a NotFoundHttpException when Swagger UI is disabled.

src/Laravel/Controller/DocumentationController::getOpenApiDocumentation() :

if ('html' === $format && $this->swaggerUiEnabled) {
 $operation = $operation->withProcessor('api_platform.swagger_ui.processor')->withWrite(true);
}

src/Symfony/Action/DocumentationAction::getOpenApiDocumentation() :

if ('html' === $format) {
 $operation = $operation->withProcessor('api_platform.swagger_ui.processor')->withWrite(true);
}
  • Updated src/Symfony/Action/DocumentationAction.php to check enable_swagger_ui, aligning the logic with src/Laravel/Controller/DocumentationController.php :
- if ('html' === $format) {
+ if ('html' === $format && $this->swaggerUiEnabled) {
 $operation = $operation->withProcessor('api_platform.swagger_ui.processor')->withWrite(true);
}
  • Added unit & functional tests (using a custom Kernel to handle dynamic configuration) to cover these scenarios.

Before

api_platform:
 enable_swagger: true
 enable_swagger_ui: false
  • /api/docs → still HTML Swagger UI accessible (not expected)
  • /api/docs.jsonopenapi → accessible (expected)

After

api_platform:
 enable_swagger: true
 enable_swagger_ui: false
  • /api/docs → returns 404
  • /api/docs.jsonopenapi → still accessible (expected)
Route Format Before After
/api/docs HTML 200 OK (UI Visible) 404 Not Found
/api/docs.jsonopenapi JSON 200 OK 200 OK

Copy link
Member

soyuka commented Nov 21, 2025

would you be able to add a functional test as well?

@Maxcastel Maxcastel changed the title (削除) fix(swagger): disable Swagger UI and keep openapi.json (削除ここまで) (追記) fix(symfony): disable Swagger UI and keep openapi.json (追記ここまで) Nov 23, 2025
@Maxcastel Maxcastel force-pushed the fix/disable-swagger-ui branch 2 times, most recently from 0b808c1 to cf6078d Compare November 24, 2025 12:53
Copy link
Author

done @soyuka
I will squash commits.

@Maxcastel Maxcastel marked this pull request as ready for review November 24, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /