Skip to content

[Bug]: Bean validation doesn't work for numbers larger than Integer.MAX_VALUE #1370

Description

@avi5kdonrh

With the following modification on petstore schema where I added minimum and maximum values, the generated POJO do not compile and give the following error:

 "components": {
		"schemas": {
			"Order": {
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"format": "int64",
                        "minimum": 0,
                        "maximum": 787878787878,
						"example": 787878787878
					}

Command used for code generation:

java -jar swagger-codegen-cli-3.0.72.jar generate -DperformBeanValidation=true -DuseBeanValidation=true  -i ./petstore.json -l java -o api && mvn -f api/pom.xml clean package -Dmaven.compiler.source=21 -Dmaven.compiler.target=21

Build error:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /test/api/src/main/java/io/swagger/client/api/StoreApi.java:[667,68] integer number too large
[ERROR] /test/api/src/main/java/io/swagger/client/model/Order.java:[109,15] integer number too large
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

A snippet from generated Order.java

    102    /**
    103    * Get id
    104    * minimum: 0
    105    * maximum: 787878787878
    106    * @return id
    107   **/
    108   @NotNull
    109  @Min(0) @Max(787878787878)  @Schema(example = "9999999999", description = "")
    110   public Long getId() {
    111     return id;
    112   }

As per my analysis the long literal "L" should be appended when extracting min/max from the parameterSchema:

https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java#L2578-L2580

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions