laravel-openapi-validator icon indicating copy to clipboard operation
laravel-openapi-validator copied to clipboard

Routes with Server url prefix

Open kdevan opened this issue 1 year ago • 4 comments

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?

kdevan avatar Oct 13 '23 21:10 kdevan

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!

luisdalmolin avatar Oct 22 '23 12:10 luisdalmolin

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 avatar Nov 09 '23 08:11 h-sigma

@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 avatar Nov 11 '23 20:11 kdevan

@kdevan Yes, 100%. This sounds like a good solution.

luisdalmolin avatar Nov 12 '23 10:11 luisdalmolin