注释中的Spring-restdocs字段描述

Bar*_*cki 1 spring-restdocs spring-auto-restdocs

是否可以使用注释(在字段级别)为字段提供描述?

我知道我可以使用description方法

.andDo(document("index", responseFields( 
            fieldWithPath("contact").description("The user's contact details"), 
Run Code Online (Sandbox Code Playgroud)

但是我更希望将该描述与字段定义一起放在我的响应对象中。

class IndexResponse {
 //The user's contact details
 String contract;
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以生成约束描述(http://docs.spring.io/spring-restdocs/docs/current/reference/html5/#_using_constraint_descriptions_in_genic_snippets),但是它仅生成验证注释的描述。

我正在寻找来自Swagger的https://github.com/swagger-api/swagger-core/wiki/Annotations#apimodelproperty之类的东西。

And*_*son 5

它没有。我是 REST Docs 项目的负责人,我认为注释不是编写文档的好方法。如果您不同意该意见并希望使用注释,您可以编写一个类似于约束描述中所做的附加组件。您可以将一个类传递给它以进行自省并自动生成FieldDescriptor实例,然后您可以将这些实例传递到请求和响应字段片段中。


小智 5

我们构建了Spring REST Docs的扩展,该扩展允许使用Javadoc进行字段描述:

class IndexResponse {
  /**
   * The user's contact details
   */
  String contract;
}
Run Code Online (Sandbox Code Playgroud)

但是目前这仅在使用Jackson和MockMvc测试的情况下有效。

项目:https//github.com/ScaCap/spring-auto-restdocs

简介文章:https//dzone.com/articles/introducing-spring-auto-rest-docs