简体   繁体   中英

How can I generate several api classes with OpenApi maven plugin?

I have a Swagger file and the Maven plugin generates a big API class for me. How would I have to set the plugin to create one endpoint per API class?

The current config of the plugin is:

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>4.2.0</version>
                <executions>
                    <execution>
                        <id>swagger-codegen-fbs4me</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/openapi/CarAPI_v0.2.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <library>spring-boot</library>
                            <skipValidateSpec>true</skipValidateSpec>
                            <configHelp>false</configHelp>
                            <templateDirectory>${project.basedir}/src/main/resources/templates</templateDirectory>
                            <configOptions>
                                <delegatePattern>false</delegatePattern>
                                <apiPackage>com.ger.car.somewhere.clients</apiPackage>
                                <modelPackage>com.ger.car.somewhere.model</modelPackage>
                                <dateLibrary>java8</dateLibrary>
                                <java8>true</java8>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

To make openAPI generator generate one client class per endpoint you could try having separate tags for the endpoints in your openapi spec, this method can create separate API client classes. IE:

/myEndpoint/{myParam}/:
parameters:
  - name: myParam
    in: path
    required: true
    schema:
      type: string
get:
  tags:
    - {unique tag for this endpoint}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM