java - Spring-restdocs:如何制作参数、路径和响应字段代码块

标签 java documentation spring-restdocs

我正在使用 spring-restdocs 生成 API 文档,我希望将所有参数、路径和响应字段 JSON 路径打印为表格内的代码部分(Asciidoc 中的反引号)。

例如,JSON 路径 sprockets.[].widgets.[].contentType 比 sprockets.[].widgets.[].contentType 更难以可变宽度字体读取,以等宽字体打印。

请求参数和路径参数也是如此 - 这些是应该以等宽字体打印的标记。

使用 Spring-restdocs 实现这一目标的最简单方法是什么?

预先感谢您的帮助。

G

最佳答案

我认为 REST 文档应该默认执行此操作。我提出了一个将在 1.1 中修复的问题:https://github.com/spring-projects/spring-restdocs/issues/230 。感谢您的建议。

同时,您可以使用custom snippet templates做您想做的事。例如,要自定义请求字段路径的格式,您需要提供 request-fields.snippet文件在 src/test/resources/org/springframework/restdocs/templates看起来像这样:

|===
|Path|Type|Description

{{#fields}}
|`{{path}}`
|{{type}}
|{{description}}

{{/fields}}
|===

注意 {{path}} 周围的反引号.

关于java - Spring-restdocs:如何制作参数、路径和响应字段代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37140695/

相关文章:

java - 将带有周和年的字符串解析为 LocalDate

Python 获取实例变量的 __doc__ 文档

c# - 生成的 WEB API 帮助区域文档不显示响应正文格式/示例

testing - JUnit 测试索引

SpringRestDoc SnippetException : Fields with the following paths were not found in the payload:

java - 如何在 Spring REST 文档中记录树

java - 将字符串时间戳转换为符合 ISO 8601 的字符串

java - 如何用注解抛出异常?

java - 字符串长度问题

java - JUnit 5 和 Webflux 的 Spring Rest 文档