Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The OPTIONS addition lead to a TypeError #4

Open
cedmax opened this issue Nov 9, 2021 · 2 comments · May be fixed by #7
Open

The OPTIONS addition lead to a TypeError #4

cedmax opened this issue Nov 9, 2021 · 2 comments · May be fixed by #7

Comments

@cedmax
Copy link

cedmax commented Nov 9, 2021

Since the version 2.0.3 I receive the following error:

TypeError: Cannot set property 'DependsOn' of undefined

because the library is trying to define DependsOn on a method not defined in my documentation.
Right now I sorted it by using v2.0.1, but in here somewhere there should be a check of the existence of the resource.

@cedmax cedmax changed the title Adding the OPTIONS method lead to a TypeError The OPTIONS addition lead to a TypeError Nov 9, 2021
@mdnorman
Copy link

mdnorman commented Dec 2, 2021

I have found that this is only if cors is false for the resource in question. Once you set cors: true, it works. This is still an issue, but just wanted to indicate where the problem might be.

This is the stack trace for version 2.0.4:

      at updateMethod (/Users/redacted/some-project/node_modules/serverless-v2-aws-documentation/src/documentation.js:228:30)
      at ServerlessV2AWSDocumentation.updateCfTemplateFromHttp (/Users/redacted/some-project/node_modules/serverless-v2-aws-documentation/src/documentation.js:255:9)
      at Array.forEach (<anonymous>)
      at /Users/redacted/some-project/node_modules/serverless-v2-aws-documentation/src/index.js:179:19
      at Array.forEach (<anonymous>)
      at ServerlessV2AWSDocumentation.beforeDeploy (/Users/redacted/some-project/node_modules/serverless-v2-aws-documentation/src/index.js:177:47)
      at PluginManager.runHooks (/Users/redacted/some-project/node_modules/serverless/lib/classes/PluginManager.js:573:41)
      at PluginManager.invoke (/Users/redacted/some-project/node_modules/serverless/lib/classes/PluginManager.js:610:20)
      at async PluginManager.spawn (/Users/redacted/some-project/node_modules/serverless/lib/classes/PluginManager.js:635:5)
      at async before:deploy:deploy (/Users/redacted/some-project/node_modules/serverless/lib/plugins/deploy.js:65:11)
      at async PluginManager.runHooks (/Users/redacted/some-project/node_modules/serverless/lib/classes/PluginManager.js:573:35)
      at async PluginManager.invoke (/Users/redacted/some-project/node_modules/serverless/lib/classes/PluginManager.js:610:9)
      at async PluginManager.run (/Users/redacted/some-project/node_modules/serverless/lib/classes/PluginManager.js:672:7)
      at async Serverless.run (/Users/redacted/some-project/node_modules/serverless/lib/Serverless.js:468:5)
      at async /Users/redacted/some-project/node_modules/serverless/scripts/serverless.js:832:9

@lmammino
Copy link

lmammino commented Dec 31, 2021

Just bumped on this one as well.

I tried setting cors: true and that indeed solves the problem.

I also tried to add an existence check as follows:

// https://github.com/bind-almir/serverless-v2-aws-documentation/blob/master/src/documentation.js#L226
// ...
+       if (typeof resource !== 'undefined') {
          resource.DependsOn = new Set();
          this.addMethodResponses(resource, eventTypes.http.documentation);
          this.addRequestModels(resource, eventTypes.http.documentation);
          if (!this.options['doc-safe-mode']) {
            this.addDocumentationToApiGateway(
              resource,
              eventTypes.http.documentation.requestHeaders,
              'header'
            );
            this.addDocumentationToApiGateway(
              resource,
              eventTypes.http.documentation.queryParams,
              'querystring'
            );
            this.addDocumentationToApiGateway(
                resource,
                eventTypes.http.documentation.pathParams,
                'path'
            );
          }
          resource.DependsOn = Array.from(resource.DependsOn);
          if (resource.DependsOn.length === 0) {
            delete resource.DependsOn;
          }
        }
+     }
// ...

And this one seems to work fine. I haven't checked thoroughly for other side effects though...

@lmammino lmammino linked a pull request Jan 5, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants