I have an enum like this:
@Getter
public enum ErrorCode implements BaseError {
// @formatter:off
FOO(100001, "Foo message.",
BAR(100002, "Bar message."),
.
.
.
FOOBAR(300003, "FOOBAR message.");
public final int errorId;
public final String errorMsg;
ErrorCode(int errorId, String errorMsg) {
this.errorId = errorId;
this.errorMsg = errorMsg;
}
}
I know, I can use @Schema(implementation = ErrorCode.class) to display the enum in SqggerUI but it displays the name. Ist there a way to display the error code (or any other defined properties of an enum)?
In this case I would like to display the list of errorCodes instead of the default which displays the list of the enum names.
As I suspected, OpenApi uses enum's toString(), which is by default implemented as calling name(). If you override the enum's toString(). you will reach your goal.
I can't see any reason why you should not redefine toString() for a Java enum, I am not aware of any contract which this should go against.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With