Skip to content

@DefaultValue for enums ignored in openapi.yaml / swagger-ui #14865

@sebthom

Description

@sebthom

Describe the bug

Specifying a default value for an enum parameter on a REST API has no effect on the generated openapi.yaml or a pre-selection of the respective value in the swagger-ui.

@Path("/hello-resteasy")
public class GreetingResource {

   public enum MyEnum {
      CAT,
      DOG,
      BAR,
      FOO
   }

   @GET
   @Produces(MediaType.TEXT_PLAIN)
   public String hello(
      @Parameter(required = true) 
      @QueryParam(value = "myEnum") 
      @DefaultValue("DOG") // -> I want MyEnum.DOG to be the default value
      final MyEnum myEnum
   ) {
      return "myEnum = " + myEnum;
   }
}

Expected behavior

Openapi.yaml should specify "DOG" as parameter default and the "DOG" entry should also be pre-selected in swagger-ui.

Actual behavior

The first entry of the enum values sorted alphabetically is pre-selected.

To Reproduce

Steps to reproduce the behavior:

  1. Extract code-with-quarkus.zip and run
  2. Go to http://localhost:8080/q/swagger-ui/#/default/get_hello_resteasy

Screenshots

Current Swagger-UI:
image

Here is a comparison of how the Openapi.yaml is currently generated (left) and how it could be generated to solve this issue (right).

image

After this change, swagger-ui would render:

image

Environment (please complete the following information):

  • Output of uname -a or ver: Microsoft Windows [Version 10.0.18363.1198]
  • Output of java -version: openjdk version "11.0.9.1" 2020-11-04 LTS
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.11.1.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions