I am trying to get the response example value in the Swagger UI docs to correctly display a map. This is what my map looks like: Map<Long, List<UserRole>>
. The UserRole object just has two fields, roleId & roleName.
According to the Javadoc for Swagger annotations the responseContainer supports Valid values are "List", "Set" or "Map". Any other value will be ignored.
However, this is the implementation inside of the SpringFox Swagger common library:
if ("List".compareToIgnoreCase(responseContainer) == 0) {
return Optional.of(resolver.resolve(List.class, response));
} else if ("Set".compareToIgnoreCase(responseContainer) == 0) {
return Optional.of(resolver.resolve(Set.class, response));
} else {
return Optional.of(resolver.resolve(response));
}
Obviously this does not support a Map.
If I don't specify a response type: @ApiResponse(code = 200, message = "OK")
then the Swagger docs look like this:
{
"additionalProp1": [
{
"roleId": 1234,
"roleName": "User"
}
],
"additionalProp2": [
{
"roleId": 1234,
"roleName": "User"
}
],
"additionalProp3": [
{
"roleId": 1234,
"roleName": "User"
}
]
}
This is almost correct except that I need to replace the additionalPropX
field with a long value. I have tried setting the examples several different ways: @ApiResponse(code = 200, message = "OK", examples = @Example(value = @ExampleProperty(value = "Puppy"))),
. I don't think that is implemented in SpringFox. I tried creating a new POJO to wrap my response but that just causes some really weird response examples.
I am using the latest Swagger dependencies through Gradle:
compile 'io.springfox:springfox-swagger-ui:2.9.2'
compile 'io.springfox:springfox-swagger2:2.9.2'
Is this possible?