Struct salvo_oapi::OpenApi

source ·
#[non_exhaustive]
pub struct OpenApi { pub openapi: OpenApiVersion, pub info: Info, pub servers: BTreeSet<Server>, pub paths: Paths, pub components: Components, pub security: BTreeSet<SecurityRequirement>, pub tags: BTreeSet<Tag>, pub external_docs: Option<ExternalDocs>, }
Expand description

Root object of the OpenAPI document.

You can use OpenApi::new function to construct a new OpenApi instance and then use the fields with mutable access to modify them. This is quite tedious if you are not simply just changing one thing thus you can also use the OpenApi::new to use builder to construct a new OpenApi object.

See more details at https://spec.openapis.org/oas/latest.html#openapi-object.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§openapi: OpenApiVersion

OpenAPI document version.

§info: Info

Provides metadata about the API.

See more details at https://spec.openapis.org/oas/latest.html#info-object.

§servers: BTreeSet<Server>

List of servers that provides the connectivity information to target servers.

This is implicitly one server with url set to /.

See more details at https://spec.openapis.org/oas/latest.html#server-object.

§paths: Paths

Available paths and operations for the API.

See more details at https://spec.openapis.org/oas/latest.html#paths-object.

§components: Components

Holds various reusable schemas for the OpenAPI document.

Few of these elements are security schemas and object schemas.

See more details at https://spec.openapis.org/oas/latest.html#components-object.

§security: BTreeSet<SecurityRequirement>

Declaration of global security mechanisms that can be used across the API. The individual operations can override the declarations. You can use SecurityRequirement::default() if you wish to make security optional by adding it to the list of securities.

See more details at https://spec.openapis.org/oas/latest.html#security-requirement-object.

§tags: BTreeSet<Tag>

List of tags can be used to add additional documentation to matching tags of operations.

See more details at https://spec.openapis.org/oas/latest.html#tag-object.

§external_docs: Option<ExternalDocs>

Global additional documentation reference.

See more details at https://spec.openapis.org/oas/latest.html#external-documentation-object.

Implementations§

source§

impl OpenApi

source

pub fn new(title: impl Into<String>, version: impl Into<String>) -> Self

Construct a new OpenApi object.

§Examples
let openapi = OpenApi::new("pet api", "0.1.0");
source

pub fn with_info(info: Info) -> Self

Construct a new OpenApi object.

Function accepts Info metadata of the API;

§Examples
let openapi = OpenApi::new("pet api", "0.1.0");
source

pub fn to_json(&self) -> Result<String, Error>

Converts this OpenApi to JSON String. This method essentially calls serde_json::to_string method.

source

pub fn to_pretty_json(&self) -> Result<String, Error>

Converts this OpenApi to pretty JSON String. This method essentially calls serde_json::to_string_pretty method.

source

pub fn to_yaml(&self) -> Result<String, Error>

Available on crate feature yaml only.

Converts this OpenApi to YAML String. This method essentially calls serde_yaml::to_string method.

source

pub fn merge(self, other: OpenApi) -> Self

Merge other OpenApi consuming it and resuming it’s content.

Merge function will take all self nonexistent servers, paths, schemas, responses, security_schemes, security_requirements and tags from other OpenApi.

This function performs a shallow comparison for paths, schemas, responses and security schemes which means that only name and path is used for comparison. When match occurs the exists item will be overwrite.

For servers, tags and security_requirements the whole item will be used for comparison.

Note! info, openapi and external_docs will not be merged.

source

pub fn info<I: Into<Info>>(self, info: I) -> Self

Add Info metadata of the API.

source

pub fn servers<S: IntoIterator<Item = Server>>(self, servers: S) -> Self

Add iterator of Servers to configure target servers.

source

pub fn add_server<S>(self, server: S) -> Self
where S: Into<Server>,

Add Server to configure operations and endpoints of the API and returns Self.

source

