laravel-openapi-validator
laravel-openapi-validator copied to clipboard
Routes with Server url prefix
I use the Server url parameter to add a relative path prefix to all of the URL's in my Open API implementation. This means that when I create the URL using laravel, it includes the prefix, and then when it matches up with this validator which is looking at the paths without the Server url prefix, every test fails request validation.
Thought I would ask if you think there's an elegant solution to this? I wouldn't mind doing a PR for this if you have a strategy in mind for an implementation. Or if you're open to a PR at all, then I could dig in and see if I can come up with a solution?
Hi @kdevan, we would have to think a bit about a solution for this, but we are definitely open to a Pull Request for this if you can come up with a solution.
Thanks!
An item in the config seems like a good solution to me. And it skips having to read the prefix from the openapi file, since for tests what matters is the internal API Route (keeping in mind that the server being deployed or tested could be behind a reverse proxy that alters the URI a little).
'api_prefix' => env('OPENAPI_API_PREFIX', '')
Currently in my HTTP tests I have to make calls to /api/my/route
.
@h-sigma I agree, this overlaps with environment specific set ups that sometimes have slightly different routes as well. A configuration option would solve all of this.
@luisdalmolin Are you open to a PR that uses a configuration value to prefix all URL's that are being tested?
@kdevan Yes, 100%. This sounds like a good solution.