Struct utoipa::openapi::OpenApi

source ·
#[non_exhaustive]
pub struct OpenApi { pub openapi: OpenApiVersion, pub info: Info, pub servers: Option<Vec<Server>>, pub paths: Paths, pub components: Option<Components>, pub security: Option<Vec<SecurityRequirement>>, pub tags: Option<Vec<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 OpenApiBuilder::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: Option<Vec<Server>>

Optional 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: Option<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: Option<Vec<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: Option<Vec<Tag>>

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

Optional global additional documentation reference.

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

Implementations

Construct a new OpenApi object.

Function accepts two arguments one which is Info metadata of the API; two which is Paths containing operations for the API.

Examples
let openapi = OpenApi::new(Info::new("pet api", "0.1.0"), Paths::new());

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


  1. json feature is needed. 

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


  1. json feature is needed. 

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.