#[non_exhaustive]pub struct OpenApi {
pub openapi: OpenApiVersion,
pub info: Info,
pub servers: BTreeSet<Server>,
pub paths: Paths,
pub webhooks: PathMap<String, RefOr<PathItem>>,
pub components: Components,
pub security: BTreeSet<SecurityRequirement>,
pub tags: BTreeSet<Tag>,
pub external_docs: Option<ExternalDocs>,
pub json_schema_dialect: String,
pub extensions: PropMap<String, Value>,
}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: OpenApiVersionOpenAPI document version.
info: InfoProvides 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: PathsAvailable paths and operations for the API.
See more details at https://spec.openapis.org/oas/latest.html#paths-object.
webhooks: PathMap<String, RefOr<PathItem>>Incoming webhooks that may be received as part of this API.
Each value is a PathItem (or a Ref to one) keyed by a unique name. Added in
OpenAPI 3.1.
See more details at https://spec.openapis.org/oas/v3.1.0#openapi-object.
components: ComponentsHolds 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.
json_schema_dialect: StringThe default value for the $schema keyword within Schema Objects contained in this
document. It defaults to <https://spec.openapis.org/oas/3.1/dialect/base> and, when
set, must be a URI.
See https://spec.openapis.org/oas/v3.1.0#openapi-object for details.
extensions: PropMap<String, Value>Optional extensions “x-something”.
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_norway::to_string method.
Sourcepub fn merge(self, other: Self) -> Self
pub fn merge(self, other: Self) -> Self
Merge other OpenApi consuming it and resuming its content.
Merge function will take all self nonexistent servers, paths, webhooks,
schemas, responses, security_schemes, security_requirements and tags from
other OpenApi.
This function performs a shallow comparison for paths, webhooks, schemas,
responses and security schemes which means that only name and path is used
for comparison. When a match occurs the existing item will be overwritten.
For servers, tags and security_requirements the whole item will be used for
comparison.
Note! info, openapi, external_docs and json_schema_dialect will not be merged.
Sourcepub fn nest<P: Into<String>>(self, path: P, other: Self) -> Self
pub fn nest<P: Into<String>>(self, path: P, other: Self) -> Self
Nest another OpenApi document under the given path prefix.
All paths from other will be prefixed with path and then merged into self.
Components, security, tags, and servers are merged as in OpenApi::merge.
§Examples
let api = OpenApi::new("My Api", "1.0.0");
let user_api = OpenApi::new("User Api", "1.0.0");
let nested = api.nest("/api/v1", user_api);Sourcepub fn nest_with_path_composer<P: Into<String>, F: Fn(&str, &str) -> String>(
self,
path: P,
other: Self,
composer: F,
) -> Self
pub fn nest_with_path_composer<P: Into<String>, F: Fn(&str, &str) -> String>( self, path: P, other: Self, composer: F, ) -> Self
Nest another OpenApi document with a custom path composer.
In most cases you should use OpenApi::nest instead.
Only use this method if you need custom path composition for a specific use case.
composer is a function that takes two strings, the base path and the path to nest,
and returns the composed path for the API Specification.
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 Servers 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 webhooks<I, K, V>(self, webhooks: I) -> Self
pub fn webhooks<I, K, V>(self, webhooks: I) -> Self
Replace the incoming webhooks map and return Self.
Webhooks were added in OpenAPI 3.1. See OpenApi::webhooks.
Sourcepub fn add_webhook<K: Into<String>, V: Into<RefOr<PathItem>>>(
self,
name: K,
webhook: V,
) -> Self
pub fn add_webhook<K: Into<String>, V: Into<RefOr<PathItem>>>( self, name: K, webhook: V, ) -> 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 SecurityRequirements 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 SecurityRequirements. 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 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.
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 Tags 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.
Sourcepub fn json_schema_dialect<S: Into<String>>(self, dialect: S) -> Self
pub fn json_schema_dialect<S: Into<String>>(self, dialect: S) -> Self
Override the default JSON Schema dialect for this OpenAPI document.
Sets the jsonSchemaDialect top-level field, which provides the default
$schema value used by Schema Objects contained in this document.
§Examples
Override default schema dialect.
let _ = OpenApi::new("openapi", "0.1.0")
.json_schema_dialect("http://json-schema.org/draft-07/schema#");Sourcepub fn add_extension<K: Into<String>>(self, key: K, value: Value) -> Self
pub fn add_extension<K: Into<String>>(self, key: K, value: Value) -> Self
Add openapi extension (x-something) for OpenApi.
Sourcepub fn into_router(self, path: impl Into<String>) -> Router
pub fn into_router(self, path: impl Into<String>) -> Router
Sourcepub fn merge_router(self, router: &Router) -> Self
pub fn merge_router(self, router: &Router) -> Self
Trait Implementations§
Source§impl<'de> Deserialize<'de> for OpenApi
impl<'de> Deserialize<'de> for OpenApi
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Handler for OpenApi
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,
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,
Source§fn arc(self) -> ArcHandlerwhere
Self: Sized,
fn arc(self) -> ArcHandlerwhere
Self: Sized,
ArcHandler.Source§fn hooped(self) -> HoopedHandlerwhere
Self: Sized,
fn hooped(self) -> HoopedHandlerwhere
Self: Sized,
HoopedHandler.