Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger: Remove class properties from parameter example value

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.

like image 664
cr1ng3 Avatar asked Jan 29 '26 14:01

cr1ng3


1 Answers

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

Example:

@ApiModelProperty(required = false, hidden = true)
private String label;
like image 164
WannaBeGeek Avatar answered Jan 31 '26 06:01

WannaBeGeek