如何从示例 JSON 生成 Swagger #definition [英] How to generate a Swagger #definition from sample JSON
本文介绍了如何从示例 JSON 生成 Swagger #definition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Take the following #definition from the pet store example. Given a #definition section a JSON structure can be generated
e.g.
Is there something that can do the reverse given a largeish complex JSON file?
Given the below JSON Structure can I get the #defintion section of a swagger file generated to save some typing
{
"variable": "sample",
"object1": {
"obj-field1": "field 1 of object",
"obj-field2": "field 2 of object",
"anArray": [
"Value 1",
{
"anArrayObj1": "obj1fieldinarray",
"anArrayObj2": "obj2fieldinarray"
}
]
}
}
解决方案
You can use this JSON-to-OpenAPI schema converter:
https://roger13.github.io/SwagDefGen/
I haven't used it personally though, so I'm not sure how good it is.
Since OpenAPI uses a subset of JSON Schema, you could also use one of the JSON Schema generators, however you may need to manually tweak the generated definition to make it OpenAPI-compatible.
这篇关于如何从示例 JSON 生成 Swagger #definition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文