nextapps-be / laravel-swagger-ui

Add Swagger UI to a Laravel application.
MIT License
160 stars 20 forks source link

Remote Reference dont supported #15

Open JonMaia opened 2 years ago

JonMaia commented 2 years ago

Hi, I want to use remote reference as indicated in the official documentation of swagger but I would not be able to, I get an error that it does not recognize the route. I am following the convention provided by the official documentation and nothing.

I would like to know if I am making a mistake or if I need to consider something else, or in short, it is a feature that is not currently contemplated. Thank you

gdebrauwer commented 10 months ago

This is not something we support at the moment. Feel free to create a PR to add this.

kukukk commented 3 weeks ago

Since my api documentation is getting quite big, I have them separated in multiple files and folders. So, I also encountered this problem.

I tried to add this functionality, but, unfortunately, it seems that things are not so simple.

Extending the route definition with ->where('filename', '.+') will instruct Laravel to pass the additional requests to get the ref files to the controller. It is necessary to handle the situations where the apidoc is spread into multiple sub-folders. But, since it is possible to define multiple versions in swagger-ui.php, it makes getting the ref files a bit complicated, because for the subsequent requests the $filename will be e.g. auth.json, register.json. Without the version info. We have to organise the code in sub-folders named based on the defined versions and extract the version from the url (/v1/auth.json), or try to get the version from the $request. From the request it can be done by using the referer header field, which includes urls.primaryName, or use the default version in case urls.primaryName is missing.

I will try to dig deeper to see if I can implement a solution which handles all the situations.

Until then you can use as a workaround the swagger-cli Node.js package, create a bundle using swagger-cli bundle -t json -o ./resources/swagger/openapi-bundle.json ./resources/swagger/openapi.json and use this bundle in swagger-ui.php.