Swagger 未生成 api 模型值
Swagger not generating api model value
我正在使用 swagger 来记录我的 REST api。
我不想自动生成文档,所以我使用带注释的 swagger-jaxrs。
@GET
@Path("/news/{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "News found", response = NewsEntry.class)})
NewsEntry是我的模型,设置如下:
@ApiModel("News Entry")
public class NewsEntry {
@ApiModelProperty(value = "the id of the item", required = true)
private static long id;
@ApiModelProperty(value = "content", required = true)
private static String content;
}
经过几次测试,我发现,如果 NewsEntry 中没有 getters/setters,它不会崩溃,但是,它会生成一个空模型...不知道我在做什么做错了吗?
这是我的 pom:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.8 </version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.8 </version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.8 </version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.8 </version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>2.1.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.1.4.Final</version>
</dependency>
您似乎正在使用一些 jaxrs1 实现。
因此在 pom
中只使用一个包就足够了
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
它是一个组合包,您可以在此处看到:https://mvnrepository.com/artifact/io.swagger/swagger-jaxrs/1.5.0
您是否尝试创建引用另一个模型而不是 NewsEntry.class?
您是否按照教程并使用相应的注释对所需的 类 进行了注释? 1.5.8 之前。是 @Api
否则你是否像教程中那样使用了正确的包扫描?
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-RESTEasy-2.X-Project-Setup-1.5
我正在使用 swagger 来记录我的 REST api。
我不想自动生成文档,所以我使用带注释的 swagger-jaxrs。
@GET
@Path("/news/{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "News found", response = NewsEntry.class)})
NewsEntry是我的模型,设置如下:
@ApiModel("News Entry")
public class NewsEntry {
@ApiModelProperty(value = "the id of the item", required = true)
private static long id;
@ApiModelProperty(value = "content", required = true)
private static String content;
}
经过几次测试,我发现,如果 NewsEntry 中没有 getters/setters,它不会崩溃,但是,它会生成一个空模型...不知道我在做什么做错了吗?
这是我的 pom:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.8 </version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.8 </version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.8 </version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.8 </version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>2.1.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.1.4.Final</version>
</dependency>
您似乎正在使用一些 jaxrs1 实现。 因此在 pom
中只使用一个包就足够了 <dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
它是一个组合包,您可以在此处看到:https://mvnrepository.com/artifact/io.swagger/swagger-jaxrs/1.5.0
您是否尝试创建引用另一个模型而不是 NewsEntry.class?
您是否按照教程并使用相应的注释对所需的 类 进行了注释? 1.5.8 之前。是 @Api
否则你是否像教程中那样使用了正确的包扫描? https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-RESTEasy-2.X-Project-Setup-1.5