Would like to know how to hide a model property in Swagger on POST. I have tried both Swagger-springmvc (0.9.3) and Springfox (supports swagger spec 2.0) to no avail.
Problem being I would like to see this in the GET requests through Swagger. But not POST requests, since id is auto-assigned, I would like to hide it just for the POST request.
public class RestModel {
private int id;
@JsonProperty
private String name;
@JsonProperty
public int getId() {
return 0;
}
@JsonIgnore
public void setId(int customerId) {
this.customerId = customerId;
}
public int getName() {
return "abc";
}
public void setName(String name) {
this.name = name;
}
}
So on GET, I should see:
{
"id": 0,
"name" : "abc"
}
And on POST, I should see just:
{
"name"
}
Tried adding: @ApiModelProperty(readonly=true). But that didn't help.
Unfortunately having different request and response models is not supported currently in springfox. The current thought is that we might support this feature using @JsonView in the future.
I have solved this with simply extending the Object that I want to hide a property of when using as request parameter.
Example:
I have the object Person.java:
I have simply created another class: PersonRequest.java:
RequestMapping looks simply like:
Works like charm :)