diff --git a/R/as.R b/R/as.R index d733dc8..7588579 100644 --- a/R/as.R +++ b/R/as.R @@ -24,14 +24,24 @@ if (rlang::is_named2(x)) { force(x_arg) x <- rlang::set_names(x, snakecase::to_snake_case) - if (any(names(x) %in% valid_names)) { - x <- as.list(x)[names(x) %in% valid_names] - if (length(extra_names)) { - to_rename <- names(x) %in% names(extra_names) - names(x)[to_rename] <- extra_names[names(x)[to_rename]] - } - return(x) + ignored_names <- names(x)[!names(x) %in% valid_names] + x <- as.list(x)[names(x) %in% valid_names] + if (length(extra_names)) { + to_rename <- names(x) %in% names(extra_names) + names(x)[to_rename] <- extra_names[names(x)[to_rename]] } + x <- x %|0|% NULL + if (length(ignored_names)) { + cli::cli_warn( + c( + "{.arg {x_arg}} expects names {.or {.val {valid_names}}}.", + "*" = "Ignored names: {.val {ignored_names}}." + ), + class = "rapid_warning_extra_names" + ) + } + + return(x) } cli::cli_abort( diff --git a/R/components-security_scheme.R b/R/components-security_scheme.R index ecb65c6..4a34847 100644 --- a/R/components-security_scheme.R +++ b/R/components-security_scheme.R @@ -78,7 +78,9 @@ S7::method(as_security_scheme, class_list) <- function(x) { if (!length(x) || !any(lengths(x))) { return(NULL) } - switch(snakecase::to_snake_case(x$type), + type <- snakecase::to_snake_case(x$type) + x$type <- NULL + switch(type, api_key = as_api_key_security_scheme(x), # http = as_http_security_scheme(x), # mutual_tls = as_mutual_tls_security_scheme(x), diff --git a/R/servers.R b/R/servers.R index 9a3960c..786d1d7 100644 --- a/R/servers.R +++ b/R/servers.R @@ -134,6 +134,9 @@ S7::method(as_servers, class_list) <- function(x) { ) } ) + if (!any(lengths(x))) { + x <- NULL + } servers( url = purrr::map_chr(x, "url"), diff --git a/tests/testthat/_snaps/components-security_scheme-api_key.md b/tests/testthat/_snaps/components-security_scheme-api_key.md index c60d82e..24e7fa9 100644 --- a/tests/testthat/_snaps/components-security_scheme-api_key.md +++ b/tests/testthat/_snaps/components-security_scheme-api_key.md @@ -18,10 +18,10 @@ @ parameter_name: chr "parm1" @ location : chr "query" -# as_api_key_security_scheme() errors for un/misnamed input +# as_api_key_security_scheme() errors for unnamed input Code - as_api_key_security_scheme(list(a = "Jon", b = "jonthegeek@gmail.com")) + as_api_key_security_scheme(list("Jon", "jonthegeek@gmail.com")) Condition Error: ! `x` must have names "parameter_name", "location", "in", or "name". diff --git a/tests/testthat/_snaps/components-security_scheme-oauth2-authorization_code_flow.md b/tests/testthat/_snaps/components-security_scheme-oauth2-authorization_code_flow.md index 3f8d36f..cfd6c81 100644 --- a/tests/testthat/_snaps/components-security_scheme-oauth2-authorization_code_flow.md +++ b/tests/testthat/_snaps/components-security_scheme-oauth2-authorization_code_flow.md @@ -123,7 +123,7 @@ @ authorization_url: chr "https://auth.ebay.com/oauth2/authorize" @ token_url : chr "https://api.ebay.com/identity/v1/oauth2/token" -# as_oauth2_authorization_code_flow() errors for un/misnamed input +# as_oauth2_authorization_code_flow() errors for unnamed input Code as_oauth2_authorization_code_flow("a") @@ -132,15 +132,6 @@ ! `x` must have names "refresh_url", "scopes", "authorization_url", or "token_url". * Any other names are ignored. ---- - - Code - as_oauth2_authorization_code_flow(list(a = "Jon", b = "jtg@gmail.com")) - Condition - Error: - ! `x` must have names "refresh_url", "scopes", "authorization_url", or "token_url". - * Any other names are ignored. - # as_oauth2_authorization_code_flow() errors for bad classes Code diff --git a/tests/testthat/_snaps/components-security_scheme-oauth2-implicit_flow.md b/tests/testthat/_snaps/components-security_scheme-oauth2-implicit_flow.md index bdb59d2..9e23de9 100644 --- a/tests/testthat/_snaps/components-security_scheme-oauth2-implicit_flow.md +++ b/tests/testthat/_snaps/components-security_scheme-oauth2-implicit_flow.md @@ -92,10 +92,10 @@ .. @ description: chr [1:2] "View and manage your account settings" ... @ authorization_url: chr "https://auth.ebay.com/oauth2/authorize" -# as_oauth2_implicit_flow() errors for unnamed or misnamed input +# as_oauth2_implicit_flow() errors for unnamed input Code - as_oauth2_implicit_flow(list(a = "Jon", b = "jonthegeek@gmail.com")) + as_oauth2_implicit_flow(list("Jon", "jonthegeek@gmail.com")) Condition Error: ! `x` must have names "refresh_url", "scopes", or "authorization_url". diff --git a/tests/testthat/_snaps/components-security_scheme-oauth2-token_flow.md b/tests/testthat/_snaps/components-security_scheme-oauth2-token_flow.md index ebe0f5f..29243b1 100644 --- a/tests/testthat/_snaps/components-security_scheme-oauth2-token_flow.md +++ b/tests/testthat/_snaps/components-security_scheme-oauth2-token_flow.md @@ -93,10 +93,10 @@ .. @ description: chr [1:2] "View and manage your account settings" ... @ token_url : chr "https://auth.ebay.com/oauth2/token" -# as_oauth2_token_flow() errors for unnamed or misnamed input +# as_oauth2_token_flow() errors for unnamed input Code - as_oauth2_token_flow(list(a = "Jon", b = "jonthegeek@gmail.com")) + as_oauth2_token_flow(list("Jon", "jonthegeek@gmail.com")) Condition Error: ! `x` must have names "refresh_url", "scopes", or "token_url". diff --git a/tests/testthat/_snaps/components-security_scheme-oauth2.md b/tests/testthat/_snaps/components-security_scheme-oauth2.md index 016a239..5e578d2 100644 --- a/tests/testthat/_snaps/components-security_scheme-oauth2.md +++ b/tests/testthat/_snaps/components-security_scheme-oauth2.md @@ -75,10 +75,10 @@ .. @ authorization_url: chr(0) .. @ token_url : chr(0) -# as_oauth2_security_scheme() errors for unnamed or misnamed input +# as_oauth2_security_scheme() errors for unnamed input Code - as_oauth2_security_scheme(list(a = "Jon", b = "jonthegeek@gmail.com")) + as_oauth2_security_scheme(list("Jon", "jonthegeek@gmail.com")) Condition Error: ! `x` must contain a named flows object. diff --git a/tests/testthat/_snaps/components-security_scheme_collection.md b/tests/testthat/_snaps/components-security_scheme_collection.md index 6fe153b..c8a19d9 100644 --- a/tests/testthat/_snaps/components-security_scheme_collection.md +++ b/tests/testthat/_snaps/components-security_scheme_collection.md @@ -39,7 +39,7 @@ @ details : list() @ description: chr(0) -# as_security_scheme_collection() errors for un/misnamed input +# as_security_scheme_collection() errors for unnamed input Code as_security_scheme_collection(as.list(letters)) diff --git a/tests/testthat/_snaps/components.md b/tests/testthat/_snaps/components.md index 491d2f1..a60a56a 100644 --- a/tests/testthat/_snaps/components.md +++ b/tests/testthat/_snaps/components.md @@ -10,7 +10,7 @@ .. @ details : list() .. @ description: chr(0) -# as_component_collection() errors for unnamed or misnamed input +# as_component_collection() errors for unnamed input Code as_component_collection(as.list(letters)) @@ -22,7 +22,7 @@ --- Code - as_component_collection(list(a = "My Cool API")) + as_component_collection(list("My Cool API")) Condition Error: ! `x` must have names "security_schemes". diff --git a/tests/testthat/_snaps/info-contact.md b/tests/testthat/_snaps/info-contact.md index 48b842e..4491cc1 100644 --- a/tests/testthat/_snaps/info-contact.md +++ b/tests/testthat/_snaps/info-contact.md @@ -64,7 +64,7 @@ @ email: chr(0) @ url : chr(0) -# as_contact() errors informatively for unnamed or misnamed input +# as_contact() errors informatively for unnamed input Code as_contact(letters) @@ -76,7 +76,7 @@ --- Code - as_contact(list(a = "Jon", b = "jonthegeek@gmail.com")) + as_contact(list("Jon", "jonthegeek@gmail.com")) Condition Error: ! `x` must have names "name", "email", or "url". @@ -85,7 +85,7 @@ --- Code - as_contact(c(a = "Jon", b = "jonthegeek@gmail.com")) + as_contact(c("Jon", "jonthegeek@gmail.com")) Condition Error: ! `x` must have names "name", "email", or "url". diff --git a/tests/testthat/_snaps/info-license.md b/tests/testthat/_snaps/info-license.md index 4ebea17..35f5c37 100644 --- a/tests/testthat/_snaps/info-license.md +++ b/tests/testthat/_snaps/info-license.md @@ -111,7 +111,7 @@ @ identifier: chr "technically these have a fancy required format" @ url : chr(0) -# as_license() errors informatively for unnamed or misnamed input +# as_license() errors informatively for unnamed input Code as_license(letters) @@ -120,15 +120,6 @@ ! `x` must have names "name", "identifier", or "url". * Any other names are ignored. ---- - - Code - as_license(list(a = "Apache 2.0", b = "https://opensource.org/license/apache-2-0/")) - Condition - Error: - ! `x` must have names "name", "identifier", or "url". - * Any other names are ignored. - # as_license() errors informatively for bad classes Code diff --git a/tests/testthat/_snaps/info.md b/tests/testthat/_snaps/info.md index 3f6b650..853f82f 100644 --- a/tests/testthat/_snaps/info.md +++ b/tests/testthat/_snaps/info.md @@ -50,7 +50,7 @@ @ summary : chr(0) @ terms_of_service: chr(0) -# as_info() errors informatively for unnamed or misnamed input +# as_info() errors informatively for unnamed input Code as_info(letters) @@ -62,7 +62,7 @@ --- Code - as_info(list(a = "My Cool API")) + as_info(list("My Cool API")) Condition Error: ! `x` must have names "title", "version", "contact", "description", "license", "summary", or "terms_of_service". diff --git a/tests/testthat/_snaps/servers-string_replacements.md b/tests/testthat/_snaps/servers-string_replacements.md index 0ede237..a9435d9 100644 --- a/tests/testthat/_snaps/servers-string_replacements.md +++ b/tests/testthat/_snaps/servers-string_replacements.md @@ -124,7 +124,7 @@ .. $ : NULL @ description: chr [1:3] "The active user's folder." NA NA -# as_string_replacements() errors for un/misnamed input +# as_string_replacements() errors for unnamed input Code as_string_replacements(letters) @@ -135,7 +135,7 @@ --- Code - as_string_replacements(list(a = "Jon", b = "jonthegeek@gmail.com")) + as_string_replacements(list("Jon", "jonthegeek@gmail.com")) Condition Error in `purrr::map_chr()`: i In index: 1. @@ -145,7 +145,7 @@ --- Code - as_string_replacements(c(a = "Jon", b = "jonthegeek@gmail.com")) + as_string_replacements(c("Jon", "jonthegeek@gmail.com")) Condition Error: ! Can't coerce `x` to . diff --git a/tests/testthat/_snaps/servers.md b/tests/testthat/_snaps/servers.md index 0d5c88c..90f22ef 100644 --- a/tests/testthat/_snaps/servers.md +++ b/tests/testthat/_snaps/servers.md @@ -9,7 +9,7 @@ @ description: chr(0) @ variables : list() -# as_servers() errors informatively for unnamed or misnamed input +# as_servers() errors informatively for unnamed input Code as_servers(list(letters)) @@ -20,17 +20,6 @@ ! `x[[i]]` must have names "url", "description", or "variables". * Any other names are ignored. ---- - - Code - as_servers(list(list(a = "https://example.com", b = "A cool server."))) - Condition - Error in `purrr::map()`: - i In index: 1. - Caused by error in `as_servers()`: - ! `x[[i]]` must have names "url", "description", or "variables". - * Any other names are ignored. - # as_servers() errors informatively for bad classes Code diff --git a/tests/testthat/_snaps/zz-rapid.md b/tests/testthat/_snaps/zz-rapid.md index fc0de4b..040d879 100644 --- a/tests/testthat/_snaps/zz-rapid.md +++ b/tests/testthat/_snaps/zz-rapid.md @@ -91,7 +91,7 @@ Error: ! Can't coerce `x` to . -# as_rapid() errors informatively for unnamed or misnamed input +# as_rapid() errors informatively for unnamed input Code as_rapid(list(letters)) @@ -105,7 +105,7 @@ --- Code - as_rapid(list(list(a = "https://example.com", b = "A cool server."))) + as_rapid(list(list("https://example.com", "A cool server."))) Condition Error: ! `x` must be comprised of properly formed, supported elements. @@ -113,22 +113,11 @@ ! `x` must have names "info", "servers", "components", or "security". * Any other names are ignored. -# as_rapid() fails gracefully for unsupported urls - - Code - as_rapid(url("https://api.apis.guru/v2/openapi.yaml")) - Condition - Error: - ! `x` must be comprised of properly formed, supported elements. - Caused by error: - ! `x` must have names "security_schemes". - * Any other names are ignored. - # as_rapid() works for urls Code - as_rapid(url( - "https://api.apis.guru/v2/specs/amazonaws.com/AWSMigrationHub/2017-05-31/openapi.yaml")) + suppressWarnings(as_rapid(url( + "https://api.apis.guru/v2/specs/amazonaws.com/AWSMigrationHub/2017-05-31/openapi.yaml"))) Output @ info : @@ -187,3 +176,49 @@ .. .. $ : chr(0) .. @ rapid_class_requirement: chr "security_scheme" +# as_rapid() works for empty optional fields + + Code + suppressWarnings(as_rapid(x)) + Output + + @ info : + .. @ title : chr "OpenFEC" + .. @ version : chr "1.0" + .. @ contact : + .. .. @ name : chr(0) + .. .. @ email: chr(0) + .. .. @ url : chr(0) + .. @ description : chr "This application programming interface (API) allows you to explore the way candidates and committees fund their"| __truncated__ + .. @ license : + .. .. @ name : chr(0) + .. .. @ identifier: chr(0) + .. .. @ url : chr(0) + .. @ summary : chr(0) + .. @ terms_of_service: chr(0) + @ servers : + .. @ url : chr "/v1" + .. @ description: chr(0) + .. @ variables : list() + @ components: + .. @ security_schemes: + .. .. @ name : chr [1:3] "ApiKeyHeaderAuth" "ApiKeyQueryAuth" "apiKey" + .. .. @ details : List of 3 + .. .. .. $ : + .. .. .. ..@ parameter_name: chr "X-Api-Key" + .. .. .. ..@ location : chr "header" + .. .. .. $ : + .. .. .. ..@ parameter_name: chr "api_key" + .. .. .. ..@ location : chr "query" + .. .. .. $ : + .. .. .. ..@ parameter_name: chr "api_key" + .. .. .. ..@ location : chr "query" + .. .. @ description: chr(0) + @ security : + .. @ name : chr [1:3] "ApiKeyHeaderAuth" "ApiKeyQueryAuth" "apiKey" + .. @ required_scopes :List of 3 + .. .. $ : chr(0) + .. .. $ : chr(0) + .. .. $ : chr(0) + .. @ rapid_class_requirement: chr "security_scheme" + diff --git a/tests/testthat/fixtures/fec.rds b/tests/testthat/fixtures/fec.rds new file mode 100644 index 0000000..54c005c Binary files /dev/null and b/tests/testthat/fixtures/fec.rds differ diff --git a/tests/testthat/test-components-security_scheme-api_key.R b/tests/testthat/test-components-security_scheme-api_key.R index abf0200..2cd2eec 100644 --- a/tests/testthat/test-components-security_scheme-api_key.R +++ b/tests/testthat/test-components-security_scheme-api_key.R @@ -41,9 +41,9 @@ test_that("length() of a api_key_security_scheme reports the proper length", { ) }) -test_that("as_api_key_security_scheme() errors for un/misnamed input", { +test_that("as_api_key_security_scheme() errors for unnamed input", { expect_snapshot( - as_api_key_security_scheme(list(a = "Jon", b = "jonthegeek@gmail.com")), + as_api_key_security_scheme(list("Jon", "jonthegeek@gmail.com")), error = TRUE ) }) @@ -64,7 +64,7 @@ test_that("as_api_key_security_scheme() errors informatively for bad classes", { }) test_that("as_api_key_security_scheme() returns expected objects", { - expect_identical( + expect_warning( as_api_key_security_scheme( list( name = "Authorization", @@ -72,6 +72,18 @@ test_that("as_api_key_security_scheme() returns expected objects", { `x-amazon-apigateway-authtype` = "awsSigv4" ) ), + regexp = "x_amazon_apigateway_authtype", + class = "rapid_warning_extra_names" + ) + + expect_identical( + suppressWarnings(as_api_key_security_scheme( + list( + name = "Authorization", + `in` = "header", + `x-amazon-apigateway-authtype` = "awsSigv4" + ) + )), api_key_security_scheme( parameter_name = "Authorization", location = "header" diff --git a/tests/testthat/test-components-security_scheme-oauth2-authorization_code_flow.R b/tests/testthat/test-components-security_scheme-oauth2-authorization_code_flow.R index 455bf81..205b4e8 100644 --- a/tests/testthat/test-components-security_scheme-oauth2-authorization_code_flow.R +++ b/tests/testthat/test-components-security_scheme-oauth2-authorization_code_flow.R @@ -90,15 +90,11 @@ test_that("length() of oauth2_authorization_code_flow reports overall length", { ) }) -test_that("as_oauth2_authorization_code_flow() errors for un/misnamed input", { +test_that("as_oauth2_authorization_code_flow() errors for unnamed input", { expect_snapshot( as_oauth2_authorization_code_flow("a"), error = TRUE ) - expect_snapshot( - as_oauth2_authorization_code_flow(list(a = "Jon", b = "jtg@gmail.com")), - error = TRUE - ) }) test_that("as_oauth2_authorization_code_flow() errors for bad classes", { diff --git a/tests/testthat/test-components-security_scheme-oauth2-implicit_flow.R b/tests/testthat/test-components-security_scheme-oauth2-implicit_flow.R index bfda7e7..bd29db8 100644 --- a/tests/testthat/test-components-security_scheme-oauth2-implicit_flow.R +++ b/tests/testthat/test-components-security_scheme-oauth2-implicit_flow.R @@ -75,9 +75,9 @@ test_that("length() of an oauth2_implicit_flow reports the overall length", { ) }) -test_that("as_oauth2_implicit_flow() errors for unnamed or misnamed input", { +test_that("as_oauth2_implicit_flow() errors for unnamed input", { expect_snapshot( - as_oauth2_implicit_flow(list(a = "Jon", b = "jonthegeek@gmail.com")), + as_oauth2_implicit_flow(list("Jon", "jonthegeek@gmail.com")), error = TRUE ) }) diff --git a/tests/testthat/test-components-security_scheme-oauth2-token_flow.R b/tests/testthat/test-components-security_scheme-oauth2-token_flow.R index f5045c8..f3eac2f 100644 --- a/tests/testthat/test-components-security_scheme-oauth2-token_flow.R +++ b/tests/testthat/test-components-security_scheme-oauth2-token_flow.R @@ -75,9 +75,9 @@ test_that("length() of an oauth2_token_flow reports the overall length", { ) }) -test_that("as_oauth2_token_flow() errors for unnamed or misnamed input", { +test_that("as_oauth2_token_flow() errors for unnamed input", { expect_snapshot( - as_oauth2_token_flow(list(a = "Jon", b = "jonthegeek@gmail.com")), + as_oauth2_token_flow(list("Jon", "jonthegeek@gmail.com")), error = TRUE ) }) diff --git a/tests/testthat/test-components-security_scheme-oauth2.R b/tests/testthat/test-components-security_scheme-oauth2.R index 4090ed7..987d3f5 100644 --- a/tests/testthat/test-components-security_scheme-oauth2.R +++ b/tests/testthat/test-components-security_scheme-oauth2.R @@ -69,11 +69,9 @@ test_that("length() of a oauth2_security_scheme reports the proper length", { ) }) -test_that("as_oauth2_security_scheme() errors for unnamed or misnamed input", { +test_that("as_oauth2_security_scheme() errors for unnamed input", { expect_snapshot( - as_oauth2_security_scheme( - list(a = "Jon", b = "jonthegeek@gmail.com") - ), + as_oauth2_security_scheme(list("Jon", "jonthegeek@gmail.com")), error = TRUE ) }) diff --git a/tests/testthat/test-components-security_scheme_collection.R b/tests/testthat/test-components-security_scheme_collection.R index 3215f0e..ead059b 100644 --- a/tests/testthat/test-components-security_scheme_collection.R +++ b/tests/testthat/test-components-security_scheme_collection.R @@ -70,7 +70,7 @@ test_that("length() of security_scheme_collection reports the overall length", { ) }) -test_that("as_security_scheme_collection() errors for un/misnamed input", { +test_that("as_security_scheme_collection() errors for unnamed input", { expect_snapshot( as_security_scheme_collection(as.list(letters)), error = TRUE diff --git a/tests/testthat/test-components.R b/tests/testthat/test-components.R index 3981f9e..9a69ea7 100644 --- a/tests/testthat/test-components.R +++ b/tests/testthat/test-components.R @@ -45,13 +45,13 @@ test_that("length() of an security_schemes reports the overall length", { ) }) -test_that("as_component_collection() errors for unnamed or misnamed input", { +test_that("as_component_collection() errors for unnamed input", { expect_snapshot( as_component_collection(as.list(letters)), error = TRUE ) expect_snapshot( - as_component_collection(list(a = "My Cool API")), + as_component_collection(list("My Cool API")), error = TRUE ) }) diff --git a/tests/testthat/test-info-contact.R b/tests/testthat/test-info-contact.R index fc14a79..87cfff7 100644 --- a/tests/testthat/test-info-contact.R +++ b/tests/testthat/test-info-contact.R @@ -69,17 +69,17 @@ test_that("length() of a contact reports the overall length", { expect_equal(length(contact(name = "A")), 1) }) -test_that("as_contact() errors informatively for unnamed or misnamed input", { +test_that("as_contact() errors informatively for unnamed input", { expect_snapshot( as_contact(letters), error = TRUE ) expect_snapshot( - as_contact(list(a = "Jon", b = "jonthegeek@gmail.com")), + as_contact(list("Jon", "jonthegeek@gmail.com")), error = TRUE ) expect_snapshot( - as_contact(c(a = "Jon", b = "jonthegeek@gmail.com")), + as_contact(c("Jon", "jonthegeek@gmail.com")), error = TRUE ) }) @@ -118,8 +118,7 @@ test_that("as_contact() returns expected objects", { as_contact( c( name = "Jon", - email = "jonthegeek@gmail.com", - x = "https://jonthegeek.com" + email = "jonthegeek@gmail.com" ) ), contact( @@ -131,8 +130,7 @@ test_that("as_contact() returns expected objects", { as_contact( c( email = "jonthegeek@gmail.com", - name = "Jon", - x = "https://jonthegeek.com" + name = "Jon" ) ), contact( @@ -144,8 +142,7 @@ test_that("as_contact() returns expected objects", { as_contact( list( name = "Jon", - email = "jonthegeek@gmail.com", - x = "https://jonthegeek.com" + email = "jonthegeek@gmail.com" ) ), contact( diff --git a/tests/testthat/test-info-license.R b/tests/testthat/test-info-license.R index c7576ab..13bc9dd 100644 --- a/tests/testthat/test-info-license.R +++ b/tests/testthat/test-info-license.R @@ -96,17 +96,11 @@ test_that("length() of a license reports the overall length", { expect_equal(length(license(name = "A")), 1) }) -test_that("as_license() errors informatively for unnamed or misnamed input", { +test_that("as_license() errors informatively for unnamed input", { expect_snapshot( as_license(letters), error = TRUE ) - expect_snapshot( - as_license( - list(a = "Apache 2.0", b = "https://opensource.org/license/apache-2-0/") - ), - error = TRUE - ) }) test_that("as_license() errors informatively for bad classes", { @@ -135,43 +129,28 @@ test_that("as_license() returns expected objects", { identifier = "Apache-2.0" ) ) - expect_identical( + expect_warning( as_license(c( name = "Apache 2.0", identifier = "Apache-2.0", x = "https://jonthegeek.com" )), - license( - name = "Apache 2.0", - identifier = "Apache-2.0" - ) - ) - expect_identical( - as_license( - c( - identifier = "Apache-2.0", - name = "Apache 2.0", - x = "https://jonthegeek.com" - ) - ), - license( - name = "Apache 2.0", - identifier = "Apache-2.0" - ) + class = "rapid_warning_extra_names" ) expect_identical( - as_license( - list( + suppressWarnings( + as_license(c( name = "Apache 2.0", identifier = "Apache-2.0", x = "https://jonthegeek.com" - ) + )) ), license( name = "Apache 2.0", identifier = "Apache-2.0" ) ) + expect_identical( as_license(list()), license() diff --git a/tests/testthat/test-info.R b/tests/testthat/test-info.R index 872aac8..90aa748 100644 --- a/tests/testthat/test-info.R +++ b/tests/testthat/test-info.R @@ -54,13 +54,13 @@ test_that("length() of an info reports the overall length", { ) }) -test_that("as_info() errors informatively for unnamed or misnamed input", { +test_that("as_info() errors informatively for unnamed input", { expect_snapshot( as_info(letters), error = TRUE ) expect_snapshot( - as_info(list(a = "My Cool API")), + as_info(list("My Cool API")), error = TRUE ) }) diff --git a/tests/testthat/test-servers-string_replacements.R b/tests/testthat/test-servers-string_replacements.R index bd08e98..81df748 100644 --- a/tests/testthat/test-servers-string_replacements.R +++ b/tests/testthat/test-servers-string_replacements.R @@ -99,17 +99,17 @@ test_that("length() of a string_replacements reports the overall length", { expect_equal(length(string_replacements(name = "A", default = "A")), 1) }) -test_that("as_string_replacements() errors for un/misnamed input", { +test_that("as_string_replacements() errors for unnamed input", { expect_snapshot( as_string_replacements(letters), error = TRUE ) expect_snapshot( - as_string_replacements(list(a = "Jon", b = "jonthegeek@gmail.com")), + as_string_replacements(list("Jon", "jonthegeek@gmail.com")), error = TRUE ) expect_snapshot( - as_string_replacements(c(a = "Jon", b = "jonthegeek@gmail.com")), + as_string_replacements(c("Jon", "jonthegeek@gmail.com")), error = TRUE ) }) diff --git a/tests/testthat/test-servers.R b/tests/testthat/test-servers.R index a8b928f..e941861 100644 --- a/tests/testthat/test-servers.R +++ b/tests/testthat/test-servers.R @@ -61,15 +61,11 @@ test_that("length() of a servers reports the overall length", { ) }) -test_that("as_servers() errors informatively for unnamed or misnamed input", { +test_that("as_servers() errors informatively for unnamed input", { expect_snapshot( as_servers(list(letters)), error = TRUE ) - expect_snapshot( - as_servers(list(list(a = "https://example.com", b = "A cool server."))), - error = TRUE - ) }) test_that("as_servers() errors informatively for bad classes", { diff --git a/tests/testthat/test-zz-rapid.R b/tests/testthat/test-zz-rapid.R index ca84afc..1a2562d 100644 --- a/tests/testthat/test-zz-rapid.R +++ b/tests/testthat/test-zz-rapid.R @@ -129,13 +129,13 @@ test_that("as_rapid() errors informatively for bad classes", { ) }) -test_that("as_rapid() errors informatively for unnamed or misnamed input", { +test_that("as_rapid() errors informatively for unnamed input", { expect_snapshot( as_rapid(list(letters)), error = TRUE ) expect_snapshot( - as_rapid(list(list(a = "https://example.com", b = "A cool server."))), + as_rapid(list(list("https://example.com", "A cool server."))), error = TRUE ) }) @@ -213,25 +213,72 @@ test_that("as_rapid() works for lists", { ) }) -test_that("as_rapid() fails gracefully for unsupported urls", { +test_that("as_rapid() works for urls", { skip_if_not(Sys.getenv("RAPID_TEST_DL") == "true") - expect_error( - as_rapid(url("https://api.apis.guru/v2/openapi.yaml")), - class = "rapid_error_unsupported_elements" - ) - expect_snapshot( - as_rapid(url("https://api.apis.guru/v2/openapi.yaml")), - error = TRUE + + expect_warning( + expect_warning( + expect_warning( + expect_warning( + expect_warning( + as_rapid( + url( + "https://api.apis.guru/v2/specs/amazonaws.com/AWSMigrationHub/2017-05-31/openapi.yaml" + ) + ), + "x_has_equivalent_paths", + class = "rapid_warning_extra_names" + ), + "x_release", + class = "rapid_warning_extra_names" + ), + "x_twitter", + class = "rapid_warning_extra_names" + ), + "parameters", + class = "rapid_warning_extra_names" + ), + "x_amazon_apigateway_authtype", + class = "rapid_warning_extra_names" ) -}) -test_that("as_rapid() works for urls", { - skip_if_not(Sys.getenv("RAPID_TEST_DL") == "true") expect_snapshot( - as_rapid( + suppressWarnings(as_rapid( url( "https://api.apis.guru/v2/specs/amazonaws.com/AWSMigrationHub/2017-05-31/openapi.yaml" ) - ) + )) + ) +}) + +test_that("as_rapid() works for empty optional fields", { + # TODO: Manually generate a more-broken example. + # + # x <- + # url("https://api.apis.guru/v2/specs/fec.gov/1.0/openapi.yaml") |> + # yaml::read_yaml() + # saveRDS(x, test_path("fixtures", "fec.rds")) + x <- readRDS(test_path("fixtures", "fec.rds")) + + expect_warning( + expect_warning( + expect_warning( + expect_warning( + as_rapid(x), + "openapi", + class = "rapid_warning_extra_names" + ), + "x_twitter", + class = "rapid_warning_extra_names" + ), + "x_apisguru_categories", + class = "rapid_warning_extra_names" + ), + "schemas", + class = "rapid_warning_extra_names" + ) + + expect_snapshot( + suppressWarnings(as_rapid(x)) ) })