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

Can't use Models defined as CloudFormation Output of different Stack #74

Open pj035 opened 6 years ago

pj035 commented 6 years ago

I have the following setup:

Stack1:

custom:
  documentation:
    models:
      - name: BadRequest400ResponseJSON
        contentType: 'application/json'
        schema: ....

resources:
  Outputs:
     BadRequest400ResponseModel:
        Value: BadRequest400ResponseJSON
     Export:
        Name: BadRequest400ResponseModel-${self:provider.stage}

Stack2:

someFunction:
  handler: myHandler
  events:
    documentation:
      methodResponses:
        - statusCode: '400'
          responseModels:
            "application/json": 
              Fn::ImportValue: 'BadRequest400ResponseModel-${self:provider.stage}'

The deployment of stack 2 fails because of Template format error: Unresolved resource dependencies [[object Object], [object Object]Model] in the Resources block of the template. The CloudFormation Template contains for some resources the object

DependsOn: [
  "MyAweSomeModel1",
  "MyAwesomeModel2",
  "[object Object]Model", // <-- this causes the problem
]

The problem is line 59, which expects the resource to be a string. If it's an object (like in my case with { "Fn::ImportValue": "<my-export-name>" }, then it fails.

A simple workaround for me is to ignore objects in line 59 (i.e. don't add them as dependency).

tchock commented 6 years ago

The dependency is definitely needed, otherwise cloudfront won't build stuff in the right order. There needs to be special handling for your case. If the model is an object, don't add them to the dependencies.

Also a good first issue to work on :)

pj035 commented 6 years ago

Of course the dependency is required. Maybe I did not express myself correctly. In my case the resource already exists, because it has been created by a different stack. Therefore that certain object should not be added to the dependencies.

I don't know if every object should be omitted or if different kind of objects (i.e. a different key than Fn::ImportValue) have to be handled differently?!

malikadit commented 6 years ago

Any update on this? With the #77 closed with the latest code we are now facing this issue. We have an errorModel defined in stack1 which we would like to import in stack 2 and we are not able to do it.

AndrewFarley commented 5 years ago

+1 any update on this? Can not use this plugin with multi-stacks currently unless someone has a clever workaround.

daoudsh commented 5 years ago

any update on this issue, or workaround !

tchock commented 5 years ago

Currently not. We also don't have that much time to investigate this. So if someone finds something, it would be really cool that they could fix it and make a PR to this project :)

gcampionpae commented 4 years ago

+1 from me as well. I might be able to try and see if I can work on a fix soon.

joaoluizhilario commented 3 years ago

+1 any update on this? some workaround or solution ?

In my case, when it shares same RestAPI into multiple stacks, the documentation of the last version is overriding another stacks functions documentation on swagger file.

gcampionpae commented 3 years ago

Sorry the project that I was working on that would have allowed me to spend some time on this has been on hold. ATM, I just renamed the various components that were similar so they all had different names and didn't overwrite each other :/