Crates.io | openapi_utils |
lib.rs | openapi_utils |
version | 0.6.1 |
source | src |
created_at | 2019-12-12 11:41:02.230389 |
updated_at | 2024-08-02 22:04:56.902033 |
description | Extension method and utilities to work with OpenAPI 3.0 files |
homepage | https://github.com/JordiPolo/oas_proxy/tree/master/openapi_utils |
repository | https://github.com/jordipolo/oas_proxy |
max_upload_size | |
id | 188781 |
size | 38,123 |
This crate provides extensions methods for multiple structs of the Openapiv3 crate.
It aims at making it more ergonomic to work with the information in the openapi contracts.
This crate provides a deref_all
method on the openapiv3::OpenAPI
data type. This method would inline all the $ref
in the document.
use openapi_utils::SpecExt;
pub fn read<P: AsRef<Path>>(filename: P) -> openapiv3::OpenAPI {
let data = std::fs::read_to_string(filename).expect("OpenAPI file could not be read.");
serde_yaml::from_str(&data).expect("Could not deserialize file as OpenAPI v3.0 yaml")
}
let spec = read(filename).deref_all();
The to_item
, to_item_ref
and to_item_mut
methods in the ReferenceOr structure assumes deref_all
has been called on the spec previously and will panic otherwise. These methods are really a shorthand to choose the right element in the enumeration (the item).
For other methods in other structures please refer to the documentation of each extension.
To have these methods available in your structures you need to use
the corresponding extension.
This crate is compatible with no_std, although a global allocator is required.