I have added Bearer token authorization to my Swagger (created with Plumber), using the solution here.
Now I would like to add arbitrary headers that are a part of the request. My plumber deployment is used by a React dashboard, where parsing req$HTTP_TENANT
gives me the desired value. And it is this I would like to recreate in Swagger.
Consider this example:
library(plumber)
r <- plumber::pr("plumber.R") %>%
plumber::pr_set_docs("swagger") %>%
plumber::pr_set_api_spec(function(spec) {
spec$components$securitySchemes$bearerAuth$type <- "http"
spec$components$securitySchemes$bearerAuth$scheme <- "bearer"
spec$components$securitySchemes$bearerAuth$bearerFormat <- "JWT"
spec$security[[1]]$bearerAuth <- ""
spec$components$parameters$HTTP_TENANT <- "HTTP_TENANT"
spec$parameters[[1]]$HTTP_TENANT <- "Customer name"
spec
})
r %>% plumber::pr_run(port = 8000, host = '0.0.0.0')
This gives the following result:
- How can arbitrary headers be requested, for example
HTTP_TENANT
, maybe typed below the Bearer token input? It could also be somewhere else at the top of Swagger. - How can default values be provided for the headers, e.g.
Customer name
, but also the Bearer token (i.e. it could be programmatically entered from R)?