【问题标题】:Swagger document for spring security using xml configuration使用 xml 配置的 Spring Security 的 Swagger 文档
【发布时间】:2015-04-29 16:42:31
【问题描述】:

我尝试使用 swagger、spring-rest-doc 和 spring-fox 为基于 spring mvc 的休息服务生成文档。但是,我的挑战是记录基于 spring security xml 配置的端点。到目前为止,spring-fox 一直是赢家。但它记录了 Spring Security 支持的所有方法。关于如何过滤掉我需要的任何想法?

例如,当我使用 /swagger-ui.html 拉出文档页面时 我看到以下组:

  • 基本错误控制器
  • 授权端点
  • whitelabel-approval-endpoint
  • 健康检查器

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

【问题讨论】:

    标签: xml spring-security swagger


    【解决方案1】:

    你看过文档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 更好。

    【讨论】:

    • 感谢您的回复。我在另一个论坛上联系了你,你回答了(谢谢)。问题是 spring (2.0.5) 中的 tokenendpoint 将端点 /oauth/token 暴露给所有 http 方法。无法弄清楚如何过滤掉特定的方法。
    • 这个 .apis(not(withClassAnnotation(CustomIgnore.class)) 不适用于 2.2.2。
    • @MikhailBatcer @ApiIgnore 已被支持。 not(....) 技术仅在您不想使用 springfox 提供的注释时使用。无论如何,如果它不起作用,请创建一个问题。
    猜你喜欢
    • 1970-01-01
    • 2017-03-03
    • 2014-12-07
    • 2014-02-25
    • 2015-11-19
    • 2021-02-15
    • 2016-10-24
    • 1970-01-01
    • 2019-09-13
    相关资源
    最近更新 更多