我@EnableSwagger2
注释类包含下列方法:
@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)
)
)
;
}
其中InputExample
是包含与@ApiModelProperty
注释许多不同的属性的类。
在我的REST控制器的方法是这样的:
@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
{
...
}
可悲的是,当我跑我的服务,然后打开我的上扬鞭UI终点,我看到的是:
那会是由以下原因造成?如何调试呢?
P.S:在@EnableSwagger2
的其余部分 - 类确实工作。
目前似乎已经与原来的类型Map<String, Object>
压倒一切的一切开发者添加到.alternateTypeRules()
内部规则。
我能找到解决这个问题的唯一方法是创建一个class MyInputMap extends Map<String, Object>
并在有关的所有端点使用它,同时还调整类型规则:
newRule(
typeResolver.resolve(MyInputMap.class),
typeResolver.resolve(InputExample.class)
)