3

I am using Swagger to document a REST API.

I am having a class like this:

public class Source{ 
    private String url;
    private String category;
    private String label;
    ... 
}

I am currently using @ApiImplicitParam to set the dataType to Source.class, but I am having multiple POST requests that get a JSON as a body parameter with, lets say, a single variable of those, for example:

{"label": "labelA"}

Because of the dataType set previously, the example value displayed by the Swagger UI is a whole Source.class, something like this:

{
    "url": "string",
    "category": "string",
    "label": "string",
    ...
}

Could I somehow chop the example value displayed by the Swagger UI for every single request of those? I mean that the getSourceFromUrl() request should get a JSON that contains only a url field, and the example should display exactly this and not the full Source.class JSON.

Thank you all in advance!

UPDATE

I am using JAX-RS. Please, ask me for more input if needed.

cr1ng3
  • 101
  • 2
  • 7
  • Possible duplicate of [Exclude Models or properties from swagger response](https://stackoverflow.com/questions/27777537/exclude-models-or-properties-from-swagger-response) – Helen Jan 23 '18 at 07:44

2 Answers2

5

If you are using springfox-swagger2 , there is an annotation @ApiModelProperty that does this.

Example:

@ApiModelProperty(required = false, hidden = true)
private String label;
WannaBeGeek
  • 979
  • 14
  • 32
  • Thank you very much for the response. My problem is that I have multiple endpoints and I wish to use the same class as parameter example value to all of them but with different set of the class's properties. I am using JAX-RS (I will update my post). P.S.: I believe that @ApiModelProperty can be used inside the class and it will affect all the endpoints that use this class as an example value. Am I wrong? – cr1ng3 Jul 26 '16 at 11:17
0

For the time being, you cannot do such a thing. You have to create a different class for each case.

See in swagger-core's github: https://github.com/swagger-api/swagger-core/issues/1863#issuecomment-237339565

cr1ng3
  • 101
  • 2
  • 7