Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 992
Amir Hajimirsadeghi Avatar asked Jun 14 '16 22:06

Amir Hajimirsadeghi


People also ask

Can API gateway call another API?

For testing, you can use the API Gateway console to call an API by using the API Gateway's TestInvoke feature, which bypasses the Invoke URL and allows API testing before the API is deployed. Alternatively, you can use the Postman application to test a successfully deployed API, without writing a script or a client.

What are the three common ways you can interact with the API of AWS?

There are several ways to call this API. They include using the AWS Command Line Interface (AWS CLI), or by using an AWS SDK. In addition, you can enable API creation with AWS CloudFormation templates or (in the case of REST APIs and HTTP APIs) Working with API Gateway extensions to OpenAPI.

How do I use a mapping template in API gateway?

You must define the model in order to have API Gateway to generate a SDK or to enable basic request validation for your API. You don't have to define any model to create a mapping template. However, a model can help you create a template because API Gateway will generate a template blueprint based on a provided model.


1 Answers

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.

like image 152
Abhigna Nagaraja Avatar answered Oct 20 '22 11:10

Abhigna Nagaraja