0

We're using Java 11 with the following version of Swagger Codegen

        <plugin>
            <groupId>io.swagger.codegen.v3</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>3.0.35</version>

I have this in my OpenAPI 3 spec for a particular DTO field,

    amount:
      type: number
      format: double
      maximum: 99999999.99
      multipleOf: 0.01

Upon running the plugin, the DTO is generated without the decimal places

  /**
   * Get amount
   * maximum: 99999999
   * @return amount
  **/
  @Schema(required = true, description = "")
  @NotNull

   @DecimalMax("99999999")   public Double getAmount() {
    return amount;
  }

As a result, when I submit a value for my listed maximum, 99999999.99, I get this error

"errorMessage": "must be less than or equal to 99999999"

What's the proper way in the openAPI spec and Swagger code gen to have a maximum field with decimal places included afterwards?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • 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:42
  • I'm already doing that, no? Also I can't tell what version of SwaggerCode gen that poster is using. I have posted my version and the generated DTO so not sure if it is a bug in the verision or somethign else I'm doing. – Dave Sep 29 '22 at 20:50
  • Did you specify useBeanValidation=true (https://github.com/swagger-api/swagger-codegen/issues/7795)? like true joda true ... – HoaPhan Oct 04 '22 at 15:37
  • Tried this but it didn't work – Dave Oct 04 '22 at 19:03

2 Answers2

0

Can you try this?

amount:
  type: number
  format: double
  exclusiveMaximum: 100000000
  multipleOf: 0.01
D.S.
  • 137
  • 5
0

Try this based on format double (am aware that DTO is not generating decimal), add it within the swagger-codegen-maven-plugin configuration in your pom.xml:

<configuration>
   <typeMappings>
     <typeMapping>Double=java.math.BigDecimal</typeMapping>
   </typeMappings>
</configuration>
djmonki
  • 3,020
  • 7
  • 18