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

Correctly normalize rails paths with optional bound params #167

Conversation

mercedesb
Copy link
Contributor

Rails supports optional bound parameters.

When using optional params, the generated paths by this gem look something like: /optional_params/(/{id)} instead of the expected /optional_params/(/{id})

If you use tools like widdershins to generate docs from your OpenAPI specification, this can break the parsing.

This PR updates the regex to not include the closing parentheses in the capture group during path normalization.

@mercedesb mercedesb force-pushed the fix-regex-for-normalizing-rails-path-with-optional-params branch 3 times, most recently from 44b1553 to 38b3f01 Compare January 10, 2024 19:19
@mercedesb mercedesb force-pushed the fix-regex-for-normalizing-rails-path-with-optional-params branch from 38b3f01 to cb8964b Compare January 10, 2024 19:23
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8b60147) 96.80% compared to head (cb8964b) 96.80%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #167   +/-   ##
=======================================
  Coverage   96.80%   96.80%           
=======================================
  Files          15       15           
  Lines         470      470           
  Branches      102      102           
=======================================
  Hits          455      455           
  Misses         15       15           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -341,6 +341,48 @@
}
}
},
"/optional_params(/{id})": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mercedesb Could you check OpenAPI documentation to verify "/optional_params(/{id})" is valid format of optional path parameter?
I've looked https://swagger.io/docs/specification/paths-and-operations/
but could not find

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh good call, it does not. Here's an open issue on the OpenAPI Specification repo where people are asking for it. I'll close this. Thanks for asking this question! I didn't think to check this.

@mercedesb
Copy link
Contributor Author

@mercedesb mercedesb closed this Jan 11, 2024
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 this pull request may close these issues.

2 participants