问题标签 [spring-restdocs]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
102 浏览

spring - RestAPI.exchange 返回 JSON

在我们的应用程序中,我们进行以下调用并以字符串形式接收响应。稍后我们将字符串操作为 JSON 并将 JSON 转换为 HashMap。(我们收到了非常大的 JSON 响应和将 String 转换为 JSON 和 JSON 转换为 HashMap。此操作在应用程序中需要很长时间)

ResponseEntity response = RestAPI.exchange(restTemplate, url, HttpMethod.GET, request, String.class);

有什么方法可以从 RestAPI.exchange 获取 JSON 格式的响应,或者有什么想法可以避免这种时间采取行动?

0 投票
1 回答
246 浏览

excel - 使用 Spring-doc 的 Excel 上传 API 文档

我有一个 Spring REST API,它将一个 Excel 文件上传到服务器。我需要用 spring 和 AsciiDoc 编写一个 API 文档。我尝试按照以下方式编写文档,但在文档 HTML 中它显示了来自 excel 的编码字符。

此代码完美运行,但以下列方式生成文档。

在此处输入图像描述

0 投票
1 回答
1118 浏览

java - Spring restdocs conditionally highlight optional parameters with asciidoc

I am using spring restdocs to produce documentation on my REST webapi; I have integrated the thing and my html gets generated (maven + asciidoc plugin, restassured apis). The only problem I have is that ifeval either doesn't work as advertised or I got it wrong.

My custom request-fields.snippet looks like this:

The 'optional' value in the tablecellcontent is rendered correctly ('true' or 'false' depending on the case), but the ifeval is not parsed (and thus shows itself unparsed on the final html, with no error).

I tried different syntaxes for the expression but none seem to work; any hints on what may be the correct syntax, if any? I am thinking about defining a custom attribute and use ifndef to get the same result, but I would prefer to use the existing optional() support if possible.

As requested I am adding the resulting .adoc

0 投票
2 回答
4356 浏览

java - Spring Rest Doc 不生成 html

我逐字遵循 Spring Rest Doc的入门指南,但我无法从生成的片段中获取任何 html。

片段在我配置的目录(build/generated-snippets)中生成得很好,但我看不到任何 html5/ 目录,其中包含从片段中生成的 html 文件。

文档在某些时候说明了如何将文档打包到 jar 中,很明显它需要 html5/ 目录中的一些文件,但这不是在构建运行时创建的:

我错过了什么?

我的项目文件build.gradle

和一个我用来测试的简单测试文件:

0 投票
1 回答
1877 浏览

spring - 在 AsciiDoc 中使用标签(Spring Rest Docs)

我正在使用 Spring Rest Docs 生成文档。我想做一些类似 Bootstrap 的Togglable tabs的事情。

Spring 文档使用可切换选项卡,但我不知道该怎么做。这是一个示例(MockMvc / REST Assured):http ://docs.spring.io/spring-restdocs/docs/1.1.0.RELEASE/reference/html5/#documenting-your-api 感谢您的帮助。

0 投票
1 回答
297 浏览

json - 如何确保我的文档与 Spring Rest Docs 保持同步?

我真的很喜欢使用失败的测试来确保文档是最新的概念。但我不知道如何使它适用于嵌套的 json。Spring REST Docs 处理分层有效负载的方式似乎违背了目的:

记录字段时,如果在有效负载中找到未记录的字段,则测试将失败。同样,如果在有效负载中找不到记录的字段并且该字段未标记为可选,则测试也将失败。对于具有分层结构的有效负载,记录一个字段足以使其所有后代也被视为已记录。

您将如何为嵌套 json 编写测试,以便对有效负载的更改导致测试失败?

例子:

测试:

即使 car.motor.power 和 suspend.type 没有定义,使用这些响应字段定义的测试也会通过。有没有办法让它工作?多次测试?

0 投票
1 回答
96 浏览

spring-restdocs - Spring Restdocs 源 gradle 构建在测试期间失败

我已经下载了 Spring RESTdocs 的 1.1.0-RELEASE 标记源代码的副本,但是“gradlew build”在测试阶段失败了。502 次测试中有 273 次失败,此错误有所不同: org.springframework.restdocs.request.RequestPartsSnippetTests > requestPartsWithOptionalColumn[Markdown] FAILED java.lang.AssertionError: Expected: is adoc snippetPart | Optional | Description ---- | -------- | ----------- a | true | one b | false | two but: was:Part | Optional | Description ---- | -------- | ----------- a | true | one b | false | two

问题看起来是字符串“adoc snippet”前缀在预期输出的开头。我认为这是不对的,尽管我可以在 AbstractContentSnippetMatcher.describeTo() 中看到它为什么会发生并且看起来不是很有条件,所以也许是测试的实际结果是错误的?

我没有对源代码做任何更改*,但我没有看到其他人报告这个问题,所以我很困惑。我对 gradle 完全陌生。我需要设置某种配置以使测试通过吗?我应该使用不同的目标吗?

(好的... 1 个小改动:我从 checkStyle 中删除了文件末尾的换行检查 - 我正在从 Github 下载到 Windows PC。)

0 投票
1 回答
115 浏览

spring - Rest docs with Spring data Rest for Spring-data-couchbase

嗨,伙计们度过了非常艰难的一天,试图用 Spring Data Couchbase 和 Spring Data Rest 找出 Restdocs。

目前我有一个利用 spring-Data-Rest-Hal-Browser 的 Spring-Data-Couchbase 项目。这很棒,因为它基本上覆盖了具有完整 Restful 服务支持的 CRUD Couchbase 存储库。我喜欢 Hal 浏览器,但是,我想用 Spring Restdocs 来扩充项目以获得额外的文档。

我不关心测试提供的基本 CRUD 功能,但是,我想利用测试驱动的文档方法来确保文档始终是最新的。有没有办法完全模拟 Couchbase 或内存表示中的某种基线,我可以用它来完成这个?

如果可能的话,我绝对会喜欢样本或参考文档,或者....以及任何可以帮助我的东西。我已经坚持了将近一个星期了:(

非常感谢任何可以提供帮助的人!

我将我当前的代码上传到 Github,以便任何人都可以在需要时获得更清晰的图片: https ://github.com/Mandalorian007/couchbase-service-example/

0 投票
1 回答
4540 浏览

spring-restdocs - spring-rest-docs 应用程序在运行或集成测试时未生成片段

我的测试课是

pom.xml

如果我使用mvn spring-boot:run没有文档生成。

如果我使用mvn integration-test我会得到 api-guide.adoc [html 文件] 但没有片段

如果我尝试运行, mvn -Dtest=com.htc.spring.rest.docs.ForRestDocumentationTest test 我会收到此错误:

0 投票
2 回答
431 浏览

json - Grails 3.1.8:Spring Rest Docs 使用 Rest Assured 提供 PayloadHandlingException:com.fasterxml.jackson.databind.JsonMappingException

我正在尝试使用 grails rest-api 的片段实现 ascii 文档,并为 json 响应提供保证:

和 UserDocumentationApiSpec(as IntegrationTest) 的代码片段:

这部分代码给了我错误跟踪:

请纠正我哪里出错了...