Modules
modelThe canonical model, apart from schemas (`crate::schema`): what a document describes, the same whichever OpenAPI version it was written in.readerReaders: one decoded document of one OpenAPI version into a `Specification`.referenceFollowing `$ref` references inside one document.schemaThe canonical schema tree.shapeShape 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.specification`Specification`: the canonical model of a document.version`Version`: the OpenAPI versions this library reads.
Contents
Functions
decodeUndocumented.decode_documentDecodes a JSON document (`decode`) whose root must be an object.parseReads a JSON document. With `version`, the document must declare that version (`Error::InvalidSpecification` otherwise).parse_documentReads an already decoded document: an array whose root is an object (objects inside may be arrays or `stdClass`).use utopia_openapi::Error;Rust
pub enum ErrorWhy a document could not be read.
use utopia_openapi::decode;Rust
pub fn decode(json: &[u8]) -> Result<Value, Error>Undocumented.
Rust
use utopia_openapi::{Value, decode};
assert!(matches!(decode(br#"{"a": 1}"#)?, Value::Array(_)));
assert_eq!(decode(b"{").unwrap_err().to_string(), "Invalid JSON: Syntax error");use utopia_openapi::decode_document;Rust
pub fn decode_document(json: &[u8]) -> Result<Array, Error>Decodes a JSON document (decode) whose root must be an object.
use utopia_openapi::parse;Rust
pub fn parse(json: impl AsRef<[u8]>, version: Option<Version>) -> Result<Specification, Error>Reads a JSON document. With version, the document must declare that
version (Error::InvalidSpecification otherwise).
Rust
use utopia_openapi::{Version, parse};
let json = br#"{"openapi": "3.0.0", "info": {"title": "x", "version": "1"}, "paths": {}}"#;
assert_eq!(parse(json, Some(Version::V3_0))?.source_version, "3.0.0");
let error = parse(json, Some(Version::V3_1)).unwrap_err();
assert_eq!(error.to_string(), "Expected OpenAPI 3.1, document declares 3.0.0");use utopia_openapi::parse_document;Rust
pub fn parse_document(document: &Array, version: Option<Version>) -> Result<Specification, Error>Reads an already decoded document: an array whose root is an object
(objects inside may be arrays or stdClass).