How do I reference one model from another model using aws API Gateway

人盡茶涼 提交于 2019-12-10 15:55:50

问题


Say I have a Model:

"Pet":{
  "type": "object"
  "properties": {
    "name":{"type":"integer"},
    "age":{"type":"integer"}
  }
}

And another model:

"Human":{
  "type": "object"
  "properties": {
    "name":{"type":"integer"},
    "age":{"type":"integer"},
    "pets":{
      "type":"array"
      "items": {
        <This is where my question is>
      }
    }
  }
}

How can I reference the Pet model in my human model?

With swagger I was able to say:

"$ref": "#/definitions/Pet"

but API Gateway seems to not allow it.


回答1:


If you mean reference model outside swagger, you can do that by specifying the model with an absolute url like below

 {"type":"array","items":{"$ref":"https://apigateway.amazonaws.com/restapis/<rest_api_id>/models/Pet"}}

For swagger, this example from open api specification shows how to reference models within swagger - https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json

"Pets": {
  "type": "array",
  "items": {
    "$ref": "#/definitions/Pet"
  }

Note that api gateway does not support 'default' response, so if you are trying to import the above petstore.json example, you need to remove the "default" fields.



来源:https://stackoverflow.com/questions/37823112/how-do-i-reference-one-model-from-another-model-using-aws-api-gateway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!