pub struct OpenApiBuilder { /* private fields */ }Expand description
OpenAPI document builder.
Implementations§
Source§impl OpenApiBuilder
impl OpenApiBuilder
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Add a description.
Sourcepub fn security_scheme(
self,
name: impl Into<String>,
scheme: SecurityScheme,
) -> Self
pub fn security_scheme( self, name: impl Into<String>, scheme: SecurityScheme, ) -> Self
Register a named security scheme, deduplicating identical definitions.
Names are explicit; arbitrary route requirement names do not infer schemes.
§Panics
Panics during registration if the name already has a different definition.
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) -> Option<&mut Operation>
pub fn add_route(&mut self, route: &Route) -> Option<&mut Operation>
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,
) -> Self
pub fn operation( self, method: &str, path: impl Into<String>, operation: Operation, ) -> Self
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>,
) -> Self
pub fn get( self, path: impl Into<String>, operation_id: impl Into<String>, ) -> Self
Add a simple GET endpoint with default 200 response.
Sourcepub fn post(
self,
path: impl Into<String>,
operation_id: impl Into<String>,
) -> Self
pub fn post( self, path: impl Into<String>, operation_id: impl Into<String>, ) -> Self
Add a simple POST endpoint with default 200 response.
Sourcepub fn put(
self,
path: impl Into<String>,
operation_id: impl Into<String>,
) -> Self
pub fn put( self, path: impl Into<String>, operation_id: impl Into<String>, ) -> Self
Add a simple PUT endpoint with default 200 response.
Sourcepub fn delete(
self,
path: impl Into<String>,
operation_id: impl Into<String>,
) -> Self
pub fn delete( self, path: impl Into<String>, operation_id: impl Into<String>, ) -> Self
Add a simple DELETE endpoint with default 200 response.