A powerful OpenAPI 3.0 code generator written in Rust that supports multiple programming languages and frameworks.
- 🚀 Multi-language Support: Generate code for Rust, Flutter/Dart, TypeScript, Python, and Java
- 🎯 Template-based Generation: Flexible template system using Handlebars
- 🔧 Extension/Implementation Pattern: Generate code as extensions or implementations for existing classes
- 📝 Automatic Type Mapping: Smart type conversion from OpenAPI schemas to target language types
- 🔗 Parameter Support: Full support for path, query, header, and body parameters
- 📚 Documentation: Auto-generate comments and documentation from OpenAPI descriptions
- ⚡ Fast & Efficient: Built with Rust for high performance
cargo install ru-openapi-cg# Generate Flutter/Dart extension
ru-openapi-cg -i openapi.json -t templates/flutter_dart.hbs -o api_client.dart -x MyApiClient
# Generate TypeScript extension
ru-openapi-cg -i openapi.json -t templates/typescript_ext.hbs -o api_client.ts -x MyApiClient
# Generate Python class
ru-openapi-cg -i openapi.json -t templates/python_ext.hbs -o api_client.py -x MyApiClient
# Generate Java class
ru-openapi-cg -i openapi.json -t templates/java_ext.hbs -o ApiClient.java -x MyApiClient
# Generate Rust implementation
ru-openapi-cg -i openapi.json -t templates/rust_impl.hbs -o api_client.rs -x MyStruct-i, --input: OpenAPI specification file (JSON/YAML)-t, --template: Template file path-o, --output: Output file path-x, --target: Target class/struct name for extension/implementation
- Extension-based approach
- Named parameters with required/optional support
- Automatic JSON serialization
- Error handling with debug logging
- Extension function pattern
- Fetch API integration
- URL parameter building
- Type-safe responses
- Class inheritance pattern
- Requests library integration
- Query parameter support
- JSON handling
- Class extension pattern
- HttpClient integration (Java 11+)
- Jackson JSON processing
- URL encoding support
- Trait implementation pattern
- Reqwest HTTP client
- Async/await support
- Error handling
The generator uses Handlebars templates for maximum flexibility. You can create custom templates or modify existing ones:
Automatic type conversion from OpenAPI schemas:
| OpenAPI Type | Dart | TypeScript | Python | Java | Rust |
|---|---|---|---|---|---|
| integer | int | number | int | Integer | i32 |
| integer (int64) | int | number | int | Long | i64 |
| number | double | number | float | Double | f64 |
| string | String | string | str | String | String |
| boolean | bool | boolean | bool | Boolean | bool |
| array | List | T[] | List[T] | List | Vec |
| object | Map<String, dynamic> | any | dict | Map<String, Object> | HashMap<String, Value> |
{
"openapi": "3.0.0",
"paths": {
"/api/users/{id}": {
"get": {
"operationId": "getUser",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {"type": "integer"}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {"type": "object"}
}
}
}
}
}
}
}
}extension ApiClient on MyApiClient {
/// getUser
Future<GetUserResponse> getUser({
required int id,
}) async {
try {
final uri = "/api/users/{id}".replaceAll("id", id.toString());
return await _sdk.get<GetUserResponse>(uri,
fromJson: (p0) => GetUserResponse.fromJson(p0));
} catch (e) {
debugPrint('getUser error: $e');
rethrow;
}
}
}- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Initial release
- Multi-language support (Rust, Flutter/Dart, TypeScript, Python, Java)
- Template-based code generation
- Extension/implementation patterns
- Automatic type mapping
- Parameter support (path, query, body)