验证所需的布尔属性不起作用

时间:2019-08-06 18:19:04

标签: java swagger swagger-2.0 swagger-codegen

我正在使用Yaml编写的Rest服务使用OpenAPI 2.0合同,并且正在使用swagger-codegen生成POJO。我激活了useBeanValidation和performBeanValidation,以便所生成的代码(在JAVA中)包括验证批注...

在我的合同中,我有一个布尔类型的字段,我将其标记为必填字段:

cancellationInd:
        description: "indicates if this is a cancellation"
        type: boolean
        required: true

,生成的代码如下:

/**
   * indicates if this is a cancellation.
   * @return cancellationInd
  **/
  @NotNull
  @ApiModelProperty(required = true, value = "indicates if this is a cancellation")
  public Boolean isCancellationInd() {
    return cancellationInd;
  }

  public void setCancellationInd(Boolean cancellationInd) {
    this.cancellationInd= cancellationInd;
  }

问题在于,当我使用JsonREserv服务时, cancelInd:null,它通过...。我期待一些HttpStatus_400 由于必填字段。当字段为空而不是null时也是如此...

{
...
  "timstamp": "2019-04-29T13:23:56.123-04:00",
  "cancellationInd": "false",
...

}  

原因似乎是当属性的类型为boolean时,在Java中生成的属性是Boolean(这是包装器,不是原始的,因此接受null)……对吗?这是一个错误吗?

有什么建议吗?

0 个答案:

没有答案
相关问题