swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Add support for @JsonView

Open brentryan opened this issue 12 years ago • 29 comments

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...

@JsonView(View.Public.class)
@ApiOperation(value = "bla bla bal.", notes = "And bla bla bla.",
        response = SomeType.class)
Response getSomeResource() {}

Where the class SomeType looks like this:

class SomeType {
  @JsonView(View.Public.class)
   private String publicProperty;
  @JsonView(View.Internal.class)
   private String internalProperty;
}

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

brentryan avatar Mar 05 '14 14:03 brentryan

+1

saadmufti avatar Mar 25 '14 15:03 saadmufti

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).

amandabouman avatar Jul 22 '14 15:07 amandabouman

+1

ryanlchandler avatar Jul 28 '14 21:07 ryanlchandler

+1

txfan avatar Sep 20 '14 05:09 txfan

+1

sseide avatar Sep 23 '14 10:09 sseide

1.5.0 will use pure jackson and therefore the @JsonView annotation.

fehguy avatar Sep 26 '14 16:09 fehguy

I'd love to see some samples committed to the develop_2.0 branch to cover @JsonView use cases.

fehguy avatar Dec 20 '14 23:12 fehguy

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.

https://github.com/swagger-api/swagger-core/blob/develop_2.0/modules/swagger-core/src/main/java/com/wordnik/swagger/core/filter/SwaggerSpecFilter.java

fehguy avatar Mar 13 '15 21:03 fehguy

fyi, the filters do not solve the problem here and suck to implement.

brentryan avatar Apr 10 '15 00:04 brentryan

fehguy, your link gives 404

batcer avatar Sep 04 '15 13:09 batcer

https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-core/src/main/java/io/swagger/core/filter/SwaggerSpecFilter.java

webron avatar Sep 04 '15 14:09 webron

+1

gustavolira avatar Nov 28 '15 13:11 gustavolira

+1

john24318 avatar Aug 02 '16 01:08 john24318

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. Please support it

sebastienvermeille avatar Sep 01 '16 14:09 sebastienvermeille

+1

takumahuwa avatar Oct 06 '16 15:10 takumahuwa

+1

salletchen avatar Oct 07 '16 08:10 salletchen

+1

aint avatar Dec 08 '16 10:12 aint

+1

monoc44 avatar Dec 27 '16 20:12 monoc44

+1

prajotNaik avatar Dec 29 '16 10:12 prajotNaik

+1

manuelhuber avatar Jan 02 '17 15:01 manuelhuber