#[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>,
pub schema: String,
pub extensions: BTreeMap<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.
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.
schema: StringSchema keyword can be used to override default $schema dialect which is by default
“https://spec.openapis.org/oas/3.1/dialect/base”.
All the references and invidual files could use their own schema dialect.
extensions: BTreeMap<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>
pub fn to_yaml(&self) -> Result<String, Error>
Converts this OpenApi to YAML String. This method essentially calls serde_norway::to_string method.
Sourcepub fn merge(self, other: OpenApi) -> OpenApi
pub fn merge(self, other: OpenApi) -> OpenApi
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 and schema will not be merged.
Sourcepub fn servers<S>(self, servers: S) -> OpenApiwhere
S: IntoIterator<Item = Server>,
pub fn servers<S>(self, servers: S) -> OpenApiwhere
S: IntoIterator<Item = Server>,
Add iterator of Servers to configure target servers.
Sourcepub fn add_server<S>(self, server: S) -> OpenApi
pub fn add_server<S>(self, server: S) -> OpenApi
Add Server to configure operations and endpoints of the API and returns Self.
Sourcepub fn paths<P>(self, paths: P) -> OpenApi
pub fn paths<P>(self, paths: P) -> OpenApi
Set paths to configure operations and endpoints of the API.
Sourcepub fn add_path<P, I>(self, path: P, item: I) -> OpenApi
pub fn add_path<P, I>(self, path: P, item: I) -> OpenApi
Add PathItem to configure operations and endpoints of the API and returns Self.
Sourcepub fn components(self, components: impl Into<Components>) -> OpenApi
pub fn components(self, components: impl Into<Components>) -> OpenApi
Add Components to configure reusable schemas.
Sourcepub fn security<S>(self, security: S) -> OpenApiwhere
S: IntoIterator<Item = SecurityRequirement>,
pub fn security<S>(self, security: S) -> OpenApiwhere
S: IntoIterator<Item = SecurityRequirement>,
Add iterator of SecurityRequirements that are globally available for all operations.
Sourcepub fn add_security_scheme<N, S>(self, name: N, security_scheme: S) -> OpenApi
pub fn add_security_scheme<N, S>(self, name: N, security_scheme: S) -> OpenApi
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, N, S>(self, schemas: I) -> OpenApi
pub fn extend_security_schemes<I, N, S>(self, schemas: I) -> OpenApi
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, I>(self, name: S, schema: I) -> OpenApi
pub fn add_schema<S, I>(self, name: S, schema: I) -> OpenApi
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) -> OpenApi
pub fn extend_schemas<I, C, S>(self, schemas: I) -> OpenApi
Sourcepub fn response<S, R>(self, name: S, response: R) -> OpenApi
pub fn response<S, R>(self, name: S, response: R) -> OpenApi
Add a new response and returns self.
Sourcepub fn extend_responses<I, S, R>(self, responses: I) -> OpenApi
pub fn extend_responses<I, S, R>(self, responses: I) -> OpenApi
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) -> OpenApi
pub fn external_docs(self, external_docs: ExternalDocs) -> OpenApi
Add ExternalDocs for referring additional documentation.
Sourcepub fn schema<S>(self, schema: S) -> OpenApi
pub fn schema<S>(self, schema: S) -> OpenApi
Override default $schema dialect for the Open API doc.
§Examples
Override default schema dialect.
let _ = OpenApi::new("openapi", "0.1.0").schema("http://json-schema.org/draft-07/schema#");Sourcepub fn add_extension<K>(self, key: K, value: Value) -> OpenApi
pub fn add_extension<K>(self, key: K, value: Value) -> OpenApi
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) -> OpenApi
pub fn merge_router(self, router: &Router) -> OpenApi
Trait Implementations§
Source§impl<'de> Deserialize<'de> for OpenApi
impl<'de> Deserialize<'de> for OpenApi
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<OpenApi, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<OpenApi, <__D as Deserializer<'de>>::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
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
OpenApi: '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
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
OpenApi: 'async_trait,
Source§fn arc(self) -> ArcHandlerwhere
Self: Sized,
fn arc(self) -> ArcHandlerwhere
Self: Sized,
ArcHandler.Source§fn hoop<H>(self, hoop: H) -> HoopedHandler
fn hoop<H>(self, hoop: H) -> HoopedHandler
Source§impl Serialize for OpenApi
impl Serialize for OpenApi
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for OpenApi
Auto Trait Implementations§
impl Freeze for OpenApi
impl RefUnwindSafe for OpenApi
impl Send for OpenApi
impl Sync for OpenApi
impl Unpin for OpenApi
impl UnwindSafe for OpenApi
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);