Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a Swagger #definition from sample JSON

Tags:

json

swagger

Take the following #definition from the pet store example. Given a #definition section a JSON structure can be generated

e.g. Coversion of definition to JSON

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"       }     ]   } } 
like image 412
user1605665 Avatar asked Mar 14 '18 11:03

user1605665


People also ask

Is Swagger automatically generated?

You can write a Swagger spec for your API manually, or have it generated automatically from annotations in your source code.

How do I create a Swagger service?

You can drag and drop a path from the Swagger file on to the left boundary of the Process Editor to create a REST service or drag it to the center and select Create Service from the resulting menu.


1 Answers

You can use this JSON-to-OpenAPI schema converter:
https://roger13.github.io/SwagDefGen/

(GitHub project)

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.

like image 138
Helen Avatar answered Sep 21 '22 09:09

Helen