我想使用 swagger 和 maven 插件从我的 restful 应用程序中生成 json-from 中的文档。创建了 json 文件,但是来自 api 的数据以及我的代码的所有描述都丢失了。
这是我的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.baintern.infoplattform</groupId>
<artifactId>infoplattform</artifactId>
<version>1.0</version>
</parent>
<artifactId>infoplattform-services</artifactId>
<name>infoplattform-services</name>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId> 3.2
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.3-M1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.0-alpha4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.3.0-alpha4</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.7</version>
<configuration>
<apiSources>
<apiSource>
<locations>
<location>services.myServices</location>
</locations>
<schemes>
<scheme>http</scheme>
<scheme>https</scheme>
</schemes>
<host>localhost:7001</host>
<basePath>/info-services</basePath>
<info>
<title>Swagger documentation</title>
<version>v1</version>
<description>swagger documentation</description>
<termsOfService>
http://localhost:7001/info-services/
</termsOfService>
<contact>
<email>info.email@domaine.de</email>
<name>Info-Box</name>
<url>https:mydomain.de/</url>
</contact>
<license>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<name>Apache 2.0</name>
</license>
</info>
<swaggerDirectory>generated/swagger-ui</swaggerDirectory>
<swaggerFileName>info-services</swaggerFileName>
<outputFormats>json</outputFormats>
<attachSwaggerArtifact>true</attachSwaggerArtifact>
<swaggerUIDocBasePath>http://localhost:7001/info-services/doc</swaggerUIDocBasePath>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这是我的java代码:
@Path("/themen")
@Api(value = "/themen", description = "Service-Methoden von Thema")
public class ThemaServices extends EjBFactoryAndUtils {
@GET
@Path("/findAllThemen")
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Liefert alle Themen", notes = "Liest alle Themen aus der Datenbank ein nach bestimmten Parametern. Die Liste wird mit Parametern eingelesen.Alle diese Parameter sind optional.", produces = MediaType.APPLICATION_JSON, httpMethod = "GET", responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Not Found.", response = List.class) })
public Response findAllThemen(
@ApiParam(value = "Bestimmt ob die zugeordnete Elemente,wie Dokumente oder Themengruppen angezeigt werden.", required = false, name = "skipZuordnungen") @DefaultValue("true") @QueryParam("skipZuordnungen") Boolean skipZuordnungen,
@ApiParam(value = "Startposition der einzulesenden Daten", required = false, name = "startPosition") @QueryParam("startPosition") Integer startPosition,
@ApiParam(value = "Maximale Anzahl der einzulesenden Daten", required = false, name = "maxResult") @QueryParam("maxResult") Integer maxResult) {
.......
}
生成的 json 文件如下所示:
"/themen/findAllThemen" : {
"get" : {
"operationId" : "findAllThemen",
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "skipZuordnungen",
"in" : "query",
"required" : false,
"type" : "boolean",
"default" : true
}, {
"name" : "startPosition",
"in" : "query",
"required" : false,
"type" : "integer",
"format" : "int32"
}, {
"name" : "maxResult",
"in" : "query",
"required" : false,
"type" : "integer",
"format" : "int32"
} ],
"responses" : {
"default" : {
"description" : "successful operation"
}
}
}
},
在此 Json 文件中,缺少来自 @ApiOperation、@ApiResponses 和 @ApiParam 的信息。由于未知原因,该插件未解析 swagger-Api 的任何内容。请有人可以帮助我正确生成缺少内容的此文件吗?