cartman
cartman

Reputation: 190

Create a generic path along with a specific one in openapi v3

I'm using express-openapi npm module for node.js server. I need for that purpose to create a generic url using openapi v3 like this one /ressources/{action} that would include all types of actions expect a few that I described specificly as /ressources/action1 and /ressources/action2 Here how I described the generic parameter in url's path:

    action:
      name: action
      in: path
      required: true
      schema:
        type: string
        not:
          enum: ['action1', 'action2']

The specific urls are described seperatly without path parameter.

The issue is that whenever I launch the server and call for example /ressources/action1 it calls the generic url. I think there is an issue with the generic action path parameter enumeration. Can someone help figure out how to correctly match my request with the appropriate url in this situation ?

I also tried to enumerate all generic possible actions like this:

    action:
      name: action
      in: path
      required: true
      schema:
        type: string
        enum: ['action3', 'action4', 'action5', 'action6']

but action1 and action2 always matches the generic url

Upvotes: 0

Views: 602

Answers (1)

Helen
Helen

Reputation: 97609

Both definitions are correct, and according to the OpenAPI Specification:

When matching URLs, concrete (non-templated) paths would be matched before their templated counterparts.

...

Path Templating Matching

Assuming the following paths, the concrete definition, /pets/mine, will be matched first if used:

/pets/{petId}
/pets/mine

The fact that the server always picks up the generic URL is a bug (or unimplemented feature?). You should open an issue with whatever server framework you are using.

Upvotes: 2

Related Questions