如何使用AWS API Gateway从另一个模型引用一个模型 [英] How do I reference one model from another model using aws API Gateway

查看:82
本文介绍了如何使用AWS API Gateway从另一个模型引用一个模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个模型:

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

另一个模型:

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

如何在人体模型中引用Pet模型?

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

我大摇大摆地说道:

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

但是API网关似乎不允许它.

but API Gateway seems to not allow it.

推荐答案

如果您是在摇摇晃晃中指代参考模型,则可以通过使用如下所示的绝对URL指定模型来做到这一点

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"}}

对于swagger,此开放api规范中的示例演示了如何在swagger中引用模型-

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"
  }

请注意,api网关不支持默认"响应,因此,如果您尝试导入上述petstore.json示例,则需要删除默认"字段.

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.

这篇关于如何使用AWS API Gateway从另一个模型引用一个模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