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
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.
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
impl OpenApi
sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Converts this OpenApi
to JSON String. This method essentially calls serde_json::to_string
method.
sourcepub fn to_pretty_json(&self) -> Result<String, Error>
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.
sourcepub fn to_yaml(&self) -> Result<String, Error>
Available on crate feature yaml
only.
pub fn to_yaml(&self) -> Result<String, Error>
yaml
only.Converts this OpenApi
to YAML String. This method essentially calls serde_yaml::to_string
method.
sourcepub fn merge(self, other: OpenApi) -> Self
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.
sourcepub fn servers<S: IntoIterator<Item = Server>>(self, servers: S) -> Self
pub fn servers<S: IntoIterator<Item = Server>>(self, servers: S) -> Self
Add iterator of Server
s to configure target servers.
sourcepub fn add_server<S>(self, server: S) -> Self
pub fn add_server<S>(self, server: S) -> Self
Add Server
to configure operations and endpoints of the API and returns Self
.
sourcepub fn paths<P: Into<Paths>>(self, paths: P) -> Self
pub fn paths<P: Into<Paths>>(self, paths: P) -> Self
Set paths to configure operations and endpoints of the API.
sourcepub fn add_path<P, I>(self, path: P, item: I) -> Self
pub fn add_path<P, I>(self, path: P, item: I) -> Self
Add PathItem
to configure operations and endpoints of the API and returns Self
.
sourcepub fn components(self, components: impl Into<Components>) -> Self
pub fn components(self, components: impl Into<Components>) -> Self
Add Components
to configure reusable schemas.
sourcepub fn security<S: IntoIterator<Item = SecurityRequirement>>(
self,
security: S,
) -> Self
pub fn security<S: IntoIterator<Item = SecurityRequirement>>( self, security: S, ) -> Self
Add iterator of SecurityRequirement
s that are globally available for all operations.
sourcepub fn add_security_scheme<N: Into<String>, S: Into<SecurityScheme>>(
self,
name: N,
security_scheme: S,
) -> Self
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 SecurityRequirement
s. Second parameter is the SecurityScheme
.
sourcepub fn extend_security_schemes<I: IntoIterator<Item = (N, S)>, N: Into<String>, S: Into<SecurityScheme>>(
self,
schemas: I,
) -> Self
pub fn extend_security_schemes<I: IntoIterator<Item = (N, S)>, N: Into<String>, S: Into<SecurityScheme>>( self, schemas: I, ) -> Self
Add iterator of SecurityScheme
s to Components
.
Accepts two arguments where first is the name of the SecurityScheme
. This is later when
referenced by SecurityRequirement
s. Second parameter is the SecurityScheme
.
sourcepub fn add_schema<S: Into<String>, I: Into<RefOr<Schema>>>(
self,
name: S,
schema: I,
) -> Self
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.
sourcepub fn extend_schemas<I, C, S>(self, schemas: I) -> Self
pub fn extend_schemas<I, C, S>(self, schemas: I) -> Self
sourcepub fn response<S: Into<String>, R: Into<RefOr<Response>>>(
self,
name: S,
response: R,
) -> Self
pub fn response<S: Into<String>, R: Into<RefOr<Response>>>( self, name: S, response: R, ) -> Self
Add a new response and returns self
.
sourcepub fn extend_responses<I: IntoIterator<Item = (S, R)>, S: Into<String>, R: Into<RefOr<Response>>>(
self,
responses: I,
) -> Self
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.
Add iterator of Tag
s to add additional documentation for operations tags.
sourcepub fn external_docs(self, external_docs: ExternalDocs) -> Self
pub fn external_docs(self, external_docs: ExternalDocs) -> Self
Add ExternalDocs
for referring additional documentation.