Crate oapi[−][src]
Simple parsing
A library to easily parse an OpenApi Document according to specifications. It allows for distant references and support the OpenApi operators.
For example, parsing a file in your code might you like the following :
extern crate oapi; extern crate sppparse; use oapi::OApi; use sppparse::SparseRoot; use std::path::PathBuf; fn main() { let doc: OApi = OApi::new( SparseRoot::new_from_file(PathBuf::from(concat!( env!("CARGO_MANIFEST_DIR"), "/tests/documents/test_docs/openapi.yml" ))) .expect("to parse the openapi"), ); doc.check().expect("not to have logic errors"); println!("{:#?}", doc); }
Extension support
You can use extension of the OpenApi Document, as specified in the specifications.
For example, parsing a file with extension in your code might you like the following :
extern crate oapi; extern crate sppparse; use oapi::{OApi, OApiExtensionExtractor}; use sppparse::SparseRoot; use std::path::PathBuf; use serde::{Serialize, Deserialize}; use sppparse::Sparsable; use oapi_derive::OApiCheckInner; #[derive(Debug, PartialEq, Serialize, Deserialize, Sparsable, OApiCheckInner)] #[serde(rename_all = "camelCase")] pub struct OApiDummyExt { first_name: String, last_name: String, } fn main() { let doc: OApi = OApi::new( SparseRoot::new_from_file(PathBuf::from(concat!( env!("CARGO_MANIFEST_DIR"), "/tests/documents/test_docs/extensions.yml" ))) .expect("to parse the openapi"), ); doc.check().expect("not to have logic errors"); let ext: OApiDummyExt = doc .root_get() .unwrap() .oapi_extract_ext(doc.doc(), "x-toto") .unwrap(); println!("{:#?}", ext); }
Structs
Enums
OApiApiKeyLocation | The possible location of an api key |
OApiError | An error throwable by OApi |
OApiExampleSelector | A selector between a single example or multiple examples |
OApiNumericFormat | The numeric format authorized by the OAPI specs |
OApiNumericMaximum | A selector between the inclusive or exclusive way to express upper numeric bound |
OApiNumericMinimum | A selector between the inclusive or exclusive way to express lower numeric bound |
OApiParameterLocation | Location possible for parameters |
OApiParameterStyle | Style possible for parameters |
OApiSchema | An OpenApi schema |
OApiSchemaAdditionalItem | A selector for additional items |
OApiSecurityScheme | The OpenApi security scheme object |
OApiStringFormat | The string format authorized by the OAPI specs |
OperatorSelector | A selector between operator or value |
Traits
OApiCheckTrait | Check trait for OApi |
OApiExtensionExtractor | Extension extractor trait |
OApiOperator | OApi Operator trait |
Type Definitions
OApiCallback | The OpenApi callback object |
Derive Macros
OApiCheck | Derive for OApiCheckTrait |