-
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.
* Implement components/parameters. * Working tests after a long break. * Update docs. * Cleanup. * Roll back parameter work. * Don't call as_security_scheme() without args as_security_scheme() doesn't make sense without args, since it needs to know what sort of empty security scheme to build. * Style. * Avoid long lines And mention everything in _pkgdown.yml. * Test as_security_scheme() with missing arg.
- Loading branch information
1 parent
e05b3f6
commit 99886d5
Showing
46 changed files
with
859 additions
and
65 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
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,79 @@ | ||
#' @include properties.R | ||
NULL | ||
|
||
#' A simple object for referencing other components in the API description | ||
#' | ||
#' The `reference` object allows for reuse of components between different parts | ||
#' of the API description. These objects are currently simple character | ||
#' references, but may change structure in the future to automatically resolve | ||
#' references. | ||
#' | ||
#' @param ref_uri Character scalar. The reference identifier. This must be in | ||
#' the form of a URI. | ||
#' @param summary Character scalar (optional). A short summary which by default | ||
#' should override that of the referenced component. If the referenced | ||
#' object-type does not allow a summary field, then this field has no effect. | ||
#' @param description Character scalar (optional). A description which by | ||
#' default should override that of the referenced component. [CommonMark | ||
#' syntax](https://spec.commonmark.org/) may be used for rich text | ||
#' representation. If the referenced object-type does not allow a description | ||
#' field, then this field has no effect. | ||
#' | ||
#' @return A `reference` S7 object pointing (by name) to another part of the | ||
#' `rapid` object. | ||
#' @export | ||
#' | ||
#' @seealso [as_reference()] for coercing objects to `reference`. | ||
#' | ||
#' @examples | ||
#' class_reference("#/components/schemas/Pet") | ||
class_reference <- S7::new_class( | ||
name = "reference", | ||
package = "rapid", | ||
properties = list( | ||
ref_uri = character_scalar_property("ref_uri"), | ||
summary = character_scalar_property("summary"), | ||
description = character_scalar_property("description") | ||
), | ||
validator = function(self) { | ||
validate_parallel( | ||
self, | ||
"ref_uri", | ||
optional = c("summary", "description") | ||
) | ||
} | ||
) | ||
|
||
S7::method(length, class_reference) <- function(x) { | ||
length(x@ref_uri) | ||
} | ||
|
||
#' Coerce lists and character vectors to references | ||
#' | ||
#' `as_reference()` turns an existing object into a `reference`. This is in | ||
#' contrast with [class_reference()], which builds a `reference` from individual | ||
#' properties. | ||
#' | ||
#' @inheritParams rlang::args_dots_empty | ||
#' @inheritParams rlang::args_error_context | ||
#' @param x The object to coerce. Must be empty or have names "type", | ||
#' "nullable", "description", and/or "format", or names that can be coerced to | ||
#' those names via [snakecase::to_snake_case()]. Extra names are ignored. This | ||
#' object should describe a single reference. | ||
#' | ||
#' @return A `reference` as returned by [class_reference()]. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' as_reference() | ||
#' as_reference(list(`$ref` = "#/components/schemas/Pet")) | ||
as_reference <- function(x, ..., arg = caller_arg(x), call = caller_env()) { | ||
as_api_object( | ||
x, | ||
class_reference, | ||
..., | ||
alternate_names = c("$ref" = "ref_uri"), | ||
arg = arg, | ||
call = call | ||
) | ||
} |
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 @@ | ||
#' @include properties.R | ||
NULL | ||
|
||
#' Reusable input and output data type definitions | ||
#' | ||
#' The `schema` object allows the definition of input and output data types. | ||
#' These types can be objects, but also primitives and arrays. This object is a | ||
#' superset of the [JSON Schema Specification Draft | ||
#' 2020-12](https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00). | ||
#' | ||
#' @inheritParams rlang::args_dots_empty | ||
#' @param type Factor (or coercible to factor). The type of object being | ||
#' defined. Currently must be one of "string", "number", "integer", "boolean", | ||
#' "array", or "object". | ||
#' @param nullable Logical scalar (default `FALSE`). Whether the parameter can | ||
#' be set to `NULL`. | ||
#' @param description Character scalar (optional). A description of the object | ||
#' defined by the schema. | ||
#' @param format Character scalar (optional). The format of the object. | ||
#' Essentially a sub-type. | ||
#' | ||
#' @return A `schema` S7 object describing the data type, with fields `type`, | ||
#' `nullable`, `description`, and `format`. | ||
#' @export | ||
#' | ||
#' @seealso [as_schema()] for coercing objects to `schema`. | ||
#' | ||
#' @examples | ||
#' class_schema("string") | ||
#' class_schema("string", nullable = TRUE, description = "A nullable string.") | ||
class_schema <- S7::new_class( | ||
name = "schema", | ||
package = "rapid", | ||
properties = list( | ||
type = factor_property( | ||
"type", | ||
c("string", "number", "integer", "boolean", "array", "object"), | ||
max_size = 1 | ||
), | ||
nullable = logical_scalar_property("nullable"), | ||
description = character_scalar_property("description"), | ||
format = character_scalar_property("format") | ||
), | ||
constructor = function(type = c( | ||
"string", "number", "integer", | ||
"boolean", "array", "object" | ||
), | ||
..., | ||
nullable = FALSE, | ||
description = character(), | ||
format = character()) { | ||
check_dots_empty() | ||
if (missing(type)) { | ||
type <- character() | ||
nullable <- logical() | ||
} | ||
S7::new_object( | ||
S7::S7_object(), | ||
type = type, | ||
nullable = nullable, | ||
description = description, | ||
format = format | ||
) | ||
}, | ||
validator = function(self) { | ||
validate_parallel( | ||
self, | ||
"type", | ||
required = "nullable", | ||
optional = c("description", "format") | ||
) | ||
} | ||
) | ||
|
||
S7::method(length, class_schema) <- function(x) { | ||
length(x@type) | ||
} | ||
|
||
#' Coerce lists to schemas | ||
#' | ||
#' `as_schema()` turns an existing object into a `schema`. This is in contrast | ||
#' with [class_schema()], which builds a `schema` from individual properties. | ||
#' | ||
#' @inheritParams rlang::args_dots_empty | ||
#' @inheritParams rlang::args_error_context | ||
#' @param x The object to coerce. Must be empty or have names "type", | ||
#' "nullable", "description", and/or "format", or names that can be coerced to | ||
#' those names via [snakecase::to_snake_case()]. Extra names are ignored. This | ||
#' object should describe a single schema. | ||
#' | ||
#' @return A `schema` as returned by [class_schema()]. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' as_schema() | ||
#' as_schema( | ||
#' list( | ||
#' type = "string", | ||
#' format = "date-time", | ||
#' description = "Timestamp when the event will occur." | ||
#' ) | ||
#' ) | ||
as_schema <- function(x, ..., arg = caller_arg(x), call = caller_env()) { | ||
as_api_object(x, class_schema, ..., arg = arg, call = call) | ||
} |
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
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
Oops, something went wrong.