openapi_from_source/
lib.rs

1//! Rust OpenAPI Generator - Automatic OpenAPI documentation from Rust web projects.
2//!
3//! This library provides tools to automatically generate OpenAPI 3.0 documentation by analyzing
4//! Rust source code. It uses static code analysis to extract route definitions, type information,
5//! and handler signatures from web framework code.
6//!
7//! # Supported Frameworks
8//!
9//! - **Axum**: Extracts routes from `Router` definitions and method chains
10//! - **Actix-Web**: Extracts routes from route macros like `#[get]`, `#[post]`, etc.
11//!
12//! # Architecture
13//!
14//! The library is organized into several modules that work together:
15//!
16//! 1. [`scanner`] - Recursively scans project directories for Rust files
17//! 2. [`parser`] - Parses Rust source files into Abstract Syntax Trees (AST)
18//! 3. [`detector`] - Automatically detects which web frameworks are used
19//! 4. [`extractor`] - Extracts route information from framework-specific code
20//! 5. [`type_resolver`] - Resolves Rust types and their definitions
21//! 6. [`schema_generator`] - Converts Rust types to OpenAPI schemas
22//! 7. [`openapi_builder`] - Constructs the complete OpenAPI document
23//! 8. [`serializer`] - Serializes the document to YAML or JSON
24//!
25//! # Example Usage
26//!
27//! ```no_run
28//! use openapi_from_source::{
29//!     scanner::FileScanner,
30//!     parser::AstParser,
31//!     detector::FrameworkDetector,
32//!     extractor::{RouteExtractor, axum::AxumExtractor},
33//!     type_resolver::TypeResolver,
34//!     schema_generator::SchemaGenerator,
35//!     openapi_builder::OpenApiBuilder,
36//!     serializer::serialize_yaml,
37//! };
38//! use std::path::PathBuf;
39//!
40//! // Scan project directory
41//! let scanner = FileScanner::new(PathBuf::from("./my-project"));
42//! let scan_result = scanner.scan().unwrap();
43//!
44//! // Parse files
45//! let parse_results = AstParser::parse_files(&scan_result.rust_files);
46//! let parsed_files: Vec<_> = parse_results.into_iter().filter_map(Result::ok).collect();
47//!
48//! // Detect frameworks
49//! let detection = FrameworkDetector::detect(&parsed_files);
50//!
51//! // Extract routes
52//! let extractor = AxumExtractor;
53//! let routes = extractor.extract_routes(&parsed_files);
54//!
55//! // Build OpenAPI document
56//! let type_resolver = TypeResolver::new(parsed_files);
57//! let mut schema_gen = SchemaGenerator::new(type_resolver);
58//! let mut builder = OpenApiBuilder::new();
59//! for route in &routes {
60//!     builder.add_route(route, &mut schema_gen);
61//! }
62//! let document = builder.build(schema_gen);
63//!
64//! // Serialize to YAML
65//! let yaml = serialize_yaml(&document).unwrap();
66//! println!("{}", yaml);
67//! ```
68//!
69//! # Command-Line Interface
70//!
71//! For command-line usage, see the [`cli`] module which provides a complete CLI application.
72
73pub mod cli;
74pub mod scanner;
75pub mod parser;
76pub mod detector;
77pub mod extractor;
78pub mod type_resolver;
79pub mod schema_generator;
80pub mod openapi_builder;
81pub mod serializer;
82pub mod error;