Replies: 1 comment 2 replies
-
@beblife I'm not sure I have a strong enough opinion about |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! 👋
Recently stumbled on an idea when working with a very specific setup that might be worth supporting.
This seemed like a good place to post my thoughts instead of a PR.
Context
When writing a test for the
/users/me
endpoint for the 401 status code with the Spectator middleware active the response validator will always resolve the path item for/users/{user}
. This is because the special case for/users/me
is not defined in the routes file and the package response validator uses$request->route()->uri()
to find the path item.Current possible solution
This can be solved by updating the
spec.json
to drop the path forusers/me
and add the 401 status code along with the security schema to theusers/{user}
path. This however might cause confusion for clients interacting with the API that theusers/{user}
endpoint always requires authentication, which is not always the case.The idea
Resolve the path item from the specification file using the
$request->path()
first and fall back to the current$request->route()->uri()
implementation when nothing is found. This approach would make the test in the context section pass, as it resolves the correct path item, without any changes to the routes setup.I created a branch on my fork with a test that replicates this setup in a simplified way and updated the middleware to support this idea to demonstrate the idea.
Happy to hear your thoughts on this!
Beta Was this translation helpful? Give feedback.
All reactions