ENV:
- springboot-2.0.2.RELEASE , springfox-swagger-ui-2.8.0 , springfox-swagger2-2.8.0
Q:
- I encapsulated a unified return object.
public class ResultVO<T> implements Serializable {
// Omit content
}
- I used swagger-ui on Controller as API doc . He works in these places and works very well.
@ApiOperation(value = "pageList", notes = "paging select", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value="/pageList",method={RequestMethod.GET,RequestMethod.POST})
@CtlResultAnnotation
public ResultVO<PageInfo<DicBase>> pageList(DicBase dicBase, @RequestParam(defaultValue="1") int pageNum,
@RequestParam(defaultValue="10") int pageSize, HttpServletRequest request){
// Omit content
}
@ApiOperation(value = "children", notes = "get children", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value="/children",method={RequestMethod.GET,RequestMethod.POST})
@CtlResultAnnotation
public ResultVO<List<DicBase>> getChildren(@RequestBody(required=false) DicBase dicBase){
// Omit content
}
@ApiOperation(value = "view", notes = "detail", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value="/view",method=RequestMethod.GET)
@CtlResultAnnotation
public ResultVO<DicBase> view(@RequestParam Long id){
// Omit content
}
- when I add this controller,I get an error on ‘swagger-ui.html’.
@ApiOperation(value = "dicValues", notes = "keys-values", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value="/dicValues",method=RequestMethod.POST)
@CtlResultAnnotation
public ResultVO<Map<String, List<DicBase>>> dicValues(@RequestParam(value = "keys[]") List<String> keys){
// Omit content
}
Errors
Resolver error at definitions.Map«string,List«DicBase»».additionalProperties.$ref
Could not resolve reference because of: Could not resolve pointer: /definitions/List does not exist in document
- Here is my swagger configuation. I know I should add ‘alternateTypeRules’, but I can not found a full document about this.
private ApiInfo setApiInfo(String title, String description, String teamService, String version) {
return new ApiInfoBuilder().title(title).description(description).termsOfServiceUrl(teamService).version(version).build();
}
@Bean
public Docket adminRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(setApiInfo("admin-api doc","(PMP)-system-api doc","https://blog.csdn.net/xu_san_duo", "1.0"))
.alternateTypeRules(
newRule(
typeResolver.resolve(
DeferredResult.class,
typeResolver.resolve(GenericType.class, WildcardType.class)
),
typeResolver.resolve(WildcardType.class)
)
)
.groupName("admin module")
.select()
.apis(RequestHandlerSelectors.basePackage("com.sdcm.web.controller.admin"))
.paths(PathSelectors.any())
.build();
}
- I want a standard or detailed way, I hope to get your help. Thanks.
I was able to prevent the bad reference from being generated by adding this to my
Docket
.where my type was
Map<String, Map<String, List<String>>>
ButI still think an invalid spec should be created. Perhaps a warning with instructions on how to handle nested Generics more than n levels deep? If that is the accurate description. 😃
The same problem in 2.9.2 version~~~~!~!~!
@dingziyang Just replace my
String.class
with your objects. Something like this:I cannot test this, but you should be able to take it from here.
@prowave thanks for the work around. There is a pr out there, but its not an ideal solution, will take a look at it.
I encountered the same problem.but I don"t want fix it like add alternateTypeRules. If the problem is processed, please let us know.thanks!
@dingziyang Take a look at this.
i also got the same issue but for my case it seems every module has got it log error. forexample Resolver error at paths./reportingrest/reportdata.post.parameters.0.schema.$ref Could not resolve reference because of: Could not resolve pointer: /definitions/ReportingrestReportdataCreate does not exist in document. Could any one direct me of where they error may arose from.
@dingziyang
import com.fasterxml.classmate.TypeResolver;