嗨,我有一个在我的应用程序中实现SwaggerSpecFilter的要求,但是它不起作用。我相信我不会在Spring配置的任何地方添加FIlter。
请您提示可能是什么问题
@SpringBootApplication
@EnableScheduling
@EnableAutoConfiguration
@EnableSwagger2
public class CDRestLauncher {
public static void main(String[] args) throws IOException {
FilterFactory.setFilter(new SwaggerFilter());
SpringApplication.run(CDRestLauncher.class, args);
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Swagger Documentation")
.description("Spring Swagger Application")
.contact("abc@gmail.com")
.build();
}
}
这是我的Filter类:
public class SwaggerFilter implements SwaggerSpecFilter{
public static final String PUBLIC = "public";
@Override
public boolean isOperationAllowed(Operation arg0, ApiDescription arg1, Map<String, List<String>> arg2,
Map<String, String> arg3, Map<String, List<String>> arg4) {
return true;
}
@Override
public boolean isParamAllowed(Parameter param, Operation arg1, ApiDescription arg2, Map<String, List<String>> arg3,
Map<String, String> arg4, Map<String, List<String>> arg5) {
System.out.println("Parameter name is: " + param.getName());
if(param.getAccess().equalsIgnoreCase("UNIX")) {
return false;
}
return true;
}
@Override
public boolean isPropertyAllowed(Model arg0, Property arg1, String arg2, Map<String, List<String>> arg3,
Map<String, String> arg4, Map<String, List<String>> arg5) {
return true;
}
}
这就是我的应用方式:
@ApiOperation( value = "Add User Authority", notes = "The Add User Authority API is used to add a user to the Connect:Direct server and set access rights for the user")
@ApiImplicitParams({
@ApiImplicitParam(value = SwaggerSinglePoint.DESC_USER_ID, dataType = CDSwaggerPrimitives.STRING, name = SwaggerSinglePoint.USER_ID, paramType = CDSwaggerPrimitives.PARAMA_TYPE_QUERY, access = "UNIX"),
})
@RequestMapping(method = RequestMethod.POST, produces = CDConstants.JSON_RESPONSE_DATA_FORMAT, consumes = CDConstants.JSON_REQUEST_DATA_FORMAT)
public String addUserAuth(@SuppressWarnings("rawtypes") @RequestBody(required=false) HashMap requestParamMap, HttpServletResponse response, HttpServletRequest request)
{
// Business Logic
}
任何帮助将不胜感激。