#[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>,
pub schema: String,
pub extensions: Option<Extensions>,
}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::builder 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: 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: PathsAvailable 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.
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.
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 individual files could use their own schema dialect.
extensions: Option<Extensions>Optional extensions “x-something”.
Implementations§
Source§impl OpenApi
impl OpenApi
Sourcepub fn builder() -> OpenApiBuilder
pub fn builder() -> OpenApiBuilder
Create an instance of OpenApi using the builder syntax
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_from(self, other: OpenApi) -> OpenApi
pub fn merge_from(self, other: OpenApi) -> OpenApi
Merge other OpenApi moving self and returning combined OpenApi.
In functionality wise this is exactly same as calling OpenApi::merge but but provides
leaner API for chaining method calls.
Sourcepub fn merge(&mut self, other: OpenApi)
pub fn merge(&mut self, other: 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 whole item will be ignored from merged results. Only items not
found will be appended to self.
For servers, tags and security_requirements the whole item will be used for
comparison. Items not found from self will be appended to self.
Note! info, openapi, external_docs and schema will not be merged.
Sourcepub fn nest<P: Into<String>, O: Into<OpenApi>>(self, path: P, other: O) -> Self
pub fn nest<P: Into<String>, O: Into<OpenApi>>(self, path: P, other: O) -> Self
Nest other OpenApi to this OpenApi.
Nesting performs custom OpenApi::merge where other OpenApi paths are prepended with given
path and then appended to paths of this OpenApi instance. Rest of the other
OpenApi instance is merged to this OpenApi with OpenApi::merge_from method.
If multiple APIs are being nested with same path only the last one will be retained.
Method accepts two arguments, first is the path to prepend .e.g. /user. Second argument
is the OpenApi to prepend paths for.
§Examples
Merge user_api to api nesting user_api paths under /api/v1/user
let api = OpenApi::builder()
.paths(
Paths::builder().path(
"/api/v1/status",
PathItem::new(
HttpMethod::Get,
Operation::builder()
.description("Get status")
.build(),
),
),
)
.build();
let user_api = OpenApi::builder()
.paths(
Paths::builder().path(
"/",
PathItem::new(HttpMethod::Post, Operation::builder().build()),
)
)
.build();
let nested = api.nest("/api/v1/user", user_api);Sourcepub fn nest_with_path_composer<P: Into<String>, O: Into<OpenApi>, F: Fn(&str, &str) -> String>(
self,
path: P,
other: O,
composer: F,
) -> Self
pub fn nest_with_path_composer<P: Into<String>, O: Into<OpenApi>, F: Fn(&str, &str) -> String>( self, path: P, other: O, composer: F, ) -> Self
Nest other OpenApi with 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.