rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Multiple Variables Path Issue Error Message #143

Closed tongueroo closed 5 years ago

tongueroo commented 5 years ago

Checklist

My Environment

Software Version
Operating System Amazon Linux
Jets 1.5.3
Ruby 2.5.3

Expected Behaviour

Deploying Jets application with routes that have different path variables under the same parent route should work.

Current Behavior

Deploying with a config/routes.rb that has:

get 'posts/:id', to: 'posts#show'
post 'post/:post_id/reveal', to: 'posts#show'

Produces this error:

A sibling ({post_id}) of this resource already has a variable path part -- only one is allowed

CloudFormation error screenshot:

cloudformation-error-multiple-variables-path

Step-by-step reproduction instructions

git clone https://github.com/tongueroo/jets-issue-path-variables demo
cd demo
# comment out the multiple route so we can get a full succcessful deploy first
# https://github.com/tongueroo/jets-issue-path-variables/blob/b7be42eb0ad2bd933461f48ab328330dd4674c9e/config/routes.rb#L5
jets deploy
# add back in the route that cause the issue
jets deploy 

Note it is helpful to comment out route that causes the issue and deploy successfully first and then deploy again.

Here's also manual reproduction using the API Gateway Console:

multiple-variables-path-part-issue

Code Sample

https://github.com/tongueroo/jets-issue-path-variables

Solution Suggestion

  1. Add docs noting this API Gateway constraint and how to currently avoid it. That's a big win and will help save folks time right now.
  2. Upon route building, check for “multiple variable part path definitions” that collide and error with an informative message to the user. So the user finds out about this early as we can help with the process, locally. Even before they try to deploy. When they deploy check the same logic and also provide same information message in case they deploy without checking locally. Something like

API Gateway only allows one unique variable path. [screenshot link]. You must use the same variable name within the same parent route path. Example: /posts/:id and /posts/:post_id/reveal should both be /posts/:id and /posts/:id/reveal.

Something like that, the message can be improved and can tell the users how to fix it.

References

Original discussion: https://community.rubyonjets.com/t/jets-deploy-create-failed-aws-stack-apigateway-embedded/52

tongueroo commented 5 years ago

Done in PR #154

Released in v1.5.9 CHANGELOG