Skip to content

[REQ] MergedSpecBuilder load servers urls from input specs #21965

@rodrigoma3

Description

@rodrigoma3

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

I recently needed to split a spec into multiple specs and generate code for each one to keep the API working.
I replaced the inputSpec option with inputSpecRootDirectory and experienced an impact on the context path.
Using the inputSpecRootDirectory option with requestMappingMode to generate code for many specs, I noticed that the context path "gets lost" because in the MergedSpecBuilder a url is fixed, link here and code shown below.

map.put("servers", Collections.singleton(
        ImmutableMap.of("url", "http://localhost:8080")
));

If you use the inputSpec option for a specific spec, it will generate the RequestMapping with the correct context path, code shown below.

@RequestMapping("${openapi.myProject.base-path:/my-context-root/v1}")

If you use the inputSpecRootDirectory option, it will generate the RequestMapping without the context path, code shown below.

@RequestMapping("${openapi.mergedSpec.base-path:}")

Describe the solution you'd like

I'd like code generation using inputSpecRootDirectory to consider the URLs of the specs' servers, because if they're configured, they're important to maintain.
If a URL is configured on the server along with a context path, the entire API will use that context path. At least, that's how it works when using inputSpec, and it makes sense to me.
Using inputSpecRootDirectory, we lose this and need to add the context path to each path. If we do this, we can't put the context path on the server to avoid confusing anyone reading the API documentation.
Another way to keep the context path on the server, not in the paths, and keep the API working with the context path, is to add the property openapi.mergedSpec.base-path=/my-context-root/v1 to application.properties. This way, we'll be spreading the context path configuration across the spec and project properties, just like if we create an option to set the context path for the merged spec in pom.xml.
Specs with different context paths in the same project can no longer use inputSpecRootDirectory with requestMappingMode because it always unifies all APIs to the same context path. This is because the property created to define the context path of the APIs is unique (openapi.mergedSpec.base-path), so my request does not change this behavior. The alternative to this is to use multiple executions, one for each spec.

Describe alternatives you've considered

As mentioned above, there are a few ways to maintain the context path found in the specs:
Using an execution for each spec instead of using inputSpecRootDirectory;
Adding the openapi.mergedSpec.base-path=/my-context-root/v1 property to application.properties;
Not placing the context path on the server and placing it in each path;

Additional context

I found these requests to not use the fixed url. here and here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions