Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger: wildcard path parameters

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 in Swagger?

like image 771
Dmitry Frank Avatar asked Feb 20 '17 01:02

Dmitry Frank


People also ask

How do you pass multiple parameters in Swagger?

If you are trying to send a body with multiple parameters, add an object model in the definitions section and refer it in your body parameter, see below (works with editor.swagger.io):

Is Swagger deprecated?

The Swagger API interface in the AppDynamics Platform is deprecated starting version 4.5. 15.


1 Answers

This is not supported as of OpenAPI 3.1, and I have to resort to a workaround.

If I have a path /tags{tag_path} and I enter something like this as tag_path: /foo/bar, then the actual query request URL will be: /tags%2Ffoo%2Fbar. So, I just added support for that on my backend: the endpoint handler for /tags* urldecodes the path (which is %2Ffoo%2Fbar), and it becomes /foo/bar again.

Yes, a hack, but it works, and it's better than nothing. In my case, tag names can't contain the / character, so there's no conflict. Your mileage may vary, of course.

like image 154
Dmitry Frank Avatar answered Oct 09 '22 15:10

Dmitry Frank