joostfarla / serverless-cors-plugin

Serverless CORS Plugin - Managing Cross-origin resource sharing (CORS) policies
ISC License
70 stars 15 forks source link

Path/Query parameters not added to Options methods causing invalid API template export #13

Closed justonian closed 8 years ago

justonian commented 8 years ago

When you setup CORS on a function or module that has a path or query string parameter, the Options method is added successfully with the header responses needed for CORS, but the path and query parameters are not added to the method request settings so whenever the API is exported as a Swagger (or other template) via the Stage settings, the template has syntax errors and does not resolve all references.

If the path and query parameters were passed down to the created options method request, even though they're not used, the Swagger templates and API exports would generate fully and not show syntax errors and warnings.

joostfarla commented 8 years ago

@justonian Thanks for reporting!

I think adding the path request parameter is a good idea. However, I don't understand why we should to the same for query strings. The thing here is that the query parameters can differ for each resource method, sharing the same path and thus share the same CORS preflight endpoint.

Could you elaborate on this?

justonian commented 8 years ago

Hello again-

On second thought, I agree that query parameters should not be included in the Options method as they vary by operation. If you could update the CORS plugin to automatically add path parameters to the request parameters of the Options methods it creates that should resolve the issue.

joostfarla commented 8 years ago

@justonian are you still struggling with this? Seen from the AWS console, it automatically adds it to the Request Paths. What tool are you using for exporting it to a Swagger definition?

justonian commented 8 years ago

I just went to check by using the AWS Console to manually export my API Gateway definition as Swagger JSON format (without custom API gateway extensions) and found that my options operations were present on all my resources, but only with response values and no request path/parameter definitions. That said, I am using an earlier version of your plug-in so not sure if you've addressed this in recent releases. Thanks!

joostfarla commented 8 years ago

Thanx! I was able to reproduce the issue and it's supported now in https://github.com/joostfarla/serverless-cors-plugin/commit/4807844d3193053428c29a2e3c9d1c327b6a4620. It will be available in the next release, probably v0.4.2!