Skip to content

Commit

Permalink
Fix tibblify issues in tibblify. (#97)
Browse files Browse the repository at this point in the history
We now rely on a version of tibblify that fixes the issues with the existing PR (mgirlich/tibblify#193). Hopefully I can make this the "real" version of tibblify before too long!
  • Loading branch information
jonthegeek authored Dec 16, 2024
1 parent 4d7399e commit f2c57c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 48 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ Imports:
snakecase,
stbl,
tibble,
tibblify,
tibblify (>= 0.3.1.9000),
xml2,
yaml
Suggests:
testthat (>= 3.0.0)
Remotes:
tibblify=mgirlich/tibblify#191
tibblify=mgirlich/tibblify#193
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Expand Down
48 changes: 2 additions & 46 deletions R/paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ S7::method(.parse_paths, class_list) <- function(paths,
.check_tibblify_version(call = call)
rlang::try_fetch(
{
tibblify::parse_openapi_spec(.prepare_spec_for_tibblify(x))
tibblify::parse_openapi_spec(x)
},
error = function(cnd) {
cli::cli_abort(
Expand Down Expand Up @@ -118,58 +118,14 @@ S7::method(.parse_paths, class_list) <- function(paths,
c(
"Incorrect tibblify version.",
i = "This package requires an in-progress version of the package tibblify.",
i = "To parse this spec, first {.run pak::pak('mgirlich/tibblify#191')}."
i = "To parse this spec, first {.run pak::pak('mgirlich/tibblify#193')}."
),
class = "rapid_error_bad_tibblify",
call = call
)
}
}

.prepare_spec_for_tibblify <- function(x) {
if ("paths" %in% names(x)) {
x$paths <- .prepare_paths_for_tibblify(x$paths)
}
return(x)
}

.prepare_paths_for_tibblify <- function(paths) {
purrr::map(
paths,
.prepare_path_for_tibblify
)
}

.prepare_path_for_tibblify <- function(path) {
methods <- c("get", "put", "post", "delete", "options", "head", "patch", "trace")
path[intersect(names(path), methods)] <- purrr::map(
path[intersect(names(path), methods)],
.prepare_method_for_tibblify
)
}

.prepare_method_for_tibblify <- function(method) {
if (is.null(method$tags)) {
method$tags <- "general"
}
method$responses <- purrr::map(
method$responses,
.prepare_response_for_tibblify
)
return(method)
}

.prepare_response_for_tibblify <- function(response) {
if (!is.null(response$`$ref`)) {
if (.is_url_string(response$`$ref`)) {
other_parts <- response[setdiff(names(response), "$ref")]
response <- c(.url_fetch(response$`$ref`), other_parts)
}
}
response$description <- response$description %||% "Undescribed"
return(response)
}

# nocov end

S7::method(.parse_paths, class_any) <- function(paths, ...) {
Expand Down

0 comments on commit f2c57c9

Please sign in to comment.