pub fn paths<P: Into<Paths>>(self, paths: P) -> Self

Set paths to configure operations and endpoints of the API.

source

pub fn add_path<P, I>(self, path: P, item: I) -> Self
where P: Into<String>, I: Into<PathItem>,

Add PathItem to configure operations and endpoints of the API and returns Self.

source

pub fn components(self, components: impl Into<Components>) -> Self

Add Components to configure reusable schemas.

source

pub fn security<S: IntoIterator<Item = SecurityRequirement>>( self, security: S, ) -> Self

Add iterator of SecurityRequirements that are globally available for all operations.

source

pub fn add_security_scheme<N: Into<String>, S: Into<SecurityScheme>>( self, name: N, security_scheme: S, ) -> Self

Add SecurityScheme to Components and returns Self.

Accepts two arguments where first is the name of the SecurityScheme. This is later when referenced by SecurityRequirements. Second parameter is the SecurityScheme.

source

pub fn extend_security_schemes<I: IntoIterator<Item = (N, S)>, N: Into<String>, S: Into<SecurityScheme>>( self, schemas: I, ) -> Self

Add iterator of SecuritySchemes to Components.

Accepts two arguments where first is the name of the SecurityScheme. This is later when referenced by SecurityRequirements. Second parameter is the SecurityScheme.

source

pub fn add_schema<S: Into<String>, I: Into<RefOr<Schema>>>( self, name: S, schema: I, ) -> Self

Add Schema to Components and returns Self.

Accepts two arguments where first is name of the schema and second is the schema itself.

source

pub fn extend_schemas<I, C, S>(self, schemas: I) -> Self
where I: IntoIterator<Item = (S, C)>, C: Into<RefOr<Schema>>, S: Into<String>,

Add Schemas from iterator.

§Examples
OpenApi::new("api", "0.0.1").extend_schemas([(
    "Pet",
    Schema::from(
        Object::new()
            .property(
                "name",
                Object::new().schema_type(SchemaType::String),
            )
            .required("name")
    ),
)]);
source

pub fn response<S: Into<String>, R: Into<RefOr<Response>>>( self, name: S, response: R, ) -> Self

Add a new response and returns self.

source

pub fn extend_responses<I: IntoIterator<Item = (S, R)>, S: Into<String>, R: Into<RefOr<Response>>>( self, responses: I, ) -> Self

Extends responses with the contents of an iterator.

source

pub fn tags<I, T>(self, tags: I) -> Self
where I: IntoIterator<Item = T>, T: Into<Tag>,

Add iterator of Tags to add additional documentation for operations tags.

source

pub fn external_docs(self, external_docs: ExternalDocs) -> Self

Add ExternalDocs for referring additional documentation.

source

pub fn into_router(self, path: impl Into<String>) -> Router

Consusmes the OpenApi and returns Router with the OpenApi as handler.

source

pub fn merge_router(self, router: &Router) -> Self

Consusmes the OpenApi and informations from a Router.

source

pub fn merge_router_with_base( self, router: &Router, base: impl AsRef<str>, ) -> Self

Consusmes the OpenApi and informations from a Router with base path.

Trait Implementations§

source§

impl Clone for OpenApi

source§

fn clone(&self) -> OpenApi

Returns a copy 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 OpenApi

source§

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

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

impl Default for OpenApi

source§

fn default() -> OpenApi

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for OpenApi

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 Handler for OpenApi

source§

fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, req: &'life1 mut Request, _depot: &'life2 mut Depot, res: &'life3 mut Response, _ctrl: &'life4 mut FlowCtrl, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Handle http request.
source§

impl PartialEq for OpenApi

source§

fn eq(&self, other: &OpenApi) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for OpenApi

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
source§

impl StructuralPartialEq for OpenApi

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> SendTarget for T
where T: Handler + Send,

source§

async fn call(self, req: Request) -> Response

Send request to target, such as Router, Service, Handler.
source§

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

§

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>,

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

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