Skip to main content

OpenApiBuilder

Struct OpenApiBuilder 

Source
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

Source

pub fn new() -> OpenApiBuilder

Constructs a new OpenApiBuilder.

Source

pub fn build(self) -> OpenApi

Constructs a new OpenApi taking all fields values from this object.

Source§

impl OpenApiBuilder

Source

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();
Source

pub fn info<I: Into<Info>>(self, info: I) -> Self

Add Info metadata of the API.

Source

pub fn servers<I: IntoIterator<Item = Server>>(self, servers: Option<I>) -> Self

Add iterator of Servers to configure target servers.

Source

pub fn paths<P: Into<Paths>>(self, paths: P) -> Self

Add Paths to configure operations and endpoints of the API.

Source

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();
Source

pub fn components(self, components: Option<Components>) -> Self

Add Components to configure reusable schemas.

Source

pub fn security<I: IntoIterator<Item = SecurityRequirement>>( self, security: Option<I>, ) -> Self

Add iterator of SecurityRequirements that are globally available for all operations.

Source

pub fn tags<I: IntoIterator<Item = Tag>>(self, tags: Option<I>) -> Self

Add iterator of Tags to add additional documentation for operations tags.

Source

pub fn external_docs(self, external_docs: Option<ExternalDocs>) -> Self

Add ExternalDocs for referring additional documentation.

Source

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();
Source

pub fn json_schema_dialect<S: Into<String>>( self, json_schema_dialect: Option<S>, ) -> Self

Add or change the default JSON Schema dialect for Schema Objects.

§Examples
let _ = OpenApiBuilder::new()
    .json_schema_dialect(Some("https://spec.openapis.org/oas/3.2/dialect/2025-09-17"))
    .build();
Source

pub fn self_uri<S: Into<String>>(self, self_uri: Option<S>) -> Self

Add or change the URI identifying this OpenAPI document.

§Examples
let _ = OpenApiBuilder::new()
    .self_uri(Some("https://example.com/openapi.json"))
    .build();

Trait Implementations§

Source§

impl Default for OpenApiBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<OpenApi> for OpenApiBuilder

Source§

fn from(value: OpenApi) -> Self

Converts to this type from the input type.
Source§

impl From<OpenApiBuilder> for OpenApi

Source§

fn from(value: OpenApiBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.