| Crates.io | openapi-from-source |
| lib.rs | openapi-from-source |
| version | 0.1.8 |
| created_at | 2025-10-23 08:59:38.502264+00 |
| updated_at | 2025-10-23 08:59:38.502264+00 |
| description | Generates OpenAPI document in YAML/JSON from RUST source code using Axum or Actix-Web |
| homepage | |
| repository | https://github.com/paxoscn/openapi-from-source.git |
| max_upload_size | |
| id | 1896826 |
| size | 311,733 |
A command-line tool that automatically generates OpenAPI 3.0 documentation from Rust web projects. The tool uses static code analysis to extract route information and data structures from your Rust source code without requiring compilation or runtime execution.
rename, skip, and flattenRouter::new(), .route(), .get(), .post(), etc.#[get], #[post], and other route macrosgit clone https://github.com/paxoscn/openapi-from-source.git
cd openapi-from-source
cargo build --release
The binary will be available at target/release/openapi-from-source.
cargo install openapi-from-source
Generate OpenAPI documentation for your Rust project:
openapi-from-source /path/to/your/project
This will output the OpenAPI document in YAML format to stdout.
Usage: openapi-from-source [OPTIONS] <PROJECT_PATH>
Arguments:
<PROJECT_PATH> Path to the Rust project directory
Options:
-f, --format <FORMAT> Output format (yaml or json) [default: yaml]
-o, --output <FILE> Output file path (if not specified, outputs to stdout)
-w, --framework <FRAMEWORK> Specify the web framework to parse (if not specified, auto-detect)
[possible values: axum, actix-web]
-v, --verbose Enable verbose output
-h, --help Print help
-V, --version Print version
openapi-from-source ./my-api-project -o openapi.yaml
openapi-from-source ./my-api-project -f json -o openapi.json
openapi-from-source ./my-api-project -w axum -o openapi.yaml
openapi-from-source ./my-api-project -v
openapi-from-source ./my-api-project | yq eval '.'
.rs filessyn crateuse axum::{Router, routing::{get, post}, Json, extract::Path};
// Simple routes
let app = Router::new()
.route("/users", get(list_users))
.route("/users", post(create_user));
// Path parameters
let app = Router::new()
.route("/users/:id", get(get_user));
// Nested routes
let app = Router::new()
.nest("/api", api_routes());
// Extractors
async fn create_user(Json(payload): Json<CreateUserRequest>) -> Json<User> {
// ...
}
use actix_web::{get, post, web, HttpResponse};
// Route macros
#[get("/users")]
async fn list_users() -> HttpResponse {
// ...
}
#[post("/users")]
async fn create_user(user: web::Json<CreateUserRequest>) -> HttpResponse {
// ...
}
// Path parameters
#[get("/users/{id}")]
async fn get_user(path: web::Path<i32>) -> HttpResponse {
// ...
}
// Scopes
web::scope("/api")
.service(list_users)
.service(create_user)
The tool automatically resolves Rust types and generates appropriate OpenAPI schemas:
String, i32, bool, etc. → OpenAPI primitive typesVec<T> → array schemasOption<T> → marks fields as non-required#[serde(rename)], #[serde(skip)], #[serde(flatten)]use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct User {
pub id: i32,
pub name: String,
#[serde(rename = "email_address")]
pub email: String,
pub age: Option<i32>,
#[serde(skip)]
pub password_hash: String,
}
This generates an OpenAPI schema with:
id as integername as stringemail_address as string (renamed)age as optional integerpassword_hash excluded from schemaIf the tool reports no routes found:
-w-v to see detailed parsing informationIf files fail to parse:
cargo checkIf schemas are incomplete:
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.