3
votes

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.

2

2 Answers

5
votes

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

Example:

@ApiModelProperty(required = false, hidden = true)
private String label;
0
votes

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