Swagger Annotation将json示例添加到响应类

时间:2017-11-03 09:04:50

标签: java swagger-ui spring-restcontroller

enter image description here

如何插入默认值而不是" {}"使用swagger注释?

1 个答案:

答案 0 :(得分:4)

您需要使用 @ApiResponses @ApiResponse 来宣布您的Rest方法。

例如

@ApiResponses(value = { 
                        @ApiResponse(code = 200, message = "Successful retrieval of demand",responseContainer="List"),
                        @ApiResponse(code = 404, message = "Demand does not exist", response = Your Error response.class),
                        @ApiResponse(code = 500, message = "Internal server error", response = Your Error response.class) 
                    }
            )

使用 @ApiModel 对您的Json Response类进行Annonatate,并使用 @ApiModelProperty

对其字段进行宣传
@ApiModel(description = "Your comment")
public class Demand implements Serializable {

    private static final long serialVersionUID = 1L;


    @ApiModelProperty(notes = "Your comments", required = true, example = "example value")
    private String demandId;
}