4

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>

2 Answers 2

2

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>.

Sign up to request clarification or add additional context in comments.

1 Comment

I did this and the build was successful. However, because sources are generated after the package phase, they are not included in the JAR. How did you accomplish that?
0

I agree with @Gaetitan:

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.

Also on your 3rd plugin, you entered the id format twice with no spaces so it could not generate your correct to run correctly. That should fix your code and make the process run correctly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.