假设我有一个模型:
"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 模型?
我可以大摇大摆地说:
"$ref": "#/definitions/Pet"
但API网关似乎不允许。
如果您指的是 swagger 之外的参考模型,您可以通过使用绝对 url 指定模型来实现,如下所示
{"type":"array","items":{"$ref":"https://apigateway.amazonaws.com/restapis/<rest_api_id>/models/Pet"}}
对于 swagger,这个来自开放 API 规范的示例展示了如何在 swagger 中引用模型 -https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json
"Pets": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
请注意,api 网关不支持“默认”响应,因此如果您尝试导入上述 petstore.json 示例,则需要删除“默认”字段。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)