Swagger Springfox:未应用备用类型规则
我的Swagger Springfox:未应用备用类型规则,swagger,swagger-ui,springfox,Swagger,Swagger Ui,Springfox,我的@EnableSwagger2注释类包含以下方法: @Bean public Docket myServiceApi() { return new Docket(DocumentationType.SWAGGER_2).groupName("My Service API").apiInfo(apiInfo()).select() .paths(PathSelectors.regex("/api.*")).build()
@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
{
...
}
@api操作(
value=“做事”,
consumes=MediaType.APPLICATION\u JSON\u值,
products=MediaType.APPLICATION\u JSON\u值,
response=SomeOutput.class
)
@请求映射(
value=“/api/v1/stuff”,
method=RequestMethod.POST,
使用={MediaType.APPLICATION_JSON_VALUE},
产生={MediaType.APPLICATION\u JSON\u VALUE}
)
@蜂鸟反应(
值={
@ApiResponse(代码=200,message=“服务执行成功”),
@ApiResponse(代码=400,消息=“输入数据错误”),
@ApiResponse(代码=500,message=“发生内部服务器错误”),
@ApiResponse(代码=503,消息=“服务当前不可用”)
}
)
公共响应DosServicesTuff(
HttpServletRequest请求,
@RequestBody映射输入内容
)投掷
验证异常,
ServiceUnavailableException,
IOException,
WorkflowDocumentProcessingException
{
...
}
遗憾的是,当我运行服务并在Swagger UI上打开端点时,我看到的只是:
这是什么原因造成的?我如何调试这个
注意:
@EnableSwagger2
-类的其余部分确实起作用。似乎已经有了一个内部规则,原始类型Map
覆盖了开发人员添加到.alternateTypeRules()
中的任何内容
解决此问题的唯一方法是创建一个类MyInputMap extends Map
,并在所有相关端点中使用它,同时将类型规则调整为:
newRule(
typeResolver.resolve(MyInputMap.class),
typeResolver.resolve(InputExample.class)
)
似乎已经有一个内部规则,其原始类型
Map
覆盖了开发人员添加到.alternateTyperles()
的任何内容
解决此问题的唯一方法是创建一个类MyInputMap extends Map
,并在所有相关端点中使用它,同时将类型规则调整为:
newRule(
typeResolver.resolve(MyInputMap.class),
typeResolver.resolve(InputExample.class)
)