Skip to content

Conversation

@jpfinne
Copy link
Contributor

@jpfinne jpfinne commented Sep 25, 2025

Fix #22027 by adding an option version attribute to the @RequestMapping annotation.

Add springApiVersion configOption
Add x-spring-api-version vendorExtensions on operation to override or disable the default

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08)

@jpfinne jpfinne marked this pull request as ready for review September 25, 2025 14:43
@jpfinne jpfinne changed the title [SPRING] add support for api versioning. Fix #22027 [Spring] add support for api versioning. Fix #22027 Sep 25, 2025
operation.vendorExtensions.put("versionQueryParamsList", versionParams);
}
if (hasApiVersion) {
if (!operation.vendorExtensions.remove(VendorExtension.X_SPRING_API_VERSION.getName(), "")) {
Copy link
Member

Choose a reason for hiding this comment

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

thanks for the Pr

quick question: why do you need to remove the extension? wouldn't the next line using putIfAbsent be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal is to remove the version attribute per operation.

For example:

/help:
  get:
    x-spring-api-version: ''

generates:

   @RequestMapping(
        method = RequestMethod.GET,
        value = TestApi.PATH_GET_HELP
    )

I've fixed the implementation and the unit test.

Copy link
Member

Choose a reason for hiding this comment

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

👌

if no further question/feedback from anyone, i'll merge it later this week

@wing328 wing328 merged commit d7b79a2 into OpenAPITools:master Oct 3, 2025
14 checks passed
@wing328 wing328 changed the title [Spring] add support for api versioning. Fix #22027 [Spring] add support for api versioning Oct 3, 2025
@wing328 wing328 added this to the 7.17.0 milestone Oct 3, 2025
rajvesh pushed a commit to rajvesh/openapi-generator that referenced this pull request Dec 25, 2025
…APITools#22028)

* Add spring api versioning support

* Do not add version if not requested

* Fix duplicate VendorExtensions

* Improve description

* Fix removal of RequestMapping version attribute if x-spring-api-version: '' is set at the operation level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQ] [SPRING] support for api versioning in spring 7

2 participants