OpenAPIContract.findOperation gives unpredicted results
szymonsasin-nordic opened this issue · 5 comments
Version
4.5.0
Context
Using vertx-openapi module
implementation("io.vertx:vertx-openapi:4.5.0")
Do you have a reproducer?
No
Steps to reproduce
Lets assume API with following paths:
(I know that below API design has an issue, but unfortunately sometimes that is not possible to change.)
GET /users/{id}/addresses/{adr-id}
GET /users/{id}/addresses/foo
...
When using it with:
val contract = OpenApiAuthorizer(jsonContract)
val operation = contract.findOperation("/users/000001/addresses/foo", HttpMethod.GET)Result is not predictable, sometimes it will return wrong Operation.
Extra
Not relevant.
I think the problem might be somewhere here:
https://github.com/eclipse-vertx/vertx-openapi/blob/main/src/main/java/io/vertx/openapi/contract/impl/PathFinder.java#L58
segmentsWithTemplating is using HashMap, so paths are not in any particular order.
I added a branch [1], with a reproducer.
[1] https://github.com/eclipse-vertx/vertx-openapi/tree/findOperations
Thanks for finding this. Do you want to provide a fix?
Hey @pk-work and @szymonsasin-nordic I didn't see any movement on this issue for the last month. I am new to contributing and these seemed "new contributor" friendly. I created this PR #50 to address this and have the path's resolved more predictably - based on which path matches the input path more exactly (from left to right).
You're reproducer TC is passing now @pk-work I added a few other TCs to make sure everything is covered. Let me know if there is anything that needs to change! This is my first PR for vertx so any comments are welcome 😃