Repository navigation
feat: make the Swagger UI optional, off by default - #80
Conversation
The Swagger UI and its static resources are to be off by default and to be turned on with tesk.api.swagger-ui.enabled; the API description stays available either way. Fails until the setting exists. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The setting tesk.api.swagger-ui.enabled (TESK_API_SWAGGER_UI_ENABLED, default false) turns the Swagger UI on, with its static resources and the redirect from the root path. The API description (/v2/api-docs) is served either way. As the app has no static resources of its own, Spring Boot's static resource mappings follow the same setting. The smoke test checks both states of the setting in the image, and waits for the API description, which is built after the app answers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Springfox maps /swagger-resources/** regardless of its own UI setting. Without the Swagger UI, leave out its controller as well, so that these paths answer 404 like the rest of the UI. Tests and the smoke test cover them; the path constants move to UrlConstants. The upgrade notes say that turning the UI on serves it publicly, and that the Helm chart of TESK has no value for the setting yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Spring and Springfox read other spellings of booleans (off, yes, 0) differently, which would serve only some of the UI. The app now fails to start on any value of tesk.api.swagger-ui.enabled other than true or false, and leaves out the UI configuration by the same reading. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideIntroduces an opt-in Swagger UI controlled by Sequence diagram for Swagger UI configuration at startupsequenceDiagram
participant App as Spring application
participant Condition as SwaggerUiDisabledCondition
participant Springfox as Springfox
participant Resources as Static resource mappings
App->>Condition: matches()
alt property is false or unset
Condition-->>App: true
App->>Springfox: removeSwaggerUiResources()
App->>Resources: disable mappings
else property is true
Condition-->>App: false
App->>Springfox: keep Swagger UI resources
App->>Resources: enable mappings
else property is invalid
Condition-->>App: throw IllegalArgumentException
end
State diagram for Swagger UI availabilitystateDiagram-v2
[*] --> Disabled: unset or false
[*] --> Enabled: true
[*] --> StartupFailure: invalid value
Disabled --> Disabled: /swagger-ui/index.html, /swagger-resources, / return 404
Disabled --> Disabled: /v2/api-docs returns 200
Enabled --> Enabled: / redirects to Swagger UI
Enabled --> Enabled: Swagger UI resources return 200
Enabled --> Enabled: /v2/api-docs returns 200
Flow diagram for optional Swagger UI routingflowchart TD
Setting{TESK_API_SWAGGER_UI_ENABLED}
Setting -->|false or unset| Disabled[Swagger UI mappings disabled]
Setting -->|true| Enabled[Swagger UI mappings enabled]
Setting -->|invalid value| Startup[Application startup fails]
Disabled --> NotFound[Swagger UI paths return 404]
Enabled --> Redirect[GET / redirects to /swagger-ui/index.html]
Enabled --> Resources[Swagger UI and /swagger-resources served]
Setting --> ApiDocs["/v2/api-docs served in either mode"]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #80 +/- ##
==========================================
+ Coverage 55.94% 56.29% +0.35%
==========================================
Files 64 66 +2
Lines 2152 2167 +15
Branches 234 236 +2
==========================================
+ Hits 1204 1220 +16
+ Misses 807 806 -1
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerUiDisabledConfiguration.java" line_range="32-35" />
<code_context>
+ @Override
+ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
+ Arrays.stream(registry.getBeanDefinitionNames())
+ .filter(name -> ApiResourceController.class.getName()
+ .equals(registry.getBeanDefinition(name).getBeanClassName()))
+ .forEach(registry::removeBeanDefinition);
+ }
+
+ @Override
</code_context>
<issue_to_address>
**OAuth client secret remains public**
When the `auth` profile is active, the UI setting is false, and a client secret is configured, the disabled configuration removes only `ApiResourceController`, leaving Springfox’s `/configuration/security` handler available; `ResourceServerConfiguration` permits `/configuration/**`, so an unauthenticated caller can retrieve the `SecurityConfiguration` response containing the configured client secret.
Ensure `/configuration/security` is not mapped or permitted while the UI is disabled, and do not expose a confidential client secret through a public endpoint.
</issue_to_address>Linked issues
#79 feat: make the Swagger UI optional, off by default · 4 of 4 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | The Swagger UI and its static resources are off by default and can be turned on with a documented setting. | ✅ Met | The setting defaults to false, controls the UI and static resource mappings, and is documented in the configuration reference. |
| 2 | The OpenAPI document itself stays available. | ✅ Met | The API description remains available regardless of the setting, with integration tests checking both disabled and enabled states. |
| 3 | Tests cover the setting on and off. | ✅ Met | Integration tests check UI paths and the root path with the setting enabled and disabled. |
| 4 | The configuration reference and the upgrade notes describe the change. | ✅ Met |
Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerUiDisabledConfiguration.java:35
Summary
Closes #79.
tesk.api.swagger-ui.enabled(TESK_API_SWAGGER_UI_ENABLED),falseby default. When it istrue, the app serves the Swagger UI at/swagger-ui/index.html, its static resources and its configuration (/swagger-resources/**), and/redirects to it, as before. When it isfalse, all of these paths answer 404./v2/api-docs) is served either way, also without a token with theauthprofile.springfox.documentation.swagger-ui.enabledand Spring Boot'sspring.web.resources.add-mappings. The app has no static resources of its own, so/webjars/**and/**follow the UI.HomeControlleris conditional on the setting./swagger-resources/**regardless of its own UI setting, soSwaggerUiDisabledConfigurationleaves that controller out when the setting is off.trueorfalse(ignoring case) stop the app at startup. Spring and Springfox read spellings likeofforyesdifferently, which would serve only part of the UI./v2/api-docs, which is built just after the app starts answering; the immediate check was flaky locally.auth, and that the Helm chart of TESK has no value for the setting yet.Verified
./mvnw clean verifyon JDK 8 (Docker,eclipse-temurin:8-jdk): 111 unit and 53 integration tests pass. The newSwaggerUi*ITtests failed before the change (UI 200 and/302 with the default settings) and again withoutSwaggerUiDisabledConfiguration(/swagger-resources200).TESK_API_SWAGGER_UI_ENABLED=offfails to start, with a message naming the setting.ci.ymlagainst the built image (on another port): passes.mkdocs build --strict: clean.adversarial-reviewerandquality-reviewer, two rounds.Declined review findings
SwaggerUi*ITclasses, or share the Kubernetes client mock: they follow the repo's pattern of one property set per class (asServiceInfo*IT), and each property set needs its own Spring context anyway.ResourceServerConfiguration's public list depend on the setting: unmapped paths answer 404 either way, and the tests cover that. There is a comment on the list now.🤖 Generated with Claude Code
Summary by Sourcery
Make the Swagger UI opt-in while keeping the API description available in all configurations.
New Features:
Bug Fixes:
Enhancements:
CI:
Documentation: