#openapi #extension #utilities #data #openapi-v3 #methods #information

openapi_utils

Extension method and utilities to work with OpenAPI 3.0 files

14 releases

0.6.1 Aug 2, 2024
0.6.0 Feb 24, 2024
0.5.2 Nov 17, 2023
0.4.0 Feb 5, 2022
0.1.1 Dec 12, 2019

#645 in Parser implementations

Download history 70/week @ 2024-07-19 79/week @ 2024-07-26 180/week @ 2024-08-02 47/week @ 2024-08-09 37/week @ 2024-08-16 72/week @ 2024-08-23 69/week @ 2024-08-30 54/week @ 2024-09-06 75/week @ 2024-09-13 98/week @ 2024-09-20 62/week @ 2024-09-27 43/week @ 2024-10-04 62/week @ 2024-10-11 78/week @ 2024-10-18 15/week @ 2024-10-25 31/week @ 2024-11-01

195 downloads per month
Used in openapi-fuzzer

MIT/Apache

26KB
509 lines

Openapi Utils

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.

Usage

This crate provides a deref_all method on the openapiv3::OpenAPI data type. This method would inline all the $ref in the document.

Example

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.

no_std support

This crate is compatible with no_std, although a global allocator is required.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.4–3.5MB
~63K SLoC