shape
ModuleShape checks on a decoded document: is this value an object, a list, a
string? Every failure is an Error::InvalidSpecification naming the
JSON Pointer location that was being read, so it can be traced back into
the source.
Contents
Functions
extensionsUndocumented.listThe value as a list: an array whose keys are `0, 1, 2, ...`.nullable_intAn integer, or `None` for `null`; a float is an error.nullable_numberAn integer or a float, or `None` for `null`.objectThe value as an object: a non-list array (an empty array is both an object and a list), or a `stdClass` cast to an array.optional_stringThe string at `key`, or `None` when it is missing or `null`.required_stringThe string at `key`, which must be present.string_listThe value as a list of strings; the error names the first item that is not.use utopia_openapi::shape::extensions;Rust
pub fn extensions(data: &Array) -> ArrayUndocumented.
Rust
use utopia_openapi::{Array, Value, shape};
let mut data = Array::new();
data.set("title".into(), Value::from("Pets"));
data.set("X-Trace".into(), Value::Bool(true));
let extensions = shape::extensions(&data);
assert_eq!(extensions.len(), 1);
assert_eq!(extensions.get_str("X-Trace"), Some(&Value::Bool(true)));use utopia_openapi::shape::list;Rust
pub fn list<'v>(value: &'v Value, location: &str) -> Result<&'v Array, Error>The value as a list: an array whose keys are 0, 1, 2, ....
use utopia_openapi::shape::nullable_int;Rust
pub fn nullable_int(value: &Value, location: &str) -> Result<Option<i64>, Error>An integer, or None for null; a float is an error.
use utopia_openapi::shape::nullable_number;Rust
pub fn nullable_number(value: &Value, location: &str) -> Result<Option<Number>, Error>An integer or a float, or None for null.
use utopia_openapi::shape::object;Rust
pub fn object<'v>(value: &'v Value, location: &str) -> Result<Cow<'v, Array>, Error>The value as an object: a non-list array (an empty array is both an
object and a list), or a stdClass cast to an array.
Rust
use utopia_openapi::shape;
use utopia_openapi::{Array, Value};
let empty = Value::Array(Array::new());
assert!(shape::object(&empty, "#/x").unwrap().is_empty());
let list = Value::Array(Array::from_list(vec![Value::Int(1)]));
let error = shape::object(&list, "#/paths").unwrap_err();
assert_eq!(error.to_string(), "Expected an object at #/paths");use utopia_openapi::shape::optional_string;Rust
pub fn optional_string<'v>(data: &'v Array, key: &str) -> Result<Option<&'v Str>, Error>The string at key, or None when it is missing or null.
use utopia_openapi::shape::required_string;Rust
pub fn required_string<'v>(data: &'v Array, key: &str, location: &str) -> Result<&'v Str, Error>The string at key, which must be present.
Rust
use utopia_openapi::{Array, Value, shape};
let error = shape::required_string(&Array::new(), "title", "#/info").unwrap_err();
assert_eq!(error.to_string(), "Expected string #/info/title");use utopia_openapi::shape::string_list;Rust
pub fn string_list<'v>(value: &'v Value, location: &str) -> Result<&'v Array, Error>The value as a list of strings; the error names the first item that is not.