OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
When I run the code generator on above it outputs following:
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.annotation.Generated;
import jakarta.validation.constraints.*;
import java.util.*;
/** Gets or Sets DocumentType */
@Generated(
value = "org.openapitools.codegen.languages.SpringCodegen",
date = "2024-04-18T08:48:15.084178-07:00[America/Los_Angeles]",
comments = "Generator version: 7.4.0")
public enum DocumentType {
TXT("txt"),
TXT2("TXT"),
HTML("html"),
HTML2("HTML"),
PDF("pdf"),
PDF2("PDF"),
DOC("doc"),
DOC2("DOC"),
XLS("xls"),
XLS2("XLS"),
PPT("ppt"),
PPT2("PPT");
private String value;
DocumentType(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static DocumentType fromValue(String value) {
for (DocumentType b : DocumentType.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
}
However this does not help when user passes txt in their REST request. Spring Framework calls Enum.valueOf to try to convert txt to a well-known enum and that call fails
java.lang.IllegalArgumentException: No enum constant xxx.openapi.model.DocumentType.txt
Bug Report Checklist
Description
OpenAPI enums are case-sensitive [1]. To cope up with this I am declaring both uppercase and lowercase enum values like this:
When I run the code generator on above it outputs following:
However this does not help when user passes
txt
in their REST request. Spring Framework callsEnum.valueOf
to try to converttxt
to a well-known enum and that call failsbecause as per docs:
The right code generation will look like following:
openapi-generator version
7.4.0
OpenAPI declaration file content or url
Generation Details
using
openapi-generator-maven-plugin
Steps to reproduce
please see above
Related issues/PRs
Suggest a fix
please see above for the right code that should be generated.