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

Add support for @JsonView annotations #1008

Closed
maliffi opened this issue Dec 21, 2021 · 11 comments · Fixed by #1209
Closed

Add support for @JsonView annotations #1008

maliffi opened this issue Dec 21, 2021 · 11 comments · Fixed by #1209
Assignees
Labels
enhancement New feature or request

Comments

@maliffi
Copy link

maliffi commented Dec 21, 2021

Hello,
I've seen that Swagger already support the usage of anootation @JsonView in order to filter input and output of a model class in RequestBody or ResponseBody (see swagger-api/swagger-core#479 fixed with swagger-api/swagger-core#2681 since 2018), but If I try using this annotation in my controller in order to selectively hide some fields of my model class from input or output in the swagger-ui, they are anyway displayed.
This is my example

    @JsonView(RestViews.ViewAdmin.class)
    public CompletionStage<FilterRest> saveFilter(
            @Valid @JsonView(RestViews.Save.class) @ConvertGroup(to = ValidationGroups.Save.class) FilterRest filterRest) {
    }

My model class is:

public class FilterRest {

    @JsonView({RestViews.Update.class, RestViews.ViewUser.class})
    @Null(groups = {ValidationGroups.Create.class})
    private String id;

    @JsonView({RestViews.Create.class, RestViews.ViewAdmin.class})
    @NotNull
    private Set<String> countryValidity;

Event the field id is marked with a different JsonView actually is showed in swagger-ui for the request in the API.

What am I doing wrong?

@phillip-kruger
Copy link
Member

SmallRye OpenAPI is primarily a microprofile open API implementation. We do not support (yet) swagger annotations, although there is an open issue to add support for it. Once that is done we can look at supporting this

@mschorsch
Copy link

JsonView is a jackson annotation not a swagger annotation.

@MikeEdgar MikeEdgar added the enhancement New feature or request label Jan 10, 2022
@mschorsch
Copy link

@phillip-kruger Is there a chance that this feature will be implemented in the near future?

JsonView support is very important for us, because we must generate different OpenAPI specifications from the same Rest-Api.

@MikeEdgar
Copy link
Member

@maliffi , @mschorsch - based on the example in this issue, would you expect the FilterRest bean to result in 6 different schemas?

  • FilterRest
  • FilterRest_ViewAdmin
  • FilterRest_Save
  • FilterRest_Update
  • FilterRest_ViewUser
  • FilterRest_Create

@mschorsch
Copy link

Yes. It would be nice if i could choose (config flag?) which JsonView(s) should be generated.

@maliffi
Copy link
Author

maliffi commented Jan 12, 2022

@maliffi , @mschorsch - based on the example in this issue, would you expect the FilterRest bean to result in 6 different schemas?

  • FilterRest
  • FilterRest_ViewAdmin
  • FilterRest_Save
  • FilterRest_Update
  • FilterRest_ViewUser
  • FilterRest_Create

Yes, this is what I would expect to see in the Schemas section of swagger.
At the same time, the example autogenerated for each API should respect the RestView used to annotate the method of rest api

@mschorsch
Copy link

mschorsch commented Feb 12, 2022

@MikeEdgar Do you know when this feature will be available? This issue prevents us from using smallrye-openapi in quarkus and is a blocker for our migration to resteasy-reactive in one of our projects.

@MikeEdgar
Copy link
Member

@mschorsch I haven't had a chance to think about a solution for this one yet, but I hope to find some time soon.

@sandronm
Copy link

Don't want to put pressure on anybody but this feature will also be nice for our current developments.
I hope this will become a reality some day ;-)

Already thank you for your all work!

@antssilva96
Copy link

I'm in the same situation as @mschorsch, this is blocking the use of quarkus-smallrye-openapi.

@Raf23
Copy link

Raf23 commented May 27, 2022

Same issue here and same situation @MikeEdgar this is blocking for us to use quarkus-smallrye-openapi

@MikeEdgar MikeEdgar self-assigned this Aug 7, 2022
MikeEdgar added a commit to MikeEdgar/smallrye-open-api that referenced this issue Aug 7, 2022
Closes smallrye#1008

Signed-off-by: Michael Edgar <michael@xlate.io>
MikeEdgar added a commit to MikeEdgar/smallrye-open-api that referenced this issue Aug 8, 2022
Closes smallrye#1008

Signed-off-by: Michael Edgar <michael@xlate.io>
MikeEdgar added a commit to MikeEdgar/smallrye-open-api that referenced this issue Aug 8, 2022
Closes smallrye#1008

Signed-off-by: Michael Edgar <michael@xlate.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants