Structures and tools to parse, navigate and validate OpenAPI v3.1.x specifications.
Note that due to v3.1.x being a breaking change from v3.0.x, you may have trouble correctly parsing specs in the older format.
let yaml = std::fs::read_to_string("path/to/openapi.yml").unwrap();
match oas3::from_yaml(yaml) {
Ok(spec) => println!("spec: {:?}", spec),
Err(err) => println!("error: {}", err)
}OpenAPI maps are represented by [Map], an order-preserving map type. When a
document is deserialized, map entries keep the order they had in the input
document. When a spec is serialized again, those entries are emitted in that
stored order rather than being sorted by key.
This applies to typed OpenAPI maps, such as paths, component maps, schema
properties, media type maps, responses, callbacks, and specification
extensions. Nested JSON objects inside extension values also preserve order
when the default preserve-order feature is enabled.
If a deterministic key-sorted map is needed, convert a [Map] into a
[std::collections::BTreeMap].
preserve-order: Enabled by default. Enablesserde_json'spreserve_orderfeature so JSON object order is preserved inside [serde_json::Value] values, including nested specification extension objects. Disabling default features opts out of thisserde_jsonfeature; typed OpenAPI maps still use [Map], but arbitrary nested JSON objects in extension values may useserde_json's default object ordering.yaml-spec: Enables YAML parsing and serialization withyaml_serde.