deliveryhero / serverless-aws-documentation

Serverless 1.0 plugin to add documentation and models to the serverless generated API Gateway
MIT License
310 stars 148 forks source link

Support in-line response model #140

Open lucas-rudd opened 4 years ago

lucas-rudd commented 4 years ago

Perhaps this is a limitation of AWS API Gateway.

But, I've noticed when doing the following, that I get a CloudFormation template validation error

methodResponses:
  - statusCode: '200'
     responseBody:
      description: Ok
     responseModels:
      application/json:
        additionalProperties: true
        type: object

I get the following error

Template format error: Unresolved resource dependencies [[object Object]Model]

This is due to this line in models.js

resource.DependsOn.add(`${models[contentType]}Model`);

I'm curious as to if the inline response model is an object that we could simply skip adding anything to the resource.DependsOn set. As there is no external model to depend on, it would seem as if we could simply do something like

addModelDependencies: function addModelDependencies(models, resource) {
    Object.keys(models).forEach(contentType => {
     if(typeof models[contentType] !== 'object') {
       resource.DependsOn.add(`${models[contentType]}Model`);
     }
    });
  },
lucas-rudd commented 4 years ago

So, I've tested this myself, and it appears as though this is a limitation of API Gateway

When running sls package, my method response looked like this

"MethodResponses": [
          {
            "StatusCode": "200",
            "ResponseModels": {
              "application/json": {
                "additionalProperties": true,
                "type": "object"
              }
            }
          }
        ]
      },
      "DependsOn": []
    },

And I got the following error in the CloudFormation stack

Value of property ResponseModels must be an object with String (or simple type) properties