java 在项目的构建过程中使用springdoc-openapi-maven-plugin生成文档的问题

gc0ot86w  于 2023-06-28  发布在  Java
关注(0)|答案(1)|浏览(183)

我使用springdoc-openapi-maven-plugin在mvn clean install命令期间生成document_name.json文件,具有以下插件配置:

<plugin>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-maven-plugin</artifactId>
    <version>0.2</version>
    <executions>
        <execution>
            <phase>integration-test</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration> 
        <outputFileName>sentinel-openapi.json</outputFileName> 
        <outputDir>${project.build.directory/../../openapi-doc/}</outputDir> 
    </configuration>
    </plugin>

此外,我还使用spring-boot-maven-plugin在集成测试期间启动和停止应用程序:

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <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>

但是,我需要使用./mvnw package命令生成相同的document_name.json文件。如何配置springdoc-openapi-maven-pluginspring-boot-maven-plugin以实现此目标?

6rqinv9w

6rqinv9w1#

默认情况下,springdoc-openapi-maven-plugin在端口8080中生成API文档(假设应用程序在8080上运行),如果应用程序运行的端口不同,则必须在openapi-maven-plugin的配置标记中指定apiDocsUrl

<plugin>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-maven-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <id>integration-test</id>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <apiDocsUrl>http://localhost:{YourApplicationPort}/v3/api-docs</apiDocsUrl>
        <outputFileName>swagger.json</outputFileName>
    </configuration>
</plugin>

相关问题