Skip to content

feat: make the Swagger UI optional, off by default - #80

Merged
uniqueg merged 5 commits into
devfrom
feat/swagger-ui-setting
Nov 6, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/swagger-ui-setting

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #79.

  • New setting tesk.api.swagger-ui.enabled (TESK_API_SWAGGER_UI_ENABLED), false by default. When it is true, 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 is false, all of these paths answer 404.
  • The API description (/v2/api-docs) is served either way, also without a token with the auth profile.
  • How it works:
    • The setting drives Springfox's springfox.documentation.swagger-ui.enabled and Spring Boot's spring.web.resources.add-mappings. The app has no static resources of its own, so /webjars/** and /** follow the UI.
    • HomeController is conditional on the setting.
    • Springfox maps /swagger-resources/** regardless of its own UI setting, so SwaggerUiDisabledConfiguration leaves that controller out when the setting is off.
  • Values other than true or false (ignoring case) stop the app at startup. Spring and Springfox read spellings like off or yes differently, which would serve only part of the UI.
  • Smoke test: checks both states of the setting in the image. It now waits for /v2/api-docs, which is built just after the app starts answering; the immediate check was flaky locally.
  • Docs:
    • Configuration reference: the new setting.
    • API page: a new Swagger UI section.
    • Access control, deployment and README: updated.
    • Upgrade notes: under 1.2.0, this is a change for deployments that use the Swagger UI. The notes say that turning it on serves it publicly, also with auth, and that the Helm chart of TESK has no value for the setting yet.

Verified

  • ./mvnw clean verify on JDK 8 (Docker, eclipse-temurin:8-jdk): 111 unit and 53 integration tests pass. The new SwaggerUi*IT tests failed before the change (UI 200 and / 302 with the default settings) and again without SwaggerUiDisabledConfiguration (/swagger-resources 200).
  • The image with TESK_API_SWAGGER_UI_ENABLED=off fails to start, with a message naming the setting.
  • Smoke script of ci.yml against the built image (on another port): passes.
  • actionlint 1.7.7: clean. mkdocs build --strict: clean.
  • Full review: adversarial-reviewer and quality-reviewer, two rounds.
  • CI on this PR: all checks pass (Test, Smoke test, Scan image, Docs, Lint, CodeQL, Codecov).

Declined review findings

  • Merge the four SwaggerUi*IT classes, or share the Kubernetes client mock: they follow the repo's pattern of one property set per class (as ServiceInfo*IT), and each property set needs its own Spring context anyway.
  • Make the paths in 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:

  • Add a configuration setting to enable the Swagger UI and its supporting resources when needed.

Bug Fixes:

  • Keep the API description publicly available while preventing partially disabled Swagger UI endpoints and rejecting ambiguous setting values.

Enhancements:

  • Make the Swagger UI disabled by default and conditionally expose its homepage, static resources, and configuration endpoints.
  • Expand integration and unit coverage for Swagger UI behavior across enabled, disabled, and authenticated configurations.

CI:

  • Update image smoke tests to verify both default-disabled and explicitly enabled Swagger UI behavior and wait for the API description before testing.

Documentation:

  • Document the new Swagger UI setting, access-control implications, deployment usage, and upgrade impact.

uniqueg and others added 5 commits November 6, 2026 14:57
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]>
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]>
@sourcery-ai

sourcery-ai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces an opt-in Swagger UI controlled by TESK_API_SWAGGER_UI_ENABLED, defaulting to off while preserving public API documentation; conditional Spring/Springfox configuration, integration and smoke tests, and deployment documentation cover both enabled and disabled modes.

Sequence diagram for Swagger UI configuration at startup

sequenceDiagram
    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
Loading

State diagram for Swagger UI availability

stateDiagram-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
Loading

Flow diagram for optional Swagger UI routing

flowchart 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"]
Loading

File-Level Changes

Change Details Files
Made Swagger UI exposure configurable and disabled by default while keeping the API description public.
  • Added the tesk.api.swagger-ui.enabled / TESK_API_SWAGGER_UI_ENABLED setting with strict true/false validation and wiring to Springfox and Spring static-resource mappings.
  • Conditionally enabled the home redirect and removed Springfox’s Swagger resource controller when the UI is disabled.
  • Kept /v2/api-docs available in both profiles and configurations.
  • Added coverage for disabled, enabled, and authenticated behavior, including static resources, redirects, and invalid values.
src/main/resources/application.properties
src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerUiDisabledCondition.java
src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerUiDisabledConfiguration.java
src/main/java/uk/ac/ebi/tsc/tesk/tes/api/HomeController.java
src/main/java/uk/ac/ebi/tsc/tesk/config/security/ResourceServerConfiguration.java
src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerUiDisabledConditionTest.java
src/integration-test/java/uk/ac/ebi/tsc/tesk/SwaggerUiAuthIT.java
src/integration-test/java/uk/ac/ebi/tsc/tesk/SwaggerUiDisabledIT.java
src/integration-test/java/uk/ac/ebi/tsc/tesk/SwaggerUiEnabledAuthIT.java
src/integration-test/java/uk/ac/ebi/tsc/tesk/SwaggerUiEnabledIT.java
src/test/java/uk/ac/ebi/tsc/tesk/UrlConstants.java
Updated CI smoke validation to exercise both Swagger UI states and wait for the API description to be ready.
  • Changed readiness polling to /v2/api-docs and retained API endpoint checks under the base path.
  • Verified that disabled mode returns 404 for UI, static-resource, configuration, and root paths while /v2/api-docs remains 200.
  • Verified that enabling the setting serves the UI and Swagger resources.
.github/workflows/ci.yml
Updated user-facing documentation and upgrade guidance for the opt-in Swagger UI behavior.
  • Documented the new configuration and public exposure implications, including auth deployments.
  • Updated README and deployment instructions to explicitly opt in to the UI.
  • Separated API description documentation from the Swagger UI documentation and clarified access-control behavior.
  • Added 1.2.0 upgrade notes, including the current Helm chart limitation.
README.md
docs/access-control.md
docs/api.md
docs/configuration.md
docs/deployment.md
docs/upgrading.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.29%. Comparing base (d60f190) to head (6cc2f7d).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 6, 2026 14:59

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit 6411597 into dev Nov 6, 2026
40 of 43 checks passed
@uniqueg
uniqueg deleted the feat/swagger-ui-setting branch November 6, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: make the Swagger UI optional, off by default

1 participant