question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for path parameters which can contain slashes

See original GitHub issue

I see there are a few issues which ask for the opposite, e.g. this one https://github.com/swagger-api/swagger-js/pull/280 , but what I’m asking for is to add some option to the parameter, which would allow it to contain non-encoded slashes.

My use case: I have an API which allows any arbitrary path to be passed in, for example all of these:

  • /api/tags
  • /api/tags/foo
  • /api/tags/foo/bar/baz

Are valid paths. I tried to describe it as follows:

  /tags{tag_path}:
    get:
      parameters:
        - name: tag_path
          in: path
          required: true
          type: string
          default: "/"

However, https://generator.swagger.io encodes slashes in the path, so it doesn’t work. So is there a way to describe my API? It feels to me like a perfectly valid use case, so I’m surprised it’s not supported.

If it’s indeed not supported, then one possible solution is to add some option for the path parameter, which would allow it to contain non-encoded slashes.

What do you think?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:57
  • Comments:58 (21 by maintainers)

github_iconTop GitHub Comments

8reactions
momegahedcommented, Nov 1, 2021

It would still be nice to have this feature

8reactions
jypmacommented, Mar 10, 2021

Could someone from the OpenAPI core team leave a final comment on the likelihood of this being added to a future spec? The most common cases I see summarized here are:

  1. Allow a * to match a path and any subpath after it : /myapi/tags/animals/mammals/tiger
  2. Allow a path parameter to be repeated : /myapi/tags/animals/mammals/tiger/tag_properties

The argument against this feature was to be able to automatically match requests against documentation, which of course should be retained. But both (1) and (2) do not need to cause problems, if some simple rules are set up, e.g.

  • A * at the end of a path is only tried when less-specific paths don’t match
  • Only one repeated path parameter is allowed in a path
  • Specific paths are always matched before a repeated path parameters when matching a path

The rules could even be more strict than that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing a parameter with slashes to the REST call
I need to pass a parameter string that contains slashes to a REST call. I tried URL encoding, or making URL map to...
Read more >
Swagger escaping forward slash in path parameters [duplicate]
Some of my APIs use a file path as the path parameter (Ex. .../hello/test.txt) which will include a forward slash. However in Swagger ......
Read more >
Using a Slash Character in Spring URLs - Baeldung
Learn several ways to deal with URLs containing slash characters in Spring.
Read more >
URL encoding slash character ('/') and Apache web servers
slashes but it is a PITA. I could add a hacky option to digilib to replace the slash in the path/filename with a...
Read more >
URI path, including path parameters - Aruba Networks
In URIs that have a query component, the path is everything before the question mark (?). The path has a hierarchy. In a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found