Reputation: 465
Interaction with the server is performed using the DTO. I use swagger to document the API, but I have a problem. In the DTO, I have fields that are set on the server, that is, the API client DOES not have to fill them in (for example, id and creationDate). But if you use swagger, it will show these fields in example, which can confuse users. I tried adding the following annotation to the DTO property:
@ApiModelProperty(hidden = true)
private Long id;
But in this case, these fields disappear from the server response example too. How to make sure that these properties are visible only in the response, that is, they are hidden only in the sample request?
Upvotes: 2
Views: 1630
Reputation: 3766
You can achieve the same using @ApiModelProperty(readOnly = true)
.
Allows a model property to be designated as read only. It will hide property from request and shows for a response only.
@ApiModelProperty(readOnly = true)
private Long id;
Upvotes: 2