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

AllOfSelect

allOf operator

AnyOfSelect

anyOf operator

NotSelect

not operator

OApi

OpenApi document

OApiComponents

The OpenApi components

OApiContact

The OpenApi contact object

OApiDocument

The OpenApi document root object

OApiEncoding

The OpenApi encoding object

OApiExample

The OpenApi example object

OApiExternalDocumentation

The OpenApi external documentation object

OApiHeader

The OpenApi header object

OApiInfo

The OpenApi document information object

OApiLicense

The OpenApi license object

OApiLink

The OpenApi link object

OApiMediaType

The OpenApi media type object

OApiOAuthFlow

The OAuth flows

OApiOAuthFlowAuthorizationCode

The OAuth Authorization Code Flow parameters

OApiOAuthFlowClientCredentials

The OAuth Client Credentials Flow parameters

OApiOAuthFlowImplicit

The OAuth Implicit Flow parameters

OApiOAuthFlowPassword

The OAuth Password Flow parameters

OApiOperation

The OpenApi operation object

OApiParameter

The OpenApi parameter object

OApiPathItem

The OpenApi path items

OApiRequestBody

The OpenApi request body object

OApiResponse

The OpenApi response object

OApiSchemaArray

An array object in a schema

OApiSchemaDiscriminator

An object to switch between multiple schemas depending on a field value

OApiSchemaNumeric

A numeric object in a schema

OApiSchemaObject

An object in a schema

OApiSchemaString

An string in a schema

OApiSchemaXml

The OpenApi xml object

OApiSecuritySchemeApiKey

Parameter for Api Key security scheme

OApiSecuritySchemeHttp

Parameter for HTTP security scheme

OApiSecuritySchemeOauth2

Parameter for OAuth2 security scheme

OApiSecuritySchemeOpenIdConnect

Parameter for OIDC security scheme

OApiServer

The OpenApi server object

OApiServerVariable

The OpenApi server variables

OApiTag

The OpenApi tag object

OneOfSelect

oneOf operator

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