OpenAPIV3

Struct OpenAPIV3 

Source
pub struct OpenAPIV3 {
    pub openapi: String,
    pub info: Info,
    pub servers: Option<Vec<Server>>,
    pub paths: BTreeMap<String, PathItem>,
    pub components: Option<Components>,
    pub security: Option<Vec<SecurityRequirement>>,
    pub tags: Option<Vec<Tag>>,
    pub external_docs: Option<ExternalDocumentation>,
    pub extras: Option<BTreeMap<String, Any>>,
}
Expand description

The root document object of an OpenAPI v3.0 specification.

This is the main entry point for an OpenAPI specification document. It contains metadata about the API, server information, available paths and operations, reusable components, security requirements, and additional documentation.

§Examples

use oas::{OpenAPIV3, Info, Server, PathItem, builders};

let spec = OpenAPIV3::new(Info::new("My API", "1.0.0"))
    .with_description("A sample API")
    .add_server(Server::new("https://api.example.com"))
    .add_path("/users", PathItem::new()
        .with_get(builders::get("List users").build()));

Fields§

§openapi: String

The semantic version number of the OpenAPI Specification version.

This MUST be the semantic version number of the OpenAPI Specification version that the OpenAPI document uses. This is not related to the API info.version string. Defaults to “3.0.0” when using OpenAPIV3::new().

§info: Info

Provides metadata about the API.

The metadata MAY be used by the clients if needed, and MAY be presented in editing or documentation generation tools for convenience.

§servers: Option<Vec<Server>>

An array of Server Objects providing connectivity information to target servers.

If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of /.

§paths: BTreeMap<String, PathItem>

The available paths and operations for the API.

This is a map where keys are path templates (like /users/{id}) and values are PathItem objects describing the operations available on those paths.

§components: Option<Components>

An element to hold various schemas for the specification.

All objects defined within the components object will have no effect on the API unless they are explicitly referenced from properties outside the components object.

§security: Option<Vec<SecurityRequirement>>

A declaration of which security mechanisms can be used across the API.

The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition.

§tags: Option<Vec<Tag>>

A list of tags used by the specification with additional metadata.

The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the Operation Object must be declared. Each tag name in the list MUST be unique.

§external_docs: Option<ExternalDocumentation>

Additional external documentation for the API.

§extras: Option<BTreeMap<String, Any>>

Extension fields that start with x-.

This allows for custom extensions to the OpenAPI specification.

Implementations§

Source§

impl OpenAPIV3

Source

pub fn new(info: Info) -> Self

Source

pub fn with_description(self, description: impl Into<String>) -> Self

Source

pub fn with_paths(self, paths: BTreeMap<String, PathItem>) -> Self

Source

pub fn with_components(self, components: Components) -> Self

Source

pub fn with_servers(self, servers: Vec<Server>) -> Self

Source§

impl OpenAPIV3

Source

pub fn add_path(self, path: impl Into<String>, path_item: PathItem) -> Self

Add a single path

Source

pub fn add_paths(self, paths: Vec<(impl Into<String>, PathItem)>) -> Self

Add multiple paths at once

Source

pub fn add_server(self, server: Server) -> Self

Add a single server

Source

pub fn add_tag(self, tag: Tag) -> Self

Add a tag

Source§

impl OpenAPIV3

Source

pub fn to_string(&self) -> String

Source

pub fn to_value(&self) -> Value

Trait Implementations§

Source§

impl Clone for OpenAPIV3

Source§

fn clone(&self) -> OpenAPIV3

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenAPIV3

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OpenAPIV3

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for OpenAPIV3

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,