0

I'm using an openapi validator (express-openapi-validator) in my Node.js project and can't figure out how to control the order of the paths matched.

If I have 2 paths such as,

/foo/{type}
   parameters:
     - name: type
       schema:
          type: string
          enum: ['bar', 'bam']

and

/foo/bar

For a request to /foo/bar, the second path is always matched.

How do I control the precedence of this match?

Mayur
  • 730
  • 8
  • 18
  • Related: [Create a generic path along with a specific one in OpenAPI v3](https://stackoverflow.com/q/55562428/113116), [Are those OpenAPI 3 paths ambiguous?](https://stackoverflow.com/q/67382759/113116) – Helen Aug 04 '21 at 10:14

1 Answers1

1

For a request to /foo/bar, the second path is always matched.

This is the correct and expected behavior. OpenAPI Specification states that specific paths must be matched before similar templated paths - see Path Templating Matching. This is not supposed to be configurable, otherwise the behavior would contradict the specification.

To have requests to /foo/bar handled by /foo/{type}, you'll need to remove the /foo/bar path from the API definition.

Helen
  • 87,344
  • 17
  • 243
  • 314