swagger 2 spring boot 生成yml文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36745620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 01:03:52  来源:igfitidea点击:

swagger 2 spring boot generate yml file

springspring-bootyamlswaggerswagger-2.0

提问by ken

I'm new to swagger, contracts, and working on Spring boot (gradle) project where we are just starting with dealing with contracts. I've used grails, love how you can put field defs in the Domain and it gets inherited up through the stack.

我是 swagger、合同和 Spring Boot (gradle) 项目的新手,我们刚刚开始处理合同。我使用过 grails,喜欢将字段定义放入域中并通过堆栈向上继承的方式。

A specific question and maybe a piggy backed splanation question too.

一个特定的问题,也可能是一个猪支持的 splanation 问题。

How can I generate basic stub of a YAML file from the standard Controller Class?

如何从标准控制器类生成 YAML 文件的基本存根?

I understand I'm supposed to create a [Name]-v1-0.yml file in the directory controller\src\test\resources

我知道我应该在目录中创建一个 [Name]-v1-0.yml 文件 controller\src\test\resources

I've implemented the swagger-ui.html in the project and a really cool interactive web page comes up showing request end points and stuffs. Using a class SwaggerConfig extends WebMvcConfigurerAdapterthat works to publish the interfaces in ui json doc web page.

我已经在项目中实现了 swagger-ui.html,一个非常酷的交互式网页出现了,显示了请求端点和内容。使用class SwaggerConfig extends WebMvcConfigurerAdapter可用于在 ui json doc 网页中发布接口。

I believe the understanding is that the yml file in the test resources directory will be a fixed generation of the "contracts" and used in some sort of gradle test method to make sure the API signature and contract points have not changed, like a basic junit style test of the interface. (Yes/no?)

我相信理解是测试资源目录中的 yml 文件将是“合同”的固定生成,并在某种 gradle 测试方法中使用以确保 API 签名和合同点没有改变,就像一个基本的 junit界面风格测试。(是/否?)

I'm lazy here thinking to myself, why am I hand hacking this stupid file? Can a yaml doc skeleton be generated for me pretty easy from the controller/model details?

我在这里很懒惰在想,我为什么要手动破解这个愚蠢的文件?可以很容易地从控制器/模型细节为我生成 yaml doc 骨架吗?

For example on the page takes a YML file and does the ui friendly page: http://editor.swagger.io/#/

例如在页面上采用 YML 文件并执行 ui 友好页面:http: //editor.swagger.io/#/

There's a really nice "uber" sample YAML file in that page, do I really need to write that, I already wrote the Controller, javadoc, annotated, all sorts of cool stuff that should be able to generate at least a pretty good starting stub of the yaml, (I blame you grails for not wanting to hack this!) that's before of course putting SpringFox annotations which do more cool stuffs and really going to town to drive more this testing contract assurance.

该页面中有一个非常好的“超级”示例 YAML 文件,我真的需要编写它吗,我已经编写了控制器、javadoc、带注释的各种很酷的东西,至少应该能够生成一个很好的起始存根在 yaml 中,(我责怪你 grails 不想破解这个!)当然是在放置 SpringFox 注释之前,这些注释可以做更多很酷的事情,并且真的要去镇上推动更多这个测试合同保证。

FYI: 'spring-boot-starter-web' 'spring-boot-starter-test' 'springfox-swagger-ui', version: '2.4.0'

供参考: 'spring-boot-starter-web' 'spring-boot-starter-test' 'springfox-swagger-ui', version: '2.4.0'

回答by ken

I got it. Very simple, why didn't I see this anywhere. :)

我知道了。很简单,为什么我在任何地方都没有看到这个。:)

Copy / paste the resource path in the browser:

在浏览器中复制/粘贴资源路径:

http://localhost:8095/v2/api-docs?group=full-api

Select the generated content and copy to the clipboard.

选择生成的内容并复制到剪贴板。

Open the Swagger Editor in a browser:

在浏览器中打开 Swagger 编辑器:

http://editor.swagger.io

http://editor.swagger.io

Select Paste JSON… from the File menu.

从文件菜单中选择粘贴 JSON...。

Paste the generated Swagger JSON content and click on Import.

粘贴生成的 Swagger JSON 内容并单击导入。

回答by Didac Montero

There is a feature request to provide a yaml representation of the specs: https://github.com/springfox/springfox/issues/651

有一个功能请求提供规范的 yaml 表示:https: //github.com/springfox/springfox/issues/651

Besides the progress, it is not available yet

除了进度,目前还没有