Bytedocs

Struct Bytedocs 

Source
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

Source

pub fn new(config: Option<Config>) -> Self

Creates a new Bytedocs instance with the specified configuration.

§Arguments
  • config - Optional configuration. If None, uses default configuration.
§Example
use bytedocs_rs::Bytedocs;

let docs = Bytedocs::new(None);
Source

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.

Source

pub fn from_env_file(env_file: &str) -> Result<Self>

Creates a Bytedocs instance from a .env file.

§Arguments
  • env_file - Path to the environment file to load
§Errors

Returns an error if the file path is empty, file cannot be read, or configuration validation fails.

Source

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 endpoint
  • description - Optional detailed description
  • parameters - Optional list of parameters
  • request_body - Optional request body specification
  • responses - 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
Source

pub fn add_routes(&mut self, routes: Vec<RouteInfo>)

Adds multiple routes at once.

§Arguments
  • routes - Vector of RouteInfo structs to add
Source

pub fn auto_detect_axum_routes(&mut self, source_paths: &[&str]) -> Result<()>

Automatically detects and extracts Axum routes from source files.

§Arguments
  • source_paths - Array of source file paths to scan
§Errors

Returns an error if source paths are empty or route detection fails.

Source

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.

Source

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.

Source

pub fn documentation(&self) -> &Documentation

Returns a reference to the generated documentation.

Source

pub fn config(&self) -> &Config

Returns a reference to the configuration.

Source

pub async fn openapi_json(&mut self) -> Result<Value>

Returns the OpenAPI specification as JSON.

§Errors

Returns an error if JSON generation fails.

Source

pub async fn openapi_yaml(&mut self) -> Result<String>

Returns the OpenAPI specification as YAML.

§Errors

Returns an error if YAML generation fails.

Source

pub fn router(&self) -> Router

Returns an Axum router with all documentation routes configured.

This can be merged with your application’s existing router.

Source

pub async fn serve(&self, addr: &str) -> Result<()>

Starts the documentation server on the specified address.

§Arguments
  • addr - The address to bind to (e.g., “0.0.0.0:8813”)
§Errors

Returns an error if the address is empty or the server fails to start.

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<T> ErasedDestructor for T
where T: 'static,