首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阐明Spring annotations文档

阐明Spring annotations文档
EN

Stack Overflow用户
提问于 2013-07-03 20:34:30
回答 2查看 1.1K关注 0票数 3

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

工件安全性生成Web API文档,但是它忽略了Spring注解,比如:@Secured (来自maven-enunciate-plugin -security)

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

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-17 16:22:48

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

我修改了docs.xml.fmtenunciate-docsdocs.fmt,这样'@Secured‘注释就可以识别了。

不幸的是,对于docs.xml.fmt来说,没有像我们在docs.fmt中那样的干净的定制方法。所以,我不得不用这些修改过的文件打包自己。

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

docs.fmt文件中,将此块添加到isDeprecated的类似功能块下面

代码语言:javascript
复制
[#function isSecured element]
  [#return (getTagValues(element, "secured")?size > 0)/]
[/#function]

现在,

就在这个区块的下面:

代码语言:javascript
复制
[#if isDeprecated(resource)]
 <p class="alert">This resource has been deprecated.</p>
[/#if]

添加另一个if块

代码语言:javascript
复制
[#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文件中,如下所示:

代码语言:javascript
复制
[#if resource.parent.annotations["java.lang.Deprecated"]??]
  <tag name="deprecated"/>
[/#if]

添加以下块

代码语言:javascript
复制
[#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]
票数 4
EN

Stack Overflow用户

发布于 2013-07-07 04:12:34

恐怕不行。虽然可以添加该功能,但Enunciate不能识别这些Spring注释。欢迎您访问open up a request

( maven-enunciate-spring-plugin只是用来阐明Spring到后端运行时的连接,它不包括您所询问的特性。)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17448136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档