-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Encode slashes in path parameters #1015
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
Conversation
Slashes in path parameters should be encoded in order to produce valid URLs. Fixes: swagger-api#1013
@@ -1464,18 +1464,7 @@ Operation.prototype.encodeQueryParam = function(arg) { | |||
* TODO revisit, might not want to leave '/' | |||
**/ | |||
Operation.prototype.encodePathParam = function(pathParam) { | |||
var encParts, part, parts, i, len; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done with a much simpler approach:
return pathParam.toString().split('/').map(encodeURIComponent).join('/')
Please update the code and and add test if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is to encode slashes as well.
Two thoughts. First, this is in the underlying javascript library, swagger-js. The PR would really belong there. Second, we have been back and forth on how this should work. Some people want to support slashes in the param and some want them encoded. The current code intentionally supports slashes so "splat" params are valid. I'm not sure what the right answer is other than to make it configurable because there's no one way to do it. |
@fehguy, IMHO the current encoding code is just a hacky and inconsistent way to work around the lack of level 2 URI templates. The encoding path pretends that parameters were actually specified as I hope that proper RFC 6570 support will make its way into the 2.1 spec, so that |
Created another PR against swagger-js at swagger-api/swagger-js#280. |
See also: OAI/OpenAPI-Specification#93 |
Closing in favor of swagger-api/swagger-js#280 |
Slashes in path parameters should be encoded in order to produce valid URLs.
Fixes: #1013