-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swagger Support #417
Comments
The GitHub version currently allows for users to add their own spec information. plumber does not currently validate this spec, so please return a valid swagger spec object. To get the latest: "Add you own spec" example: (changes title to the current time) If elements are required to be an array, I suggest using |
Please see #390 as an example of an error caused a vector of size 1 when it should be treated as a list. |
Pretty interesting. Two comments on that: When I tried to run the above code with the devel version of swagger, I get an error: library(plumber)
pr <- plumber$new()
pr$handle("GET", "/:path/here", function(){})
pr$run(
port = 1234,
swagger = function(pr_, spec, ...) {
spec$info$title <- Sys.time()
spec
}
)
Running plumber API at http://127.0.0.1:1234
Running Swagger UI at http://127.0.0.1:1234/__swagger__/
<simpleError: 'swagger_spec' is not an exported object from 'namespace:swagger'>
<simpleError: 'swagger_spec' is not an exported object from 'namespace:swagger'> When I use the devel version of rstudio/swagger, then I don't get an error. So maybe specify a minimal version requirement on swagger? But when I want to click on the json link right below the API title (http://127.0.0.1:1234/openapi.json in my case), I get this error:
This also happens when I don't specify the
Makes sense to me. What about a mixed approach? With
That would allow to maintain a clean swagger config file because specifying many elements of the configuration similar to spec$info$title <- Sys.time() may lead to code that is not very readable. Optionally, I think it would be nice if there would be a function to export the config file. I did not find that? Is it there already? Thanks for your work on the project. |
Great idea.
Yay for finding a bug!
Correct
Check out |
(Leaving this issue open for now as there is currently dev version support but not support on the CRAN version of plumber.) |
Thank you so much, very useful. |
@schloerke Thanks for clarification on midterm scope. Injecting a custom swagger works like a charm with the yaml fix mentioned in #390 . |
Just wanted to include an idea for automatically populating the query parameter required field in a Swagger spec by inspecting a function's formal arguments:
Which could be used to generate the equivalent of
|
myFun <- function(x, y = 1, z = NULL, b = .GlobalEnv) {
}
args <- formals(myFun)
sapply(args, is.symbol)
# x y z a b
# TRUE FALSE FALSE FALSE TRUE But this will? sapply(args, identical, formals(function(x){})$x)
# x y z a b
# TRUE FALSE FALSE FALSE FALSE |
Plumber has no plans on fully supporting OpenAPI Spec via plumber tags ( Going to close this issue as the v1.0.0 release of Example: pr$set_api_spec(object)
pr$set_api_spec(func)
pr_set_api_spec(pr, object)
pr_set_api_spec(pr, function)
Also, we are able to validate what plumber is returning using |
Does the current annotation support swagger specs fully? For example I wanted to have a POST API with name value in form-data whose value is of type 'File'. If annotations do not support, is it possible for me to prepare the swagger json/yml separately and pass it as argument when I launch the router?
The text was updated successfully, but these errors were encountered: