2017-09-05 60 views
0

我正在使用swagger來記錄我的REST api。Swagger沒有生成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> 

回答

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