-
Notifications
You must be signed in to change notification settings - Fork 17
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
Generate correct path key for typed path parameters #12
Conversation
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.
Thanks for the PR. Here is one proposal
@@ -271,7 +271,7 @@ function buildBodyParam(bodyParamsStr) { | |||
} | |||
|
|||
function buildPathKey(pathStr, group) { | |||
return `${pathStr.replace(/:(.*?)(\/|$)/g, '{$1}$2')}${group}`; | |||
return `${pathStr.replace(/:([^:/]+)(?::[^/]+)?(\/|$)/g, '{$1}$2')}${group}`; |
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.
How about this lazy RegExp: /:(.+?)(?::.+?)?(\/|$)/g
?
.+?
is a bit more general than [^:/]
and [^/]
.
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 should work as well. (Although the amount of laziness here worries me.)
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.
Why?
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.
Maybe it's just me, but when examining an RE with more than one non-greedy qualifier, I need to consider more variants to ensure it will not go the wrong way. With [^:/]
and [^/]
, it's more straightforward and easier to understand.
The type and the preceding semicolon are now stripped from the path key.
f8831a8
to
6c0f403
Compare
Merged, thanks! |
Path parameters can be typed (
/some/:param:integer
); they are parsed and the parameter type is taken into account, but the resulting path key in the output contains the entire parameter specification (name:type
) which is obviously incorrect.This PR modifies the code to strip the type and the preceding semicolon from the path key.