plumber filter auth causes swagger to fail

I have an plumber API which I've been asked to secure by requiring that a specific API_KEY be provided as a header. I have added a filter which returns an error if the API_KEY is missing or is incorrect. However, if I start up the API with swagger enabled a request is passed to this filter, and since no API_KEY was provided as a header it will throw an error and kill swagger.

Is there a way to both have swagger and the API_KEY filter?

2 Likes

Don't apply your filter on swagger routes

if (!req$PATH_INFO %in% c("/__docs__/", "/__swagger__/", "/openapi.json") {
 # filter
} else {
# nofilter
}

Or something similar

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.