【问题标题】:Swagger not generating api model valueSwagger 不生成 api 模型值
【发布时间】:2017-09-05 11:40:57
【问题描述】:

我正在使用 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 中没有 getter/setter,它不会崩溃,但是,它会生成一个空模型......知道我做错了什么吗?

这是我的 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>

【问题讨论】:

    标签: jersey jetty swagger


    【解决方案1】:

    您似乎正在使用一些 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

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 2019-05-19
      • 1970-01-01
      • 2019-04-05
      • 2020-04-05
      • 1970-01-01
      • 2020-06-11
      • 2017-11-10
      • 2022-10-24
      相关资源
      最近更新 更多