How to handle multiple base paths in OpenAPI when generating code

76 views Asked by At

I have the following OpenAPI specification:

openapi: 3.0.3
info:
 ...

paths:
 /a1/persons:
 /a1/addresses:
 /a1/posts
   ...
 /a2/persons:
 /a2/comments
   ...

Given the following OpenAPI maven plugin:


<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>6.6.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>
                   ${project.basedir}/src/main/resources/openapi/api.yaml
                </inputSpec>
                <generatorName>spring</generatorName>
                <apiPackage>com.redacted.api</apiPackage>
                <modelPackage>com.redacted.api.model</modelPackage>
                <configOptions>
                    <interfaceOnly>true</interfaceOnly>
                    <language>spring</language>
                    <useBeanValidation>true</useBeanValidation>
                    <performBeanValidation>false</performBeanValidation>
                    <useJakartaEe>true</useJakartaEe>
                    <apiPackage>com.redacted.controller</apiPackage>
                    <serializableModel>true</serializableModel>
                    <documentationProvider>springdoc</documentationProvider>
                    <useSpringBoot3>true</useSpringBoot3>
                    <generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
                    <additionalModelTypeAnnotations>@lombok.Builder @lombok.NoArgsConstructor @lombok.AllArgsConstructor</additionalModelTypeAnnotations>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

When I run the Maven build, the plugin generates two API Interfaces:

  • A1Api
  • A2Api

Instead of generating multiple interfaces, such as PersonsApi etc. Ideally, I would like the plugin to generate interfaces named after the basePath, like so: A1Persons, A2Persons and so on.

Is there a way to achieve that?

0

There are 0 answers