简体   繁体   English

如何以编程方式将JSON转换为Swagger YAML? 是否有REST API可以做到?

[英]How to convert JSON to Swagger YAML programmatically? Is there a REST API to do it?

I want to automate a process where I want to convert a JSON file to a YAML file particularly in the format of Swagger YAML. 我想自动化一个过程,在该过程中我想将JSON文件转换为YAML文件,尤其是以Swagger YAML的格式。 I have tried python and npm libraries but they dont give the same YAML. 我尝试了python和npm库,但它们没有给出相同的YAML。 Is there a Swagger REST API to do the job? 是否有Swagger REST API可以完成这项工作?

The REST way- REST方式

curl -X POST \\ https://generator3.swagger.io/api/generate \\ -H 'content-type: application/json' \\ -d @file-name.json -o result.zip curl -X POST \\ https://generator3.swagger.io/api/generate \\ -H'内容类型:application / json'\\ -d @ file-name.json -o result.zip

Or else 要不然

curl -X POST \\ https://generator3.swagger.io/api/generate \\ -H 'content-type: application/json' \\ -d '{ "spec" : "Key1: Value1, Key2: Value2", "lang" : "openapi-yaml", "type" : "CLIENT", "codegenVersion" : "V3" }' -o result.zip curl -X POST \\ https://generator3.swagger.io/api/generate \\ -H'内容类型:application / json'\\ -d'{“ spec”:“ Key1:Value1,Key2:Value2”,“ lang“:” openapi-yaml“,” type“:” CLIENT“,” codegenVersion“:” V3“}'-o result.zip

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

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