Expand description
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.
§Example
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)
}§Map Order Preservation
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.
§Crate Features
preserve-order: Enabled by default. Enablesserde_json’spreserve_orderfeature so JSON object order is preserved insideserde_json::Valuevalues, including nested specification extension objects. Disabling default features opts out of thisserde_jsonfeature; typed OpenAPI maps still useMap, but arbitrary nested JSON objects in extension values may useserde_json’s default object ordering.yaml-spec: Enables YAML parsing and serialization withyaml_serde.
Re-exports§
Modules§
- map
- Order-preserving key-value map.
- spec
- Structures used in parsing and navigating OpenAPI specifications.
Functions§
- from_
json - Deserializes an OpenAPI spec (JSON-format) from a string.
- from_
yaml yaml-spec - Deserializes an OpenAPI spec (YAML-format) from a string.
- to_json
- Serializes OpenAPI spec to a JSON string.
- to_yaml
yaml-spec - Serializes OpenAPI spec to a YAML string.
Type Aliases§
- Open
ApiV3 Spec - Version 3.1.x of the OpenAPI specification.