Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sebthom opened this issue Feb 5, 2021 · 1 comment · Fixed by #14916
Closed

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

sebthom opened this issue Feb 5, 2021 · 1 comment · Fixed by #14916
Labels
Milestone

Comments

@sebthom
Copy link
Contributor

sebthom commented Feb 5, 2021

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)
@sebthom sebthom added the kind/bug Something isn't working label Feb 5, 2021
@ghost
Copy link

ghost commented Feb 5, 2021

@sebthom sebthom changed the title @DefaultValue for enums ignored in openapi / swagger-ui @DefaultValue for enums ignored in openapi.yaml / swagger-ui Feb 5, 2021
@ghost ghost added this to the 1.12 - master milestone Feb 10, 2021
@gsmet gsmet modified the milestones: 1.12.0.CR1, 1.11.4.Final Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants