I have simple CXF-REST application for which for one of the services', I have an object as input. One of the parameters are mandatory for successful validation, however, swagger-ui shows optional or empty.
How to update it to show 'required' or a star mark ?
I tried using @ApiModelProperty(required=true)
, however no luck.
@Path("/user")
@Api(value = "/user", description = "User Service")
public interface UserService {
@POST
@Path("/saveUser")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Save User details to backend", response = User.class)
public User saveUser(User user);
}
@ApiModel(description = "User")
@XmlRootElement
public class User {
@ApiModelProperty(value = "", required = true)
private String name;
private Integer age;
//getters and setters
}
We use swagger-annotations_2.10-1.3.0.jar
,
swagger-core_2.10-1.3.0.jar
,
swagger-jaxrs_2.10-1.3.0.jar
in our application.
ScreenShot is in the link below
The swagger-ui.js javascript file can be updated as below, so that the 'required' string can appear in the model section for the specified attribute.
if(!propertyIsRequired) {
html += ', <span class="propOptKey">optional</span>';
} else {
html += ', <span class="propOptKey">required</span>';
}