Reputation: 37916
I use SpringFox and Swagger UI for API documentation.
I have a DTO in which there is a property which is of type Long. It's not populated 99% of time so I want to demonstrate this fact in documentation by setting the property value to null
. So I want this JSON in examples section
{
/* ... */
"legacyId": null
}
I've already tried
@ApiModelProperty(value = "legacyId", example = null)
public Long getLegacyId() {
return legacyId;
}
But I got a warning "Attribute value must be constant". What else I can do ?
Upvotes: 5
Views: 9161
Reputation: 27048
As you can see here, there is no null dataType. You have two options
You can define as
@ApiModelProperty(example = "null") --> This will display as "null"
This will mislead the user and might lead to NPE
@ApiModelProperty(hidden = true)
personally, I would prefer second one because, when spring maps the json from UI in your controller, if nothing is passed from frontend, it will be null automatically.
Upvotes: 7