Rust

Crate root

Module
What utopia_openapi defines at its root.

Modules

Contents

use utopia_openapi::Error;
Rust
pub enum Error

Why 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).