OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA-UNDERTOW] integer enum generates value of type string
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating classes from the specified openapi.yaml specification which contains enums of type integer, the generated code has incorrect type for values
openapi-generator version
5.0.1 version of openapi-generator-maven-plugin
openapi-version
3.0.0
OpenAPI declaration file content or url
QualificationFragment:
description: qualification of the resource instance
type: object
properties:
name:
type: string
example: "Undertowtest instance 1"
type:
type: integer
enum:
- 1
- 2
Generation Details
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapigen.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/openapi.yaml</inputSpec>
<generatorName>org.openapitools.codegen.languages.JavaUndertowServerCodegen</generatorName>
<modelPackage>com.api.model</modelPackage>
<apiPackage>com.api</apiPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Clarity in explaining the issue
The generated code generates the following output when enum of type integer is used
public class QualificationFragment {
private String name;
public enum TypeEnum {
NUMBER_1(1),
NUMBER_2(2);
private String value;
TypeEnum(String value) {
this.value = value;
}
@Override
@JsonValue
public String toString() {
return value;
}
}
private TypeEnum type;
/**
*/
public QualificationFragment name(String name) {
this.name = name;
return this;
}
@ApiModelProperty(example = "Undertowtest instance 1", value = "")
@JsonProperty("name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
*/
public QualificationFragment type(TypeEnum type) {
this.type = type;
return this;
}
@ApiModelProperty(value = "")
@JsonProperty("type")
public TypeEnum getType() {
return type;
}
public void setType(TypeEnum type) {
this.type = type;
}
}
Steps to reproduce
- Generate code with a yaml spec that has integer type enum specifications
Related issues/PRs
Suggest a fix
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 with the JavaUndertowServerCodegen generator and the provided OpenAPI YAML, then reproduce the output through the openapi-generator-maven-plugin. Compare the generated integer enum declaration with the expected numeric value type; done means the generated Undertow model preserves integer enum values instead of declaring them as String.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100