-
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
Work in progress, combined PR #536
Conversation
…oad. More swagger swag.
Merge remote-tracking branch 'upstream/master' into to_from_openapi # Conflicts: # R/plumber-response.R # man/plumber.Rd
Merge branch 'rm_pr_link_news' into to_from_openapi # Conflicts: # NEWS.md
@meztez Do you mind remerging the |
I was thinking about splitting this one in smaller chunk since you merge #532 if it is ok with you. yes before monday. |
Even better! 🙌 |
Merge remote-tracking branch 'upstream/master' into to_from_openapi # Conflicts: # DESCRIPTION # NAMESPACE # NEWS.md # R/content-types.R # R/globals.R # R/plumb-block.R # R/plumber.R # R/post-body.R # R/query-string.R # R/swagger.R # inst/examples/15-swagger-spec/entrypoint.R # man/addParser.Rd # man/parsers.Rd # tests/testthat/test-postbody.R # tests/testthat/test-swagger.R
dataTypesInfo <- list() | ||
dataTypesMap <- list() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May we use a more specific name? Maybe apiTypesInfo
? (sub("data", "api", .)
)
It's a lot of name changes, but it helps when reading to supply context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was in the process a decoupling the mountui part and de renaming, reorganizing part.
Also wondering what would be a good name for dataType.
It refers to OpenAPI data types. If you think apiTypes would work, I'm down for it.
Don't worry about replacing stuff. Naming things is the hardest part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also wondering what would be a good name for dataType.
apiType
helps a lot. It lets me know that it's prolly a string value describing the OpenAPI Spec type.
dataType
feels like an output of typeof()
or something unrelated to OpenAPI
I was in the process a decoupling the mountui part and de renaming, reorganizing part.
Great! Feel free to make those changes there. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am hoping to refer to all things OpenAPI
by using api
in the variable name.
(Things with plumber
are pr
or router
.)
ui = interactive(), | ||
debug = interactive(), | ||
swaggerCallback = getOption('plumber.swagger.url', NULL) | ||
callback = getOption('plumber.ui.callback', getOption('plumber.swagger.url', NULL)), | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the order? And set ui
to TRUE.
...,
ui = TRUE,
debug = interactive(),
callback = ....
if (is.list(self$customSpec)) { | ||
ret <- utils::modifyList(ret, self$customSpec) | ||
} | ||
ret <- removeNaOrNulls(ret) | ||
|
||
ret | ||
}, | ||
#' @description Retrieve openAPI file | ||
openAPIFile = function() { | ||
self$swaggerFile() | ||
}, | ||
#' @field customSpec A list of custom spec to overlay over openAPI spec | ||
#' generated from a plumber router. | ||
customSpec = NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using a static object, I'd like to supply a function directly.
#### in the private defs
apiHandler = force,
#' @description Add a function to customize what is returned in `$apiSpec()`.
#' @param api_fun This function should accept an OpenAPI Specification autogenerated by `plumber`. It should return a list object in valid OpenAPI Specification format. This will not be validated.
setApiHandler = function(api_fun = force) {
# allow null values
if (!is.null(api_fun)) {
stopifnot(is.function(api_fun))
}
private$apiHandler <- api_fun
}
# Lay those over the default globals so we ensure that the required fields | ||
# (like API version) are satisfied. | ||
#' @description Retrieve OpenAPI specification | ||
openAPISpec = function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a little shorter and less confusing with the caps
openAPISpec = function() { | |
apiSpec = function() { |
In the documentation, we can always refer to it as the OpenAPI Specification function
|
||
# Lay those over the default globals so we ensure that the required fields | ||
# (like API version) are satisfied. | ||
#' @description Retrieve OpenAPI specification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They seem to like Specification
to be capitalized
The OpenAPI Specification (OAS) defines ....
#' @description Retrieve OpenAPI specification | |
#' @description Retrieve OpenAPI Specification |
|
||
### Legacy/Deprecated | ||
#' @description Retrieve OpenAPI specification (deprecated and will be removed in a coming release) | ||
openAPIFile = function() { | ||
self$openAPISpec() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self$openAPISpec() | |
warning("`$openAPIFile()` has been deprecated in v1.0.0 and will be removed in a coming release. Please use `$apiSpec()`.") | |
self$openAPISpec() |
self$openAPISpec() | ||
}, | ||
#' @description Retrieve OpenAPI specification (deprecated and will be removed in a coming release) | ||
swaggerFile = function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swaggerFile = function() { | |
warning("`$swaggerFile()` has been deprecated in v1.0.0 and will be removed in a coming release. Please use `$apiSpec()`.") | |
swaggerFile = function() { |
@@ -1071,7 +985,7 @@ plumber <- R6Class( | |||
private$ends[[preempt]] <- c(private$ends[[preempt]], ep) | |||
}, | |||
|
|||
swaggerFileWalkMountsInternal = function(router, parentPath = "") { | |||
routerSpecificationInternal = function(router, parentPath = "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for renaming these variables! 😃
By adding #562, this one can die in peace. Goodbye shemera PR. |
I combined all the work done into one PR, it was getting hard to track all work across different branches.
This is still a work in progress.
What this branch contains:
Still to be done:
Breaking:
swagger/swaggerCallback in run method of PlumberRouter :
ui
andcallback
paramui
can be TRUE, FALSE or character vectorcallback
has the same function as before (RStudio)Why I broke stuff : I felt it was needed for 5.0.0 to make a clear split between the UIs (Swagger, Redoc) and OpenAPI specifications. You don't need to run a router to get the specs with your custom definitions in this PR. I also think the run method had too much clutter.
Custom definitions are applied using
utils::modifyList
and overwrite default plumber spec. This is a bit different than prior approach.Open questions to maintainers:
Body parsing
Decide what to do with files sent to API
Misc