Convert JSON to JSON Schema draft 4 compatible with Swagger 2.0

前端 未结 3 1447
南旧
南旧 2021-01-04 03:03

I\'ve been given some JSON files generated by a REST API with plenty of properties.

I\'ve created a Swagger 2.0 definition for this API and need to give it the corre

3条回答
  •  北海茫月
    2021-01-04 03:56

    I also needed a converter tool and came across this. So far it seems to work pretty well. It does both JSON and YAML formats.

    https://swagger-toolbox.firebaseapp.com/

    Given this JSON (their sample):

    {
      "id": 1,
      "name": "A green door",
      "price": 12,
      "testBool": false,
      "tags": [
        "home",
        "green"
      ]
    }
    

    it generated this:

    {
        "required": [
            "id",
            "name",
            "price",
            "testBool",
            "tags"
        ],
        "properties": {
            "id": {
                "type": "number"
            },
            "name": {
                "type": "string"
            },
            "price": {
                "type": "number"
            },
            "testBool": {
                "type": "boolean"
            },
            "tags": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            }
        }
    }
    

提交回复
热议问题