deliveryhero / serverless-aws-documentation

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

Model dependency causing failed CF updates #155

Open sahandseifi opened 4 years ago

sahandseifi commented 4 years ago

Imagine Mode2 references Model1 using the $ref keyword, and both models are defined in the models section of the serverless.yml file:

Model2:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Model2",
    "type": "array",
    "items": {
        "$ref": "https://apigateway.amazonaws.com/restapis/API_ID/models/Model1"
    }
}

serverless.yml

custom:
  documentation:
    models: 
      - name: "Model1"
        contentType: "application/json"
        schema: ${file(Model1.json)}
      - name: "Model2"
        contentType: "application/json"
        schema: ${file(Model2.json)}

This will cause a cloudformation update failure when Model2 is being applied earlier than Model1. This is due to the CloudFormation update template not including any dependency between the models. With Model1 not yet existing, the canonical $ref URL will be invalid and AWS will reject Model2 and fail the stack update completely.

Essentially, there is a need to specify how models depend on each other, optionally similar to other resources using the "dependsOn" keyword. Or even better, detect the dependency automatically and inject the "dependsOn" in the CF template correctly.

Can someone please confirm if this is a valid issue? I'd be happy to make a PR myself with some guidance.

milanzivic commented 3 years ago

I'm experiencing the same issue here. Any response from anyone related to the project?