Skip to main content

Crate oas3

Crate oas3 

Source
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. Enables serde_json’s preserve_order feature so JSON object order is preserved inside serde_json::Value values, including nested specification extension objects. Disabling default features opts out of this serde_json feature; typed OpenAPI maps still use Map, but arbitrary nested JSON objects in extension values may use serde_json’s default object ordering.
  • yaml-spec: Enables YAML parsing and serialization with yaml_serde.

Re-exports§

pub use self::map::Map;
pub use self::spec::Spec;

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_yamlyaml-spec
Deserializes an OpenAPI spec (YAML-format) from a string.
to_json
Serializes OpenAPI spec to a JSON string.
to_yamlyaml-spec
Serializes OpenAPI spec to a YAML string.

Type Aliases§

OpenApiV3Spec
Version 3.1.x of the OpenAPI specification.