简体   繁体   English

在Spring REST Docs中包含“试用”表单

[英]Including a “try out” form in Spring REST Docs

I am starting to use Spring REST Docs but I miss a nice feature of swagger... the "try it out!" 我开始使用Spring REST Docs,但是我错过了一个强大的功能……“尝试一下!” button that includes a HTML form to test the API. 按钮,其中包含用于测试API的HTML表单。 I get the curl link OK; 我知道卷曲链接; but I usually use swagger form. 但我通常使用摇摇欲坠的形式。 Is there a simple way to do this in Spring REST Docs? Spring REST Docs中有没有简单的方法可以做到这一点? Thanks 谢谢

I solved it for myself by creating a tool to convert Spring REST Docs cURL snippets to Postman collections. 我通过创建一个将Spring REST Docs cURL代码片段转换为Postman集合的工具自己解决了该问题。 It's available as a npm package: https://www.npmjs.com/package/restdocs-to-postman that can be used on the command line and as a library. 它以npm软件包的形式提供: https ://www.npmjs.com/package/restdocs-to-postman,可在命令行上使用并用作库。 This is one solution for https://github.com/spring-projects/spring-restdocs/issues/47 . 这是https://github.com/spring-projects/spring-restdocs/issues/47的一种解决方案。 In my opinion tools like Postman are good to try out APIs. 我认为像Postman这样的工具可以很好地尝试API。

Edit: There are converters from Postman and Insomnia to Swagger. 编辑:有从邮差和失眠到Swagger的转换器。 So with two conversions (restdocs to Postman/Insomnia and Postman/Insomnia to Swagger) one can get a Swagger playground. 因此,通过两次转换(将restdocs转换为Postman / Insomnia,将Postman / Insomnia转换为Swagger),可以转换为Swagger游乐场。 This is not optimal, but works. 这不是最佳方法,但是可以。

Examples for converters: 转换器示例:

Edit 2: I have created instruction on how to create a Swagger playground out of Spring REST Docs: https://github.com/fbenz/restdocs-to-swagger It takes a few steps and would be simpler if Spring REST Docs would directly produce a Swagger file, but it works and can be automated. 编辑2:我已经创建了有关如何从Spring REST Docs中创建Swagger操场的说明: https : //github.com/fbenz/restdocs-to-swagger这需要一些步骤,如果直接使用Spring REST Docs,它将更加简单产生Swagger文件,但是它可以工作并且可以自动化。

No, the closest I believe it can provide is a curl with an example request. 不,我相信它可以提供最接近的是curl用一个例子请求。 There is an open enhancements to provide Postman collections, https://github.com/spring-projects/spring-restdocs/issues/47 , but nothing as simple as Swagger's try it out! 有一个开放的增强功能可提供Postman集合, 网址https://github.com/spring-projects/spring-restdocs/issues/47 ,但是没有Swagger的try it out!简单try it out!

Also somewhat related from this ticket, https://github.com/spring-projects/spring-restdocs/issues/213 , 也与此票证有些相关, https://github.com/spring-projects/spring-restdocs/issues/213

I'm rather torn on trying to add support for generating a Swagger specification. 我很想尝试增加对生成Swagger规范的支持。 When you describe Swagger as providing an "API Playground", you've drawn a very important distinction that many others do not. 当您将Swagger描述为提供“ API游乐场”时,您已经做出了非常重要的区分,而其他许多人则没有。 I firmly believe that Swagger's UI is not a substitute for API documentation and using it as such isn't good for a service or its users. 我坚信Swagger的UI不能替代API文档,因此使用它对服务或其用户不利。

My fear is that if Spring REST Docs provided support for producing a Swagger specification, people would then use that specification to populate Swagger's UI and consider their service to be documented. 我担心的是,如果Spring REST Docs为生成Swagger规范提供了支持,那么人们将使用该规范填充Swagger的UI并考虑将其服务记录在案。 It's a matter of weighing up trusting people to do the right thing, versus encouraging people to shoot themselves in the foot. 这是权衡信任人们做正确的事情,而不是鼓励人们用脚射击自己的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM