Skip to content

feat: Add login endpoint configuration with example values for username and password - #3323

Merged
bnasslahsen merged 2 commits into
springdoc:mainfrom
Mattias-Sehlstedt:configure-spring-login-example
Sep 6, 2026
Merged

feat: Add login endpoint configuration with example values for username and password#3323
bnasslahsen merged 2 commits into
springdoc:mainfrom
Mattias-Sehlstedt:configure-spring-login-example

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Adds two new configuration properties that let users define example values for the username and password fields of the auto-generated Spring Security login endpoint, so those examples show up in the OpenAPI document and Swagger UI "Try it out" form.

New configuration properties

Property Description
springdoc.login-endpoint.username-example Example value applied to the username field of the login request body.
springdoc.login-endpoint.password-example Example value applied to the password field of the login request body.

Example:

springdoc.show-login-endpoint=true
springdoc.login-endpoint.username-example=demouser
springdoc.login-endpoint.password-example=secret

The new app13 tests are copied from the existing app6 tests to showcase that the previous behavior with springdoc.show-login-endpoint=true is not affected.

Fixes: #3321

An alternative design would be a single boolean flag (e.g. springdoc.login-endpoint.show-credentials=true) that reads the application's actual configured username/password (such as spring.security.user.name / spring.security.user.password) and injects them as examples. That was deliberately not chosen, as a separation of concerns as well as a safety measure.

Documentation examples are a documentation concern; they should not be coupled to, or reach into, security configuration internals. Such a solution could easily result in the user setting the property to true in the root application.properties, and it thus affecting the prod settings too. This solution forces the user to specify the exact credentials, which could only do harm if the user has the same credentials in test and prod.

@bnasslahsen
bnasslahsen merged commit ccb2fc0 into springdoc:main Sep 6, 2026
1 check passed
@bnasslahsen

Copy link
Copy Markdown
Collaborator

Merged, thanks @Mattias-Sehlstedt.

Two small follow-ups on top of your commit:

  • realigned the buildRequestBody continuation line to the 4-tab continuation indent Spring JavaFormat uses (it was aligned visually on the opening paren);
  • recorded the feature in CHANGELOG.md under 3.1.1.

The same feature is being backported to the spring-boot-3 line for 2.9.1.

@Mattias-Sehlstedt
Mattias-Sehlstedt deleted the configure-spring-login-example branch September 6, 2026 11:50
bnasslahsen added a commit that referenced this pull request Sep 6, 2026
Backport of #3323, which resolves #3321.

`springdoc.login-endpoint.username-example` and
`springdoc.login-endpoint.password-example` set the example shown for
the generated login endpoint. Both are optional: when unset the endpoint
is documented exactly as before.

Co-Authored-By: Mattias Sehlstedt <mattias.sehlstedt@gmail.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bnasslahsen added a commit that referenced this pull request Sep 6, 2026
…e fixes

Backports to the Spring Boot 3 line:
- #3323 / #3321 - login endpoint example values
- #3317 - ignore an injected HttpHeaders parameter
- the shared-schema fix on top of the #3136 backport
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.

Support adding example values to the Spring Security login endpoint.

2 participants