I am using Spring MVC (via Spring Boot) and have integrated Swagger API documentation using the swagger-spring-mvc library.
I have a class that looks something like this:
@ApiModel
public class CartItem {
...
private Money listPrice; // joda money class
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty(required = true, dataType = "java.lang.String")
public Money getListPrice() {
return listPrice;
}
...
}
Since I'm using the ToStringSerializer for this field, it's returning listPrice.toString in the JSON, in other words:
{
"listPrice": "USD 10.50"
}
However, the swagger documentation is not honoring the dataType = "java.lang.String". It shows the response model as:
"CartItem": {
"description": "",
"id": "CartItem",
"properties": {
"listPrice": {
"required": false,
"type": "Money"
}
}
}
I have tried putting the @ApiModelProperty annotation on the field as well as the method, and in both cases the required
field is respected, but the dataType
field is ignored. I have also tried using "String", "string", and "java.lang.String" for the dataType but none of those have worked.
Am I missing something, or is this just a bug in the swagger-spring-mvc library?