pub struct Bytedocs { /* private fields */ }
Expand description
Main entry point for Bytedocs API documentation generation.
Bytedocs
is the primary struct for creating and managing API documentation.
It wraps the internal APIDocs
implementation and provides a user-friendly API.
Implementations§
Source§impl Bytedocs
impl Bytedocs
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Creates a Bytedocs
instance from environment variables.
Reads configuration from environment variables and validates it.
§Errors
Returns an error if environment variables are invalid or configuration validation fails.
Sourcepub fn from_env_file(env_file: &str) -> Result<Self>
pub fn from_env_file(env_file: &str) -> Result<Self>
Sourcepub fn add_route(
&mut self,
method: &str,
path: &str,
handler: Option<Box<dyn Any + Send + Sync>>,
summary: Option<&str>,
description: Option<&str>,
parameters: Option<Vec<Parameter>>,
request_body: Option<RequestBody>,
responses: Option<HashMap<String, Response>>,
) -> Result<()>
pub fn add_route( &mut self, method: &str, path: &str, handler: Option<Box<dyn Any + Send + Sync>>, summary: Option<&str>, description: Option<&str>, parameters: Option<Vec<Parameter>>, request_body: Option<RequestBody>, responses: Option<HashMap<String, Response>>, ) -> Result<()>
Adds a new API route to the documentation.
§Arguments
method
- HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)path
- API endpoint path (must start with ‘/’)handler
- Optional handler function (for framework integration)summary
- Optional short description of the endpointdescription
- Optional detailed descriptionparameters
- Optional list of parametersrequest_body
- Optional request body specificationresponses
- Optional response specifications
§Errors
Returns an error if:
- Method is empty or invalid
- Path is empty or doesn’t start with ‘/’
- Path format is invalid
Sourcepub fn add_routes(&mut self, routes: Vec<RouteInfo>)
pub fn add_routes(&mut self, routes: Vec<RouteInfo>)
Sourcepub fn auto_detect_axum_routes(&mut self, source_paths: &[&str]) -> Result<()>
pub fn auto_detect_axum_routes(&mut self, source_paths: &[&str]) -> Result<()>
Sourcepub fn auto_detect_from_main(&mut self) -> Result<()>
pub fn auto_detect_from_main(&mut self) -> Result<()>
Convenience method to auto-detect routes from src/main.rs
.
§Errors
Returns an error if route detection fails.
Sourcepub fn generate(&mut self) -> Result<()>
pub fn generate(&mut self) -> Result<()>
Generates the API documentation.
This must be called after adding all routes and before serving the documentation.
§Errors
Returns an error if documentation generation fails.
Sourcepub fn documentation(&self) -> &Documentation
pub fn documentation(&self) -> &Documentation
Returns a reference to the generated documentation.