I am using Swagger Codegen 3.0.19, also tried OpenAPI Generator 4.0.3.
Java Environment:
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Runner:
java -jar ./libs/openapi-generator-cli-4.3.0.jar generate \
-i pet.yaml \
-g spring \
-o ./OUTPUT/api/
Here's my OpenAPI Schema:
openapi: "3.0.0"
....
CaptureStatus:
type: object
description: Holds current capture status.
properties:
status:
type: string
enum:
- ON
- OFF
description: Capture status values.
....
Output is:
....
public enum StatusEnum {
TRUE("true"),
FALSE("false");
private String value;
StatusEnum(String value) {
this.value = value;
}
....
Why does the codegen translate the ON/OFF enum to TRUE/FALSE? It does not do it when I generate using Swagger Editor GUI.
In YAML 1.1, on
, off
, y
, n
, yes
and no
are boolean values. This was changed in YAML 1.2, this version no longer considers these values as booleans.
It looks like Swagger Codegen and OpenAPI Generator use YAML 1.1 parsers. In this case you need to enclose 'ON'
and 'OFF'
in quotes to treat them as strings:
enum:
- 'ON'
- 'OFF'