pub struct OpenApiBuilder { /* private fields */ }Expand description
OpenAPI document builder.
Implementations§
Source§impl OpenApiBuilder
impl OpenApiBuilder
Sourcepub fn new(
title: impl Into<String>,
version: impl Into<String>,
) -> OpenApiBuilder
pub fn new( title: impl Into<String>, version: impl Into<String>, ) -> OpenApiBuilder
Create a new builder.
Sourcepub fn description(self, description: impl Into<String>) -> OpenApiBuilder
pub fn description(self, description: impl Into<String>) -> OpenApiBuilder
Add a description.
Sourcepub fn server(
self,
url: impl Into<String>,
description: Option<String>,
) -> OpenApiBuilder
pub fn server( self, url: impl Into<String>, description: Option<String>, ) -> OpenApiBuilder
Add a server.
Sourcepub fn tag(
self,
name: impl Into<String>,
description: Option<String>,
) -> OpenApiBuilder
pub fn tag( self, name: impl Into<String>, description: Option<String>, ) -> OpenApiBuilder
Add a tag.
Sourcepub fn schema(self, name: impl Into<String>, schema: Schema) -> OpenApiBuilder
pub fn schema(self, name: impl Into<String>, schema: Schema) -> OpenApiBuilder
Add a schema component.
Sourcepub fn registry(&mut self) -> SchemaRegistryMut<'_>
pub fn registry(&mut self) -> SchemaRegistryMut<'_>
Access the component schema registry for in-place registration.
Sourcepub fn add_route(&mut self, route: &Route)
pub fn add_route(&mut self, route: &Route)
Add a metadata-rich route (from fastapi-router) as an OpenAPI operation.
This is a convenience bridge used by integration tests and by higher-level crates.
Sourcepub fn add_routes<'a, I>(&mut self, routes: I)where
I: IntoIterator<Item = &'a Route>,
pub fn add_routes<'a, I>(&mut self, routes: I)where
I: IntoIterator<Item = &'a Route>,
Add multiple routes.
Sourcepub fn operation(
self,
method: &str,
path: impl Into<String>,
operation: Operation,
) -> OpenApiBuilder
pub fn operation( self, method: &str, path: impl Into<String>, operation: Operation, ) -> OpenApiBuilder
Add a path operation (GET, POST, etc.).
This is the primary method for registering routes with OpenAPI.
§Example
ⓘ
let builder = OpenApiBuilder::new("My API", "1.0.0")
.operation("GET", "/users", Operation {
operation_id: Some("get_users".to_string()),
summary: Some("List all users".to_string()),
responses: HashMap::from([
("200".to_string(), Response {
description: "Success".to_string(),
content: HashMap::new(),
})
]),
..Default::default()
});Sourcepub fn get(
self,
path: impl Into<String>,
operation_id: impl Into<String>,
) -> OpenApiBuilder
pub fn get( self, path: impl Into<String>, operation_id: impl Into<String>, ) -> OpenApiBuilder
Add a simple GET endpoint with default 200 response.
Sourcepub fn post(
self,
path: impl Into<String>,
operation_id: impl Into<String>,
) -> OpenApiBuilder
pub fn post( self, path: impl Into<String>, operation_id: impl Into<String>, ) -> OpenApiBuilder
Add a simple POST endpoint with default 200 response.
Sourcepub fn put(
self,
path: impl Into<String>,
operation_id: impl Into<String>,
) -> OpenApiBuilder
pub fn put( self, path: impl Into<String>, operation_id: impl Into<String>, ) -> OpenApiBuilder
Add a simple PUT endpoint with default 200 response.
Sourcepub fn delete(
self,
path: impl Into<String>,
operation_id: impl Into<String>,
) -> OpenApiBuilder
pub fn delete( self, path: impl Into<String>, operation_id: impl Into<String>, ) -> OpenApiBuilder
Add a simple DELETE endpoint with default 200 response.
Auto Trait Implementations§
impl Freeze for OpenApiBuilder
impl RefUnwindSafe for OpenApiBuilder
impl Send for OpenApiBuilder
impl Sync for OpenApiBuilder
impl Unpin for OpenApiBuilder
impl UnsafeUnpin for OpenApiBuilder
impl UnwindSafe for OpenApiBuilder
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).