delvedor / find-my-way

A crazy fast HTTP router
MIT License
1.5k stars 140 forks source link

Bug `-` parameter separator logic #147

Open mhamann opened 4 years ago

mhamann commented 4 years ago

I've got a situation where I'm taking an OpenAPI v3 doc, parsing it, and registering its paths in find-my-way via fastify.

However, I'm facing a problem where the OpenAPI doc has path parameters in the format {some-param}. I convert those to :some-param for find-my-way, but they're then interpreted as a parameter some + a path segment param. This is caused by this parsing logic: https://github.com/delvedor/find-my-way/blob/master/index.js#L131

I'll submit a PR, but I think that logic should ensure that the - character is followed by a : to indicate the second parameter. Otherwise, it should be assumed that it's just a continuation of the original parameter up to the next /.

mcollina commented 4 years ago

In https://github.com/delvedor/find-my-way/pull/27, this feature was actually coded with - as a separator, so it's working as expected.

We can potentially change this in a semver-major (one is due soon), but it 's not clear how if we want to retain similar functionality (having a part of a segment being parametric).

mhamann commented 4 years ago

Thanks for the background @mcollina. So, what's the expected behavior of /foo/:param-x vs. /foo/:param-x-:param-y?

mhamann commented 4 years ago

I looked at https://github.com/delvedor/find-my-way/blob/master/test/issue-17.test.js and realized that my first example would make -x the suffix of the parameter. So now I better understand the comment you made.

What do you think about wrapping a param to indicate that it should be taken literally? e.g. /foo/:{param-x}?

mcollina commented 4 years ago

That would work.

Ekott2006 commented 1 year ago

Hello, What's the next step??

mcollina commented 1 year ago

Somebody that needs this feature should work on it ;)