Skip to main content

ApiDocBuilder

Struct ApiDocBuilder 

Source
pub struct ApiDocBuilder { /* private fields */ }
Expand description

Builder for an ApiDoc.

Typical use:

use doxa::ApiDocBuilder;
use utoipa_axum::router::OpenApiRouter;

let (router, openapi) = OpenApiRouter::<()>::new().split_for_parts();

let api_doc = ApiDocBuilder::new()
    .title("Example API")
    .version(env!("CARGO_PKG_VERSION"))
    .description("Example service")
    .server("/", "current host")
    .bearer_security("bearer")
    .merge(openapi)
    .build();

Implementations§

Source§

impl ApiDocBuilder

Source

pub fn new() -> Self

Construct an empty builder. Title, version, and at least one path (via Self::merge) should be supplied before Self::build.

Source

pub fn title(self, title: impl Into<String>) -> Self

Set the API title that appears in the document’s info.title.

Source

pub fn version(self, version: impl Into<String>) -> Self

Set the API version that appears in the document’s info.version. Conventionally env!("CARGO_PKG_VERSION").

Source

pub fn description(self, description: impl Into<String>) -> Self

Set the API description that appears in the document’s info.description. Markdown is supported by most viewers.

Source

pub fn contact_name(self, name: impl Into<String>) -> Self

Set the contact name on the document’s info.contact.

Source

pub fn contact_email(self, email: impl Into<String>) -> Self

Set the contact email on the document’s info.contact.

Source

pub fn contact_url(self, url: impl Into<String>) -> Self

Set the contact URL on the document’s info.contact.

Source

pub fn license(self, name: impl Into<String>) -> Self

Set the license name on the document’s info.license.

Source

pub fn license_url(self, url: impl Into<String>) -> Self

Set the license URL on the document’s info.license.

Source

pub fn server( self, url: impl Into<String>, description: impl Into<String>, ) -> Self

Append a server entry. The first call sets the primary server; additional calls add alternates (staging, regional endpoints).

Source

pub fn bearer_security(self, name: impl Into<String>) -> Self

Register an HTTP bearer security scheme under the given name, advertising the bearer format as JWT.

The name is what handlers reference in their security(...) blocks (e.g., security(("bearer" = []))). Use bearer_security_with_format to override the format (for example for opaque, introspection-based tokens).

Source

pub fn bearer_security_with_format( self, name: impl Into<String>, bearer_format: impl Into<String>, ) -> Self

Register an HTTP bearer security scheme under the given name with an explicit bearerFormat value.

Use this when the bearer token format is not JWT — for example RFC 7662 opaque tokens validated by introspection, SAML bearer assertions, or a proprietary token format that clients should not attempt to decode locally.

Source

pub fn security_scheme( self, name: impl Into<String>, scheme: SecurityScheme, ) -> Self

Register an arbitrary security scheme under the given name. Use this for OAuth flows, API keys, OpenID Connect, etc.

Source

pub fn oauth2_security( self, name: impl Into<String>, flows: impl IntoIterator<Item = Flow>, ) -> Self

Register an OAuth2 security scheme under the given name with the supplied Flow entries.

Prefer this over Self::bearer_security when handlers declare per-operation scope requirements (e.g. via crate::DocOperationSecurity impls). The bearer-only HTTP scheme has no scope vocabulary, so OpenAPI client codegen (openapi-generator, oapi-codegen, etc.) silently drops any scopes attached to operation security entries. With an OAuth2 scheme that publishes the scope vocabulary in flows.<flow>.scopes, generated clients carry the required scopes through to the token request.

Source

pub fn tag( self, name: impl Into<String>, description: impl Into<String>, ) -> Self

Register a tag with a display name and description. Tags are auto-discovered from operations at build time, so this is only needed when you want to override the description shown in the docs UI for a specific tag.

When provided, the tag’s position in the .tag() call order determines its display order in the sidebar. Auto-discovered tags without an explicit .tag() entry appear after any explicitly registered ones, sorted alphabetically.

Source

pub fn tag_group( self, name: impl Into<String>, tags: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Manually group tags into a named section via the x-tagGroups vendor extension (Scalar + Redoc).

When any .tag_group() call is present, auto-grouping is disabled — the caller takes full control of the grouping. Tags not assigned to any group may be hidden by some renderers (notably Redoc).

When no .tag_group() calls are present, the builder auto-generates groups by splitting tag names on the delimiter (default ": "). For example, "Admin: Models" is placed in the "Admin" group. Tags without the delimiter go into the default group (see Self::default_tag_group).

Source

pub fn default_tag_group(self, name: impl Into<String>) -> Self

Set the name of the default tag group for tags that don’t contain the group delimiter. Defaults to "API" when auto-grouping is active.

Only meaningful when no explicit .tag_group() calls are present (i.e., auto-grouping is active).

Source

pub fn tag_group_delimiter(self, delimiter: impl Into<String>) -> Self

Set the delimiter used to split tag names into (group, display_name) for auto-generated tag groups. Defaults to ": ".

For example, with delimiter ": ", the tag "Admin: Models" is placed in the "Admin" group. With delimiter "/", the tag "Admin/Models" would be placed in the "Admin" group.

Source

pub fn schema_tag( self, schema: impl Into<String>, tag: impl Into<String>, ) -> Self

Manually assign a tag to a schema. The tag is injected as an x-tags vendor extension on the schema in components.schemas. Manual tags merge with auto-inferred tags (schemas automatically inherit tags from the operations that reference them).

Source

pub fn sse_openapi_version(self, version: SseSpecVersion) -> Self

Choose the OpenAPI spec version used to render text/event-stream responses produced by handlers returning crate::SseStream.

Defaults to SseSpecVersion::V3_2 — the rendered document will carry openapi: "3.2.0" and SSE responses will place the event schema under itemSchema, matching the OpenAPI 3.2 first-class SSE support. Call with SseSpecVersion::V3_1 to downgrade for consumers that still require the 3.1 shape (Redoc, openapi-generator, swagger-parser < 3.2).

§Example
use doxa::{ApiDocBuilder, SseSpecVersion};

// Render against OpenAPI 3.1 for consumers that don't yet
// understand the 3.2 `itemSchema` keyword.
let doc = ApiDocBuilder::new()
    .title("Compat")
    .version("1.0.0")
    .sse_openapi_version(SseSpecVersion::V3_1)
    .build();
Source

pub fn merge(self, openapi: OpenApi) -> Self

Merge an existing OpenApi (typically from utoipa_axum::router::OpenApiRouter::split_for_parts) into the document. The merged document inherits paths, components, and tags from the supplied value.

Source

pub fn try_build(self) -> Result<ApiDoc, BuildError>

Finalize the builder, producing an ApiDoc with its JSON representation pre-serialized into an Arc<str>. Returns an error only if JSON serialization itself fails — which in practice requires a malformed custom schema to be present in the merged document.

Source

pub fn build(self) -> ApiDoc

Convenience wrapper around Self::try_build that panics on serialization failure. Suitable for startup code where a failed build is unrecoverable.

Trait Implementations§

Source§

impl Default for ApiDocBuilder

Source§

fn default() -> ApiDocBuilder

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

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,