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

@Schema annotation with type String and allowableValues set doesn't generate enum drop-down in swagger-ui after upgrading from 1.6.6 (when Spring custom converter is used) #1663

Closed
solita-alperttiti opened this issue May 12, 2022 · 5 comments
Labels
incomplete incomplete description: Make sure you Provide a Minimal, Reproducible Example - with HelloController

Comments

@solita-alperttiti
Copy link

solita-alperttiti commented May 12, 2022

Describe the bug

After upgrading from springdoc-openapi 1.6.6 to 1.6.7/1.6.8 enum drop-down is not visible in swagger-ui.

EDIT: problem is most likely a custom converter with enum (plain or decorated with schema-annotation). More details from comments.

This works with 1.6.6. as expected, but in 1.6.7/1.6.8 there is only normal empty text-field and not the enum drop-down with allowable values:


@Schema(type = "String", allowableValues = {
    "foo", "bar"
})
public enum FooBar {
[..]

And enum is used as pathvariable in controller:


@GetMapping(value = "/some/path/{fooBar}")
public void getFooBar(@PathVariable FooBar fooBar) {
[..]

  • What version of spring-boot you are using?
    2.6.7
  • What modules and versions of springdoc-openapi are you using?
    1.6.6 works, 1.6.7/1.6.8 doesn't
@solita-alperttiti
Copy link
Author

Ok, digged a little bit more into this and it seems this is about spring custom converter used for that enum. If I remove converter then everything works in 1.6.8 as expected with plain enum and with decorating schema-annotation. It seems there has been some fixes for custom converters, e.g. this one #1534 . Need to check it in more detail if it explains this behaviour.

@solita-alperttiti solita-alperttiti changed the title @Schema annotation with type String and allowableValues set doesn't generate enum drop-down in swagger-ui after upgrading from 1.6.6 @Schema annotation with type String and allowableValues set doesn't generate enum drop-down in swagger-ui after upgrading from 1.6.6 (when Spring custom converter is used) May 13, 2022
@solita-alperttiti
Copy link
Author

solita-alperttiti commented May 13, 2022

As a workaround you could move @Schema-annotation for enum directly to controller(s) parameters, but obviously this isn't an optimal solution, because then you'll need to duplicate it for every place where that enum type is used. So, I think this should be fixed in a way, that @Schema-annotation of some type will be respected even if spring custom converter is involved.

@bnasslahsen
Copy link
Contributor

@solita-alperttiti,

Your description is not clear.
Provide a Minimal, Reproducible Example - with HelloController that reproduces the problem

@bnasslahsen bnasslahsen added the incomplete incomplete description: Make sure you Provide a Minimal, Reproducible Example - with HelloController label May 23, 2022
@solita-alperttiti
Copy link
Author

solita-alperttiti commented May 24, 2022

@bnasslahsen I have made a sample project to help reproducing the described behavior easily.

Please see: https://github.com/solita-alperttiti/springdoc-enum-example

@bnasslahsen
Copy link
Contributor

@solita-alperttiti,

Should be fixed with the next release.

This is the workaround, until then

    @GetMapping(value = "/example/{fooBar}")
    public String getFooBar(@PathVariable @Parameter(schema = @Schema(allowableValues = { "foo", "bar" })) FooBar fooBar) {
        return fooBar.name();
    }

bnasslahsen added a commit that referenced this issue May 24, 2022
…enerate enum drop-down in swagger-ui after upgrading from 1.6.6 (when Spring custom converter is used). Fixes #1663.
bnasslahsen added a commit that referenced this issue May 24, 2022
…es set doesn't generate enum drop-down in swagger-ui after upgrading from 1.6.6 (when Spring custom converter is used) #1663
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incomplete incomplete description: Make sure you Provide a Minimal, Reproducible Example - with HelloController
Projects
None yet
Development

No branches or pull requests

2 participants