-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 #479
Comments
+1 |
Is there any consideration of this? Or any sort of workaround to make it at all possible? We have multiple views per class and would like to be able to customize the view by endpoint (i.e., we can't hide properties across the board because some properties are shown in some services and not in others). |
+1 |
+1 |
1 similar comment
+1 |
1.5.0 will use pure jackson and therefore the @JSONVIEW annotation. |
I'd love to see some samples committed to the develop_2.0 branch to cover @JSONVIEW use cases. |
I know this has gone unanswered for a long time, and I hate to do this, but that functionality just doesn't fit in with swagger. I suggest using filters to attain a similar result, which gives you even more control since the determination is dynamic. |
fyi, the filters do not solve the problem here and suck to implement. |
fehguy, your link gives 404 |
+1 |
1 similar comment
+1 |
Hm it is still not resolved in my opinion. This api implicit model only supports manual setted parameters... that means we have to write it : in jsonviews + in swagger doc If jsonviews was supported we only had to write into jsonviews. |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
1 similar comment
+1 |
@fehguy Thanks for your comment. I don't think SwaggerSpecFilter can be of any help as the limitation resides in the OAI syntax itself. Taking this example (pseudo code):
=> parsing these two resources will translate into the following OAI JSON file:
Sadly, method SwaggerSpecFilter#isPropertyAllowed() is invoked only once, either after scanning serviceA or serviceB. Would it be difficult to instead generate a 'contextualized' definition model which could have then different properties (hidden or not), like:
|
+1 |
I also just ran into this! Another idea might be to change the property definition to allow for a |
Another alternative to using JSON views that will get you a more precise swagger definition is to leverage Java 8's "mixin" capability with default interface methods. For example one can define a base
You can then make "mixins" of common properties...
... and subclasses of the base
Full |
+1 |
+1 Yeah, this feature would be much appreciated. |
+1 Strictly speaking, the appropriate JsonView is dynamically specified. For our purposes, we don't need that generality. What would work just fine for us is to have a new @ApiJsonView annotation that contains the JsonView class and to have the Swagger object-graph walker just do the same test against that that Jackson does. That change doesn't sound very hard. |
Support has been added via #2681. |
In java, many REST services are written using Jersey/dropwizard frameworks and which rely on the Jackson Json library for serialization. With this Jackson library they allow us to define a "JsonView" which acts as a subset of a model that might be exposed via an api (http://wiki.fasterxml.com/JacksonJsonViews).
For example if I have a resource annotated with the following...
Where the class SomeType looks like this:
I want the swagger docs to only include the property "publicProperty" since it was annotated with the @JSONVIEW(View.Public.class). This dropwizard/jersey resource renders the correct response, but swagger still generates api docs that include both properties.
Is it possible to fix this or is there a swagger change coming that might fix this? I've heard that in the most recent SNAPSHOT of swagger that there's support for "@ApiModelProperty(hidden=true)", but I'd rather not have to duplicate annotating my models like this especially since I think the @JSONVIEW is more flexible.
Thanks,
Brent
The text was updated successfully, but these errors were encountered: