So I am currently trying to update my backend which is running Quarkus to version 3.
The new version of Quarkus is using smallrye, but I am having some trouble with generating my OpenAPI specification files (.yaml) as it is not generating the enum property as expected.
I am currently using the smallrye-open-api-maven-plugin version 3.11.
The code below is code I made up, but is based on the experience in my code base.
I have the following Java class:
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@Schema(title = "CoolStuff", description = "This is actually the cool stuff")
public class CoolClass {
public enum CoolEnum {
Cool,
NotCool;
}
@Schema(description = "The command")
private final CoolEnum command;
@Schema(description = "The id")
private final String id;
public CoolClass(CoolEnum command, String id) {
this.command = command;
this.id = id;
}
public CoolEnum getCommand() {
return command;
}
public String getId() {
return id;
}
}
When compiling and making the maven plugin generate the .yaml file I get this:
CoolClass:
title: CoolStuff
description: This is actually the cool stuff
type: object
properties:
command:
description: The command
type: object
id:
description: The id
type string
I would have expected the following .yaml, which is the .yaml I need:
CoolClass:
title: CoolStuff
description: This is actually the cool stuff
type: object
properties:
command:
description: The command
type: string
enum:
- Cool
- NotCool
id:
description: The id
type string
I do not really see what I have done wrong here?
I have another example as well:
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
@Schema(title = "CoolStuffCool", description = "This is actually the cool stuff")
public class CoolClassClass {
public enum CoolEnumEnum {
Cool,
NotCool;
}
public enum NotCoolEnumEnum {
Work,
NotWork;
}
@Schema(description = "The command", implementation = CoolEnumEnum.class, type = SchemaType.STRING)
private final CoolEnumEnum command;
@Schema(description = "The mode", implementation = NotCoolEnumEnum.class, type = SchemaType.STRING)
private final NotCoolEnumEnum mode;
public CoolClassClass(CoolEnumEnum command, NotCoolEnumEnum mode) {
this.command = command;
this.mode = mode;
}
public CoolEnumEnum getCommand() {
return command;
}
public NotCoolEnumEnum getMode() {
return mode;
}
@JsonCreator
public static CoolClassClass firValue(
@JsonProperty("command") String command, @JsonProperty("mode") String mode) {
CoolEnumEnum commandValue = (value != null && !value.isEmpty()) ? CoolEnumEnum.valueOf(command)) : null;
NotCoolEnumEnum modeValue = (value != null && !value.isEmpty()) ? NotCoolEnumEnum.valueOf(mode)) : null;
return new CoolClassClass(command, mode);
}
}
The class CoolClassClass
is being generated correctly with the enum properties. I have tried adding the @JsonCreator
to the CoolClass
but that did not work. I also tried adding the implementation
and type
in the CoolClass
but also without luck.
When expressing the enumeration
property with the values manually, then the .yaml is also generated correctly, however I am relying heavy on that the enum properties can be generated automatically from the code, as the general backend is dependent on multiple classes, which needs to update the APIs for the other classes.
Is there something I am missing?
BareMaxx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.