【问题标题】:Enunciate Spring annotations API documentation阐明 Spring 注释 API 文档
【发布时间】:2013-07-03 12:34:29
【问题描述】:

我正在使用 Enunciate 在 maven 项目中生成 REST API 文档。

工件 maven-enunciate-plugin 生成 Web API 文档,但它忽略 Spring 注释,例如:@Secured(来自 spring-security)

我尝试使用支持 spring 的 maven artifact maven-enunciate-spring-plugin 生成文档,但它甚至不生成 Web API 文档。

有没有办法配置 enunciate 或使用另一个 enunciate maven 插件,以便在 Enunciate 生成的文档中识别和提及来自 Spring 的注释?

【问题讨论】:

    标签: spring maven documentation enunciate


    【解决方案1】:

    没关系,我设法通过“将自定义皮肤应用到 Enunctiate 的文档”(http://docs.codehaus.org/display/ENUNCIATE/Applying+a+Custom+Skin+to+Enunciate%27s+Documentation) 解决了这个问题

    我修改了docs.xml.fmtdocs.xml.fmtdocs.fmt,以便识别“@Secured”注解。

    不幸的是,对于docs.xml.fmt,没有像docs.fmt 那样干净的自定义方式。所以,我不得不用这些修改后的文件打包自己。

    我提到了@Deprecated(java.lang.Deprecated)是如何处理的,并遵循了类似的方法。

    docs.fmt文件中,将该块添加到isDeprecated类似功能块的正下方

    [#function isSecured element]
      [#return (getTagValues(element, "secured")?size > 0)/]
    [/#function]
    

    现在,

    就在这个块下面:

    [#if isDeprecated(resource)]
     <p class="alert">This resource has been deprecated.</p>
    [/#if]
    

    添加另一个 if 块

    [#if isSecured(resource)]
      <p class="note">This resource is available only to these roles:  
      [#assign securedTags = getTagValues(resource, "secured") /]
      [#if securedTags?size > 0]
        ${securedTags[0]}
      [/#if]
    
      [#list resource.parent.annotations as tag]
          ${tag}
      [/#list]
      </p>
    [/#if]
    

    现在,在docs.xml.fmt 文件中,就在下面:

    [#if resource.parent.annotations["java.lang.Deprecated"]??]
      <tag name="deprecated"/>
    [/#if]
    

    添加以下块

    [#if resource.parent.annotations["org.springframework.security.access.annotation.Secured"]??]
      <tag name="secured">
    
        [#list resource.parent.annotations["org.springframework.security.access.annotation.Secured"]["value"] as roles]
          <![CDATA[${roles}]]> 
        [/#list]
    
      </tag>
    [/#if]
    

    【讨论】:

      【解决方案2】:

      恐怕不会。尽管可以添加该功能,但 Enunciate 无法识别那些 Spring 注释。欢迎您来open up a request

      maven-enunciate-spring-plugin 仅用于将 Spring 中的 Enunciate 连接到后端运行时,它不包括您要询问的功能。)

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 2010-09-05
      • 1970-01-01
      • 1970-01-01
      • 2010-10-02
      • 2014-10-30
      相关资源
      最近更新 更多