我正在寻找一种方法将swagger中定义的模式转换为JSON-Schema .

例如,在我的招摇中,我有:

"definitions" : {
    "response" : {
        "properties" : {
            "responseContent" : {
                "$ref" : "#/definitions/objectResponse"
            }
        }
    },

    "objectResponse" : {
        "description" : "response",
        "properties" : {
            "idResponse" : {
                "type"        : "string",
                "description" : "Response",
                "minLength"   : 0,
                "maxLength"   : 255
            }
        }
    }
}

我想要 :

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {},
  "id": "http://example.com/example.json",
  "properties": {
    "responseContent": {
      "id": "/properties/responseContent",
      "properties": {
        "idResponse": {
          "id": "/properties/responseContent/properties/idResponse",
          "type": "string"
        }
      },
      "type": "object"
    }
  },
  "type": "object"
}

目前,我找到了一个解决方案:

  • 根据swagger生成响应(例如使用apimatic.io)

  • 使用jsonschema.net转换响应

但是通过这个过程,我失去了限制,我依赖外部工具 .

谢谢你的帮助 .

PS:我对API世界有点新意,不要犹豫深刻解释我很好奇

码头