My @EnableSwagger2
annotated class contains the following method:
@Bean
public Docket myServiceApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("My Service API").apiInfo(apiInfo()).select()
.paths(PathSelectors.regex("/api.*")).build()
.alternateTypeRules(
newRule(
typeResolver.resolve(Map.class, String.class, Object.class),
typeResolver.resolve(InputExample.class)
)
)
;
}
Where InputExample
is a class that contains many different properties annotated with @ApiModelProperty
.
The method in my REST controller looks like this:
@ApiOperation(
value = "Do stuff",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE,
response = SomeOutput.class
)
@RequestMapping(
value = "/api/v1/stuff",
method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE}
)
@ApiResponses(
value = {
@ApiResponse(code = 200, message = "Service execution successful"),
@ApiResponse(code = 400, message = "Bad input data"),
@ApiResponse(code = 500, message = "An internal server error occurred"),
@ApiResponse(code = 503, message = "The service is currently unavailable")
}
)
public ResponseEntity<SomeOutput> doServiceStuff(
HttpServletRequest request,
@RequestBody Map<String, Object> inputContent
) throws
ValidationException,
ServiceUnavailableException,
IOException,
WorkflowDocumentProcessingException
{
...
}
Sadly, when I run my Service and open my endpoint on Swagger UI, all I see is:
What could this be caused by? How can I debug this?
P.S.: The rest of the @EnableSwagger2
- class does work.
There already seems to be an internal rule with the original type Map<String, Object>
overriding whatever the developer adds to .alternateTypeRules()
.
The only way I could find to fix this is to create a class MyInputMap extends Map<String, Object>
and use it in all endpoints in question, while also adjusting the type rule to:
newRule(
typeResolver.resolve(MyInputMap.class),
typeResolver.resolve(InputExample.class)
)