swagger-api / swagger-api/swagger-codegen
[JAVA] Generated code contains value which is expressed as integer but is too large for integer.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
We use a swagger file which contains the following field definition:
number:
type: integer
description: >-
The unique identification of an action discount for an insurance
policy.
maximum: 1e+10
minimum: 0
exclusiveMaximum: true
The java file generated contains this code:
@Min(0) @Max(10000000000)
public Long getNumber() {
return number;
}
The java compiler complains about the value 10000000000 because it is too big to be expressed as an integer.
The code generation should generate 10000000000L instead.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
See description.
Command line used for generation
Generated from Maven:
<execution>
<id>generate-model</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/swagger/swagger.yaml</inputSpec>
<apiPackage>nl.xxx.gen.yyy.api</apiPackage>
<modelPackage>nl.xxx.gen.yyy.model</modelPackage>
<generateApis>false</generateApis>
<language>spring</language>
<configOptions>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
</configOptions>
<library>spring-mvc</library>
</configuration>
</execution>
Steps to reproduce
Use this field in swagger definition:
number:
type: integer
description: >-
The unique identification of an action discount for an insurance
policy.
maximum: 1e+10
minimum: 0
exclusiveMaximum: true
Generate the model using this maven configuration:
<execution>
<id>generate-model</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/swagger/swagger.yaml</inputSpec>
<apiPackage>nl.xxx.gen.yyy.api</apiPackage>
<modelPackage>nl.xxx.gen.yyy.model</modelPackage>
<generateApis>false</generateApis>
<language>spring</language>
<configOptions>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
</configOptions>
<library>spring-mvc</library>
</configuration>
</execution>
Related issues/PRs
Suggest a fix/enhancement
When the underlying data type is Long, always generate the validation rules using the "L suffix" notation for java.
E.g: not 10000000000000 but 10000000000000L
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 by reproducing the Maven model generation with the Swagger declaration shown in the issue and inspect the generated Java model containing the @Max value. Trace the Java validation annotation template or generation entry point responsible for numeric bounds. Done means the generated Long bound uses the L suffix and the generated source compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100