Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Path templating with dashes and slashes #289

Closed
theganyo opened this issue Oct 16, 2015 · 13 comments
Closed

Path templating with dashes and slashes #289

theganyo opened this issue Oct 16, 2015 · 13 comments

Comments

@theganyo
Copy link
Contributor

I had a couple of issues with path templates in swagger-tools today:

  1. You can't have a parameter in your template that has a dash ('-') in it: /path/{Some-ID}. Note that this doesn't get an error on parsing or validation, but it also will not match an incoming request to a path like /path/24. It seems to me that this is probably a bug in either swagger-tools validation or path-matching.

  2. A parameter in a template cannot match slashes within the segment. Ie. /path/{SubPath}/end will not match an incoming request to /path/some/sub/end. This seems more likely to be correct, but...

I couldn't find where either of the above examples were explicitly allowed or disallowed in the spec. Did I just miss the definition in the spec? Or are either of these a bug / limitation in swagger-tools?

Thanks!

@whitlockjc
Copy link
Member

  1. It seems that pillarjs/path-to-regexp does not handle - in the variable name portion of paths. I have opened up a question to see if this should be supported at pillarjs/path-to-regexp/issues/63.
  2. It seems to be working as designed for this one.

@whitlockjc
Copy link
Member

@webron, can you comment on this? Are there any expected limitations on the characters used in the parameter name for path templates?

@webron
Copy link

webron commented Oct 18, 2015

The Swagger spec doesn't provide specific details about it.

However, following RFC 6570 it looks like characters other than alphanumeric or underscore cannot be used unless they are decoded. I'd leave the decision on whether to support it up to you, but I believe it's ok to not provide support for it.

@mohsen1
Copy link
Contributor

mohsen1 commented Oct 19, 2015

The RFC 6570 limitation is not good enough for Swagger. A path parameter that is just a number (/{1}) doesn't make much sense for example. Other example is %. It should not be allowed in path parameter name since it's going to complicate a lot of things.

@webron
Copy link

webron commented Oct 19, 2015

The RFC limitation would probably have to be good enough for Swagger as I suspect that the next version of the spec would refer to it more explicitly and depend on it for the restrictions and behavior regarding path templating.

@mohsen1
Copy link
Contributor

mohsen1 commented Oct 19, 2015

Is there an open issue/proposal for this?

@webron
Copy link

webron commented Oct 19, 2015

Too many, @mohsen1. Too many :)

@mohsen1
Copy link
Contributor

mohsen1 commented Oct 19, 2015

Could you link on of many to this so we can track it?

@webron
Copy link

webron commented Oct 19, 2015

@whitlockjc
Copy link
Member

pillarjs/path-to-regexp/issues/63 punted on this and I think I will as well. We can reopen it if someone feels we need to, and by "need" I mean has a current use case for it, not some "it sure would be nice" scenario.

@cjolif
Copy link

cjolif commented Oct 17, 2016

I do have a use-case :( I was given some guidelines on how to name an API, that guideline include "dash" in path parameters and I can't make it work :(

@cjolif
Copy link

cjolif commented Oct 17, 2016

@whitlockjc if you don't intend to fix it would there's be a relatively easy way to plugin in the desired behavior into swagger-tools from the outside?

@webron

The RFC limitation would probably have to be good enough for Swagger as I suspect that the next version of the spec would refer to it more explicitly and depend on it for the restrictions and behavior regarding path templating.

I still don't see the spec depending this right? Is there a place I could point people to saying that this might not be a good idea to rely on "-" here?

@whitlockjc
Copy link
Member

I'll give it some thought.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants