This package contains tools for working with the Algorand API specifications and generating Rust HTTP client libraries using a custom Jinja2-based generator.
- Python 3.12+ - Required for the custom OAS generator
- uv - Python package manager
- Rust - Required for compiling generated clients and running API tools
- Node.js - JavaScript runtime (only for convert-openapi script)
# Install Python dependencies for the OAS generator
cd api/oas_generator
uv install
# Install JavaScript dependencies (only needed for convert-openapi)
cd ../
npm installNOTE: These scripts can be run from the repository root using
cargo api <command>.
Converts the Algod, Indexer, and KMD OpenAPI 2.0 specs to OpenAPI 3.0:
cargo api convert-openapiConvert individual specifications:
# Convert only algod spec
cargo api convert-algod
# Convert only indexer spec
cargo api convert-indexer
# Convert only kmd spec
cargo api convert-kmdThe converted specs will be available at:
specs/algod.oas3.jsonspecs/indexer.oas3.jsonspecs/kmd.oas3.json
Generate all Rust API clients using the custom Jinja2-based generator:
cargo api generate-allGenerate individual clients:
# Generate algod client only
cargo api generate-algod
# Generate indexer client only
cargo api generate-indexer
# Generate kmd client only
cargo api generate-kmdThe generated Rust clients will be available at:
../crates/algod_client/../crates/indexer_client/../crates/kmd_client/
# Test the OAS generator
cargo api test-oas
# Format the OAS generator code
cargo api format-oas
# Lint and type-check the OAS generator
cargo api lint-oas
# Format generated Rust code
cargo api format-algod
cargo api format-indexer
cargo api format-kmdThe project uses a custom Jinja2-based generator located in oas_generator/ that creates optimized Rust API clients from OpenAPI 3.x specifications.
- Complete Rust Client Generation: APIs, models, and configuration
- Msgpack Support: Automatic detection and handling of binary encoding
- Signed Transactions: Algorand-specific vendor extension support (
x-algokit-signed-txn) - Type Safety: Comprehensive OpenAPI to Rust type mapping
- Template-based: Customizable Jinja2 templates for code generation
The generator creates complete Rust crates with the following structure:
crates/{algod_client,indexer_client,kmd_client}/
├── Cargo.toml
├── README.md
└── src/
├── lib.rs
├── apis/
│ ├── mod.rs
│ ├── client.rs
│ └── {endpoint}.rs
└── models/
├── mod.rs
└── {model}.rs
The algod.oas2.json is taken directly from go-algorand. To convert the spec to OpenAPI 3.0, use cargo api convert-algod which runs the TypeScript script scripts/convert-openapi.ts via swagger converter endpoint.
The indexer.oas2.json is taken directly from indexer. To convert the spec to OpenAPI 3.0, use cargo api convert-indexer which runs the same TypeScript conversion script.
The KMD Swagger 2.0 specification is sourced from go-algorand. Convert it to OpenAPI 3.0 with cargo api convert-kmd which invokes scripts/convert-openapi.ts.
The current approach is to manually edit and tweak the OAS2 specs fixing known issues from the source repositories, then use the custom Rust OAS generator to generate clients from the v3 specs. OpenAPI v3 is preferred for client generation as it offers enhanced schema features, better component reusability, and improved type definitions compared to v2.
The custom Rust generator is configured with:
- Package names:
algod_client,indexer_client,kmd_client - Msgpack detection: Automatic handling of binary-encoded fields
- Algorand extensions: Support for signed transaction via a vendor extension
- Type safety: Complete OpenAPI to Rust type mapping
- Error handling: Comprehensive error types and response handling
For detailed information about the generator architecture and customization options, see oas_generator/ARCHITECTURE.md.