swagger-api / swagger-api/swagger-codegen-generators
[Bug]: Bean validation doesn't work for numbers larger than Integer.MAX_VALUE
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
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:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java around lines 2578-2580, where minimum and maximum values are extracted. Reproduce with the provided petstore schema and generation command, then build api/pom.xml and inspect generated Order.java and StoreApi.java. Done means large int64 validation bounds produce compilable Java while retaining the requested values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100