将 Swagger JSON 转换为 RAML/YAML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32730224/
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
Convert Swagger JSON to RAML/YAML
提问by helios
How do I convert Swagger JSON to RAML/YAML and validate it? I am not looking for a programmatic way, just a one off conversion.
如何将 Swagger JSON 转换为 RAML/YAML 并对其进行验证?我不是在寻找一种编程方式,只是一次转换。
回答by helios
Here are the steps:
以下是步骤:
- Export Swagger JSON into a file on your drive. This JSON should be published on your server at the following URI: /swagger/docs/v1
- Go to http://editor.swagger.io/#/
- On the top left corner, select File-> Import File... Point to the local Swagger JSON file you exported in step #1 to open in the Swagger Editor
- Select Generate Client -> Swagger YAML option from the menu
- It will generate the YAML that you can validate at http://www.yamllint.com/site
- 将 Swagger JSON 导出到驱动器上的文件中。此 JSON 应发布在您服务器上的以下 URI:/swagger/docs/v1
- 转到http://editor.swagger.io/#/
- 在左上角,选择 File->Import File... 指向您在步骤 1 中导出的本地 Swagger JSON 文件以在 Swagger 编辑器中打开
- 从菜单中选择 Generate Client -> Swagger YAML 选项
- 它将生成您可以在http://www.yamllint.com/站点上验证的 YAML
回答by Adeel Ali
Conversion
转换
If you are looking to convert from any version Swagger to RAML 0.8 then APITransformer.com can do it for you. We're almost done with RAML 1.0 export. Will release it in a week's time.
如果您希望从任何版本的 Swagger 转换为 RAML 0.8,那么 APITransformer.com 可以为您完成。我们几乎完成了 RAML 1.0 的导出。将在一周内发布。
Validation
验证
The converted description comes out of the same code-gen engine that APIMatic uses to validate an API description before generating SDKs/Client libraries. Therefore, the converted RAML will be validated by default.
转换后的描述来自 APIMatic 在生成 SDK/客户端库之前用来验证 API 描述的相同代码生成引擎。因此,默认情况下将验证转换后的 RAML。
API descriptions in a variety of formats can also be validated via APIMatic's CLIor APIMatic's API
各种格式的 API 描述也可以通过APIMatic 的 CLI或APIMatic 的 API进行验证
回答by William Cheng
To convert API spec between various formats (e.g. Swagger/OpenAPI, RAML, Postman, etc), you can use the following free and open source tools:
要在各种格式(例如 Swagger/OpenAPI、RAML、Postman 等)之间转换 API 规范,您可以使用以下免费和开源工具:
回答by Nikhil Nanjappa
Its actually pretty simple
其实很简单
Web version of swagger editorgives the flexibility to import your existing swagger file(JSON/YAML) and download the configuration file that is currently being shown. So just combine these two.
swagger 编辑器的Web 版本可以灵活地导入现有的 swagger 文件(JSON/YAML)并下载当前显示的配置文件。所以只需将这两者结合起来。
Note: Converting JSON to YAML exists, but not JSON to RAML
注意:存在将 JSON 转换为 YAML,但不存在将 JSON 转换为 RAML
- First import your swagger JSON at http://editor.swagger.io/#/(File > Import File)
- Once you see your configurations, just download the corresponding YAML version (File > Download YAML).
- 首先在http://editor.swagger.io/#/ (文件 > 导入文件)导入你的 swagger JSON
- 看到您的配置后,只需下载相应的 YAML 版本(文件 > 下载 YAML)。
The YAML version of the JSON you just uploaded will be downloaded.
您刚刚上传的 JSON 的 YAML 版本将被下载。
回答by coding
While I wish there was a command line tool, this company has made a converter it seems:
虽然我希望有一个命令行工具,但该公司似乎制作了一个转换器:

