I am developing an API using filter routes to check the authorization with token bearier. The API itself work well if I test it in postman. But when i run the plumber documentation by Swagger, this eror always appear. I dont want to use the authorization on swagger routes.
I have put the route condition based on solution answered by @meztez (post page), but swagger doesn't seem to be able to continue to the next endpoint with plumber::forward() function.
Is there something wrong with my script? Please welcome your input and suggestions.
Thankyou for your reply. I have try your script, now the swagger documentation can show up.
But it seems that with the addition return() function, the process does not leave the routes filter.
In the following output results, the API is still checking the token. Is there any other way to make the API read the main endpoint?
Update:
From my observations, unfortunately this plumber filter cannot be bypassed. Couse even the swagger run successfully, it will check again the filter routes when the endpoint is hit.
So i used to add the swagger docs input field for Authorization using this function.
It works well for me.
Thank you very much for your advice. You're right it can trigger another execution loop. Actually, it solve my first problem :). The swagger can escape the filter routes if the PATH_INFO one of this list c("/__docs__/", "/__swagger__/", "/openapi.json").
But at the end, swagger change the PATH_INFO back to original. So it will read again the filter routes.
This is the log on my console, when i hit via swagger. I've added print(req$PATH_INFO) on the first line of filter routes. It seems that this check token cannot be passed in Swagger, right?
> pr('backup/api-test_v2.R') %>%
+ #pr_set_api_spec(add_auth) %>%
+ pr_run(port=8002,host = '127.0.0.1',docs=T)
Running plumber API at http://127.0.0.1:8002
Running swagger Docs at http://127.0.0.1:8002/__docs__/
[1] "My path: /__docs__/"
[1] "Run for document!"
[1] "My path: /openapi.json"
[1] "Run for document!"
[1] "My path: /hit_model"
[1] "Token not found in request header"