问题
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