2015-04-29 81 views
0

我尝试使用swagger,spring-rest-doc和spring-fox生成基于spring mvc的rest服务的文档。但是,我的挑战是记录基于spring安全xml配置的端点。到目前为止,春狐已经成为赢家。但它记录了所有弹簧安全支持的方法。关于如何筛选出我需要的想法?使用xml配置的弹簧安全性的Swagger文档

举例来说,当我使用/swagger-ui.html拉起文档页面 我看到以下组:

  • 基本误差控制器
  • 授权端点
  • 白色标签-approval端点
  • 健康检查

其中我只需要授权,ENDP oint和健康检查器。有任何想法吗?

回答

0

你看过文档to transition to 2.0

@Bean 
public Docket swaggerSpringMvcPlugin() { 
    return new Docket(DocumentationType.SWAGGER_2) 
     .groupName("business-api") 
     .select() 
      //Ignores controllers annotated with @CustomIgnore 
      .apis(not(withClassAnnotation(CustomIgnore.class)) 
      // and by paths 
      .paths(paths()) 
      .build() 
     .apiInfo(apiInfo()) 
     .securitySchemes(securitySchemes()) 
     .securityContext(securityContext()); 
} 

您应该能够使用RequestHandlerSelectors筛选您使用以下谓词需要 API的

  • 类注释,如例显示上述withClassAnnotation
  • 方法的注释(用于过滤操作) withMethodAnnotation
  • 由基础包装basePackage

我怀疑你已经想出了如何让它与XML配置工作(在这种情况下,这个问题的标题是不正确的)。如果你需要更多的例子,还有很多demos and examples。如果您还有其他问题,问题跟踪器可能比我们不经常使用的stackoverflow.com更好。

+0

感谢您的回复。我伸出了另一个论坛,你回答(谢谢)。问题在于spring(2.0.5)中的tokenendpoint将endpoint/oauth/token暴露给所有的http方法。无法弄清楚如何过滤出特定的方法。 – picsram

+0

这个'.apis(not(withClassAnnotation(CustomIgnore.class))'不适用于我的2.2.2。 –

+1

@MikhailBatcer'@ ApiIgnore'已经被支持。'not(....)'技术只是如果你不想使用springfox提供的注释,无论如何,如果它不起作用,请创建一个问题。 –