简体   繁体   中英

How to generate client code using springdoc-openapi-maven-plugin and swagger-codegen-maven-plugin?

My goal is to generate Spring Boot REST Client using OpenAPI 3.0 .

I would like to first generate the OpenAPI specification file (springdoc-openapi-maven-plugin) of my API and then generate the client code from this file (swagger-codegen-maven-plugin) using Maven.

My problem is that swagger-codegen-maven-plugin is executed before springdoc-openapi-maven-plugin . So, the output file generated by springdoc-openapi-maven-plugin does not exist when swagger-codegen-maven-plugin executes.

How to execute springdoc-openapi-maven-plugin before swagger-codegen-maven-plugin given the following Maven build plugins configuration?

My Maven build plugin configuration:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.1</version>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springdoc</groupId>
                <artifactId>springdoc-openapi-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <apiDocsUrl>myServerUrl:myPort/v3/api-docs</apiDocsUrl>
                    <outputFileName>openApiFile.json</outputFileName>
                    <outputDir>${project.basedir}/src/main/resources</outputDir>
                    <skip>false</skip>
                </configuration>
            </plugin>

            <plugin>
                <groupId>io.swagger.codegen.v3</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>3.0.24</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/openApiFile.json</inputSpec>
                            <language>typescript-angular</language>
                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

The issue was that springdoc-openapi-maven-plugin is executed during integration-test phase while swagger-codegen-maven-plugin default phase is generate-sources which is executed before integration-test in the build lifecycle.

I just specified a phase for swagger-codegen-maven-plugin which is after integration-test : <phase>post-integration-test</phase> .

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