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

Generate correct path key for typed path parameters #12

Merged
merged 1 commit into from
Jan 17, 2019

Conversation

pvgoran
Copy link
Contributor

@pvgoran pvgoran commented Dec 24, 2018

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.

Copy link
Owner

@Ajaxy Ajaxy left a 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}`;
Copy link
Owner

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 [^/].

Copy link
Contributor Author

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.)

Copy link
Owner

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

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.
@Ajaxy Ajaxy merged commit f7b618e into Ajaxy:master Jan 17, 2019
@Ajaxy
Copy link
Owner

Ajaxy commented Jan 17, 2019

Merged, thanks!

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