Issue
I have a DTO object
public class Rate {
private final Integer rate;
private final String user;
private final Date date;
}
and two controllers
https://zapodaj.net/2f60536ba4326.png.html - GET the rating https://zapodaj.net/71e52684343df.png.html - POST the rating
When adding the rating I do not want to add a user or date, because it is automatically completed on the sevice layer. How to ignore these fields so that they are not shown at all and that the user can not complete these fields when sending the assessment POST, and that they can only be seen when displaying GET.
Solution
You can set the readOnly attribute to true for the properties which should be shown in the response, but not in the request.
private Integer rate;
@ApiModelProperty(readOnly = true)
private String user;
@ApiModelProperty(readOnly = true)
private Date date;
The model generated by swagger-fox will be
"definitions": {
"Obj": {
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date-time",
"readOnly": true
},
"rate": {
"type": "integer",
"format": "int32"
},
"user": {
"type": "string",
"readOnly": true
}
}
}
}
In the swagger editor, it will be displayed in the following manner.
Answered By - Ranjith
Answer Checked By - David Marino (JavaFixing Volunteer)