pub struct OpenApiBuilder { /* private fields */ }Expand description
Builder for OpenApi with chainable configuration methods to create a new OpenApi.
§Examples
Create OpenApi using OpenApiBuilder.
let openapi = OpenApiBuilder::new()
.info(Info::new("My api", "1.0.0"))
.paths(Paths::new())
.components(Some(
Components::new()
))
.build();Implementations§
Source§impl OpenApiBuilder
impl OpenApiBuilder
Sourcepub fn new() -> OpenApiBuilder
pub fn new() -> OpenApiBuilder
Constructs a new OpenApiBuilder.
Source§impl OpenApiBuilder
impl OpenApiBuilder
Sourcepub fn openapi(self, openapi: OpenApiVersion) -> Self
pub fn openapi(self, openapi: OpenApiVersion) -> Self
Set the OpenApiVersion the document serializes as.
Defaults to OpenApiVersion::Version31. Set OpenApiVersion::Version32 to opt in to
OpenAPI 3.2 output.
§Examples
Opt in to OpenAPI 3.2 output.
let openapi = OpenApiBuilder::new()
.openapi(OpenApiVersion::Version32)
.info(Info::new("my api", "0.1.0"))
.build();Sourcepub fn servers<I: IntoIterator<Item = Server>>(self, servers: Option<I>) -> Self
pub fn servers<I: IntoIterator<Item = Server>>(self, servers: Option<I>) -> Self
Add iterator of Servers to configure target servers.
Sourcepub fn paths<P: Into<Paths>>(self, paths: P) -> Self
pub fn paths<P: Into<Paths>>(self, paths: P) -> Self
Add Paths to configure operations and endpoints of the API.
Sourcepub fn webhooks<P: Into<Paths>>(self, webhooks: Option<P>) -> Self
pub fn webhooks<P: Into<Paths>>(self, webhooks: Option<P>) -> Self
Add Paths to describe incoming requests that may be initiated by the API provider.
§Examples
Describe a newPet webhook that the API provider may send to a subscriber.
let openapi = OpenApiBuilder::new()
.info(Info::new("Events API", "1.0.0"))
.paths(Paths::new())
.webhooks(Some(PathsBuilder::new().path(
"newPet",
PathItem::new(
HttpMethod::Post,
OperationBuilder::new().response("200", Response::new("Webhook received")),
),
)))
.build();Sourcepub fn components(self, components: Option<Components>) -> Self
pub fn components(self, components: Option<Components>) -> Self
Add Components to configure reusable schemas.
Sourcepub fn security<I: IntoIterator<Item = SecurityRequirement>>(
self,
security: Option<I>,
) -> Self
pub fn security<I: IntoIterator<Item = SecurityRequirement>>( self, security: Option<I>, ) -> Self
Add iterator of SecurityRequirements that are globally available for all operations.
Add iterator of Tags to add additional documentation for operations tags.
Sourcepub fn external_docs(self, external_docs: Option<ExternalDocs>) -> Self
pub fn external_docs(self, external_docs: Option<ExternalDocs>) -> Self
Add ExternalDocs for referring additional documentation.
Sourcepub fn schema<S: Into<String>>(self, schema: S) -> Self
pub fn schema<S: Into<String>>(self, schema: S) -> Self
Override default $schema dialect for the Open API doc.
§Examples
Override default schema dialect.
let _ = OpenApiBuilder::new()
.schema("http://json-schema.org/draft-07/schema#")
.build();