Swagger页面报错Resolver error at definitions

问题描述

打开swagger页面报错Resolver error at definitions


原因分析:

从错误提示可以看出,是由map引起的原因,具体是因为swagger配置没有默认添加map的复杂结构引起的,需要手动添加。


解决方案:

找到swagger配置类,在Docket方法里添加mapRule即可,Map的类型就按报错的标题格式添加。

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
 
        //参数可以多个
        docket.alternateTypeRules(
                AlternateTypeRules.newMapRule(String.class, Object.class),
                AlternateTypeRules.newMapRule(String.class, List.class)
            );
        return docket;
    }
}