Springfox注释@ApiModelProperty不显示结果

时间:2018-10-15 10:03:18

标签: java swagger springfox

我正在使用springfox-swagger2 v.9.2.2。当我尝试向字段或get方法添加@ApiModelProperty批注时,返回的json不显示任何信息。

TestRestController.java

@Api(value = REST_URL, tags = "First endpoint")
@RestController(REST_BEAN)
@RequestMapping(REST_URL)
public class TestRestController {  

  @ApiOperation(value = "Some GET method", authorizations = @Authorization(value = "basicAuth"), response = TestRestResponse.class)  
  @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<TestRestResponse> getResult(  
    @ApiParam(  
      name = "firstParam",  
      value = "First parameter of get method" ) @RequestParam String firstParam) {  
    ...
  }
}  

TestRestResponse.java

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonPropertyOrder({
    "firstProperty",  
    "secondProperty",  
    "thirdProperty" })
@ApiModel(value = "Rest response", description = "Response returned by TestRest")
public class ShipmentRestResponse {  

  private String firstProperty;
  private Integer secondProperty;
  private MyClass thirdProperty;

  @ApiModelProperty(
      value ="firstProperty",
      notes = "Could be one of two values",
      dataType = "java.lang.String",
      allowableValues = "Ok, Error")
  public String getFirstProperty() {
    return firstProperty;
  }

  public void setFirstProperty(String firstProperty) {
    this.firstProperty = firstProperty;
  }  

  public Integer getSecondProperty() {
    return secondProperty;
  }

  public void setSecondProperty(Integer secondProperty) {
    this.secondProperty = secondProperty;
  }

  public MyClass getThirdProperty() {
    return thirdProperty;
  }

  public void setThirdProperty(MyClass thirdProperty) {
    this.thirdProperty = thirdProperty;
  }
}

SwaggerConfig.java

@EnableSwagger2  
public class SwaggerConfig {

  @Bean
  public Docket api(ServletContext servletContext) {
    return new Docket(DocumentationType.SWAGGER_2).tags(
            new Tag("First endpoint", "This is the first endpoint"))
                                                  .protocols(Sets.newHashSet("https"))
                                                  .select()
                                                  .apis(RequestHandlerSelectors.any())
                                                  .paths(PathSelectors.any())
                                                  .build()
                                                  .genericModelSubstitutes(Optional.class)
                                                  .securitySchemes(Collections.singletonList(new BasicAuth("basicAuth")));

  }
}

当我最后发送get到localhost:8080 / rest / v2 / api-docs时,我只会看到

"definitions": {
  "Rest Response": {
    "type": "object",
    "title": "Rest Response",
    "description": "Response returned by TestRest"
  }
}

有什么我忘了吗?我试图删除@JsonPropertyOrder注释,但是这样做没有帮助。我认为课程上的@ApiModel和字段/方法上的@ApiModelProperty足以显示出来。

0 个答案:

没有答案