0

We use microprofile openapi annotations to generate Swagger documentation for our rest interfaces. Enums often have a property that stores the "display name", which is shown instead of the Enum.

For example:

@AllArgsConstructor
@Getter
@JsonbTypeAdapter(MyEnumAdapter.class)
@Schema(implementation = MyEnum.class)
public enum MyEnum{
    V1("displayname v1"),
    V2("displayname v2"),
    V3("displayname v3");

    private final String name;

    @Nullable
    public static MyEnumfromString(String name) {
        return Arrays.stream(values()).filter(u -> u.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
    }


}

Swagger shows enum like this:

MyEnum string
Enum:
[ V1, V2, V3 ]

What I want:

 MyEnum string
 Enum:
 [ "displayname V1", "displayname V2", "displayname V3" ]

The APIs return the "display name", however, Swagger shows the "Enum name" which often leads to confusion. Is there a possibility to change the Swagger values?

Clemens
  • 99
  • 1
  • 10

1 Answers1

0

Can you please provide us annotations you used on the service and result on the swagger.json ?

You have to enter manually allowableValues attribute on your @ApiParam annotation.

public Object ...(@QueryParam(...)
                  @ApiParam(name = ..., value = "...", 
                            allowableValues = "displayname v1, displayname v2, displayname v3")
                  MyEnum myEnum) {
mothinx
  • 45
  • 2
  • 11