0

I defined missingRatio variable in my openApi yaml file as below. Openapi version is "3.0.0"

api.yaml

missingRatio:
  type: number
  format: float
  minimum: 0.1
  maximum: 0.3
  default: 0.2
  multipleOf: 0.1
  description: "Ratio of data to remove for validation"

But unfortunately in generated code min and max values are set to 0. So when I use, it only accepts 0 as value.

generated code

  /**
   * Ratio of data to remove for validation
   * minimum: 0
   * maximum: 0
   * @return missingRatio
  **/
  @ApiModelProperty(value = "Ratio of data to remove for validation")

  @DecimalMin("0") @DecimalMax("0") 
  public Float getMissingRatio() {
    return missingRatio;
  }

How Can I resolve this issue?

Abdusoli
  • 661
  • 1
  • 8
  • 24
  • Does this answer your question? [OpenAPI 3.0 valid minimum and maximum values](https://stackoverflow.com/q/60808674/113116) – Helen Sep 29 '22 at 20:44

1 Answers1

0

Maybe you should remove the format: float from your schema. Floating point arithmetic is unreliable. Leave the field as BigDecimal and see if it works.

@DecimalMin and @DecimalMax work for BigDecimals and not float as per documentation

https://docs.oracle.com/javaee/7/api/javax/validation/constraints/DecimalMin.html

Excerpt from Oracle docs:

Note that double and float are not supported due to rounding errors (some providers might provide some approximative support).

null elements are considered valid.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • 2
    Sounds more like a comment than an actual answer. Avoid answers that require further confirmation. See [answer]. – Zabuzard Sep 09 '22 at 10:47