Open API 中路径的优先级 3

Priority of paths in Open API 3

我在我的 Node.js 项目中使用 openapi 验证器 (express-openapi-validator),但不知道如何控制匹配路径的顺序。

如果我有 2 条路径,例如,

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

/foo/bar

对于 /foo/bar 的请求,第二个路径始终匹配。

我如何控制这个匹配的优先级?

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

这是正确的预期行为。 OpenAPI 规范声明特定路径必须在相似的模板化路径之前匹配 - 参见 Path Templating Matching。这不应该是可配置的,否则行为将与规范相矛盾。

要让 /foo/bar 的请求由 /foo/{type} 处理,您需要从 API 定义中删除 /foo/bar 路径。