为摇摇欲坠指定了无效的模型架构

时间:2018-06-22 09:52:35

标签: json swagger aws-api-gateway

我试图在AWS上部署API,但不允许在JSON文件中添加模型并显示错误:

它可以在不使用模型的情况下工作,因此也许它不是采用这种方式,所以请建议我如何在AWS的API JSON中使用模型!

错误是:

Your API was not imported due to errors in the Swagger file.
Unable to create model for 'LandingPageDTO': Invalid model specified: Validation Result: warnings : [], errors : [Invalid model schema specified]
Unable to put method 'POST' on resource at path '/userservice/la/program-summary': Invalid model name specified: null
Additionally, these warnings were found:
Reference to model 'LandingPageDTO' not found. Ignoring.

我的招摇的json是:

{
  "swagger" : "2.0",
  "info" : {
    "description" : "demo",
    "version" : "v0.1",
    "title" : "demo"
  },
  "host": "localhost:7000",
  "basePath": "/",
  "paths" : {
    "/userservice/la/program-summary" : {
      "post" : {
        "tags" : [ "user-controller" ],
        "summary" : "getLALandingPage",
        "operationId" : "getLALandingPageUsingPOST",
        "consumes" : [ "application/json" ],
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "in" : "body",
          "name" : "landingPage",
          "description" : "landingPage",
          "required" : true,
          "schema" : {
            "$ref" : "#/definitions/LandingPageDTO"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "OK",
            "schema" : {
              "type" : "object",
              "properties" : { }
            }
          },
          "201" : {
            "description" : "Created"
          },
          "401" : {
            "description" : "Unauthorized"
          },
          "403" : {
            "description" : "Forbidden"
          },
          "404" : {
            "description" : "Not Found"
          }
        }
      }
    }
  },
  "definitions" : {
  "LandingPageDTO" : {
      "type" : "object",
      "properties" : {
        "filter" : {
          "type" : "object",
          "additionalProperties" : {
            "type" : "string"
          }
        },
        "page" : {
          "type" : "integer",
          "format" : "int32"
        },
        "searchTerm" : {
          "type" : "string"
        },
        "size" : {
          "type" : "integer",
          "format" : "int32"
        },
        "sortDirection" : {
          "type" : "string",
          "enum" : [ "ASC", "DESC" ]
        },
        "sortProperty" : {
          "type" : "string"
        },
        "uid" : {
          "type" : "string"
        }
      },
      "example" : {
        "filter" : {
          "key" : "filter"
        },
        "uid" : "uid",
        "sortDirection" : "ASC",
        "searchTerm" : "searchTerm",
        "size" : 6,
        "sortProperty" : "sortProperty",
        "page" : 0
      }
    }
  }
}

任何人都可以建议如何在AWS的swagger json API中导入模型。

1 个答案:

答案 0 :(得分:1)

根据AWS API Gateway - Known Issues

  
      
  • API网关支持大多数Swagger规范,但以下情况除外:      
        
    • 模型不支持additionalProperties字段。
    •   
    • 不支持example标签。
    •   
    • 不支持int32int64类型的数字。
    •   
    • ...
    •   
  •   

因此,您的模型似乎与API Gateway不完全兼容。尝试从模型中删除additionalPropertiesformat: int32example,看是否有帮助。