Swagger Codegen 从 OpenAPI 文件生成代码。反之亦然——从 Java 代码注释生成 OpenAPI 文件——你需要Swagger Core,例如它的 Maven 插件,swagger-maven-plugin
.
将以下依赖项添加到您的pom.xml
:
<dependencies>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
然后在你的构建中使用它;示例配置:
<plugins>
<plugin>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.0.9</version>
<configuration>
<outputFileName>openapi</outputFileName>
<outputPath>${project.build.directory}/generatedtest</outputPath>
<configurationFilePath>${project.basedir}/src/main/resources/configurationFile.yaml</configurationFilePath>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>