-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Better read. * Implement tibblified paths. * Toward a real class_paths. * Add pkgdown info.
- Loading branch information
1 parent
99886d5
commit 0bb15ec
Showing
16 changed files
with
549 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
Package: rapid | ||
Title: R 'API' Descriptions | ||
Version: 0.0.0.9000 | ||
Version: 0.0.0.9003 | ||
Authors@R: c( | ||
person("Jon", "Harmon", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0003-4781-4346")), | ||
person("The Linux Foundation", role = "cph", | ||
comment = "OpenAPI Specification") | ||
) | ||
Description: Convert an 'API' description ('APID'), such as one that follows | ||
the 'OpenAPI Specification', to an R 'API' description object (a | ||
"rapid"). The rapid object follows the 'OpenAPI Specification' to | ||
Description: Convert an 'API' description ('APID'), such as one that | ||
follows the 'OpenAPI Specification', to an R 'API' description object | ||
(a "rapid"). The rapid object follows the 'OpenAPI Specification' to | ||
make it easy to convert to and from 'API' documents. | ||
License: MIT + file LICENSE | ||
URL: https://jonthegeek.github.io/rapid/, | ||
https://github.com/jonthegeek/rapid | ||
BugReports: https://github.com/jonthegeek/rapid/issues | ||
Depends: | ||
R (>= 3.5.0) | ||
Imports: | ||
cli, | ||
glue, | ||
|
@@ -24,12 +26,15 @@ Imports: | |
S7 (>= 0.1.1), | ||
snakecase, | ||
stbl, | ||
tibble, | ||
tibblify, | ||
xml2, | ||
yaml | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
Remotes: | ||
jonthegeek/stbl | ||
jonthegeek/stbl, | ||
mgirlich/tibblify#191 | ||
Config/testthat/edition: 3 | ||
Config/testthat/parallel: true | ||
Encoding: UTF-8 | ||
|
@@ -38,6 +43,7 @@ RoxygenNote: 7.3.1 | |
Collate: | ||
'properties.R' | ||
'security.R' | ||
'paths.R' | ||
'components-security_scheme_details.R' | ||
'components-security_schemes.R' | ||
'components.R' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#' The available paths and operations for the API | ||
#' | ||
#' Holds the relative paths to the individual endpoints and their operations. | ||
#' The path is appended to the URL from the [class_servers()] object in order to | ||
#' construct the full URL. The paths may be empty. | ||
#' | ||
#' @param ... A data.frame, or arguments to pass to [tibble::tibble()]. | ||
#' | ||
#' @return A `paths` S7 object with details about API endpoints. | ||
#' @export | ||
#' | ||
#' @seealso [as_paths()] for coercing objects to `paths`. | ||
#' | ||
#' @examples | ||
#' class_paths() | ||
#' class_paths( | ||
#' tibble::tibble( | ||
#' endpoint = c("/endpoint1", "/endpoint2"), | ||
#' operations = list( | ||
#' tibble::tibble(operation_properties = 1:2), | ||
#' tibble::tibble(operation_properties = 3:5) | ||
#' ) | ||
#' ) | ||
#' ) | ||
class_paths <- S7::new_class( | ||
"paths", | ||
package = "rapid", | ||
parent = class_data.frame, | ||
constructor = function(...) { | ||
if (...length() == 1 && is.data.frame(..1)) { | ||
return(S7::new_object(tibble::as_tibble(..1))) | ||
} | ||
S7::new_object(tibble::tibble(...)) | ||
} | ||
) | ||
|
||
#' Coerce objects to paths | ||
#' | ||
#' `as_paths()` turns an existing object into a `paths` object. This is in | ||
#' contrast with [class_paths()], which builds a `paths` object from individual | ||
#' properties. In practice, [class_paths()] and `as_paths()` are currently | ||
#' functionally identical. However, in the future, `as_paths()` will coerce | ||
#' other valid objects to the expected shape. | ||
#' | ||
#' @inheritParams rlang::args_dots_empty | ||
#' @inheritParams rlang::args_error_context | ||
#' @param x The object to coerce. Must be empty or be a `data.frame()`. | ||
#' | ||
#' @return A `paths` object as returned by [class_paths()]. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' as_paths() | ||
#' as_paths(mtcars) | ||
as_paths <- S7::new_generic("as_paths", "x") | ||
|
||
S7::method(as_paths, class_data.frame) <- function(x, | ||
..., | ||
arg = caller_arg(x), | ||
call = caller_env()) { | ||
class_paths(x) | ||
} | ||
|
||
S7::method(as_paths, class_any) <- function(x, | ||
..., | ||
arg = caller_arg(x), | ||
call = caller_env()) { | ||
as_api_object(x, class_paths, ..., arg = arg, call = call) | ||
} | ||
|
||
.parse_paths <- S7::new_generic(".parse_paths", "paths") | ||
|
||
S7::method(.parse_paths, class_data.frame | class_paths) <- function(paths, | ||
...) { | ||
paths | ||
} | ||
|
||
S7::method(.parse_paths, class_list) <- function(paths, | ||
openapi, | ||
x, | ||
call = caller_env()) { | ||
if (!is.null(openapi) && openapi >= "3") { | ||
return(.parse_openapi_spec(x, call = call)) | ||
} | ||
return(tibble::tibble()) | ||
} | ||
|
||
.parse_openapi_spec <- function(x, call = caller_env()) { # nocov start | ||
rlang::try_fetch( | ||
{ | ||
tibblify::parse_openapi_spec(x) | ||
}, | ||
error = function(cnd) { | ||
cli::cli_abort( | ||
"Failed to parse paths from OpenAPI spec.", | ||
class = "rapid_error_bad_tibblify", | ||
call = call | ||
) | ||
} | ||
) | ||
} # nocov end | ||
|
||
S7::method(.parse_paths, class_any) <- function(paths, ...) { | ||
return(tibble::tibble()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.