OpenAPITools / OpenAPITools/openapi-generator

[REQ][Spring] Be able to filter with API version

Open
#8,545 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

I need to generate multiple versions of an API handled by the same service. The version can be provided by a custom header or a custom query param. So I can't use Media-type tricks.

My need is to use the spring capacity of filtering (example can be found here).

This will allow us to generate and deploy each version of each contract without conflict and manage.

Describe the solution you'd like

I want to be able to do something like this

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>5.0.1-SNAPSHOT</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>src/main/resources/openapi.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <apiPackage>org.openapitools.api</apiPackage>
                            <modelPackage>org.openapitools.model</modelPackage>
                            <generateSupportingFiles>false</generateSupportingFiles>
                            <configOptions>
                                <versionType>HEADER</versionType>
                                <versionToken>X-CUSTOM-VERSION</versionToken>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

and get

    @GetMapping(
        value = "/ponies",
        produces = { "application/json" },
        headers = "X-CUSTOM-VERSION=1.0.0"
    )

Describe alternatives you've considered

Media-type and path have been excluded. I don't manage to specify this kind of filtering directly in the OAS3 file.

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Spring generator entry point and the Maven plugin configuration shown in the issue, using openapi.yaml as the input. Check how configOptions are passed to the generator and how generated @GetMapping annotations are produced. Done means HEADER and X-CUSTOM-VERSION result in version-filtered mappings like the requested example, with generator coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.