Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inproper paths matching order #798

Open
qiuchengxuan opened this issue Jun 14, 2023 · 1 comment
Open

Inproper paths matching order #798

qiuchengxuan opened this issue Jun 14, 2023 · 1 comment

Comments

@qiuchengxuan
Copy link

qiuchengxuan commented Jun 14, 2023

In openapi3/paths.go, InMatchingOrder consider number of variables only, assuming with the following two apis:

  • /v1/api/{name:.*}
  • /v1/api/whatever/{id}

they have the same number of variables, and the first one is lexicographical less than the second, which cause the first one matched first, while we prefer the second api matched first,

@fenollp
Copy link
Collaborator

fenollp commented Apr 6, 2024

From this func's docs: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#paths-object

In case of ambiguous matching, it's up to the tooling to decide which one to use.

If you'd like to share another algorithm, feel free to open a PR along with a test showing this behavior.
We can switch today's logic then, when both options are available to pick from for users of the lib.

Note: looks like it's only a matter of fiddling with the sort.Sort impl to also take len(ps[i]) into account, in order to impl the sorting you desire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants