ru-openapi-cg-0.1.0 is not a library.
ru-openapi-cg
A powerful OpenAPI 3.0 code generator written in Rust that supports multiple programming languages and frameworks.
Features
- 🚀 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
Installation
Quick Start
Basic Usage
# Generate Flutter/Dart extension
# Generate TypeScript extension
# Generate Python class
# Generate Java class
# Generate Rust implementation
Command Line Options
-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
Supported Languages
Flutter/Dart
- Extension-based approach
- Named parameters with required/optional support
- Automatic JSON serialization
- Error handling with debug logging
TypeScript
- Extension function pattern
- Fetch API integration
- URL parameter building
- Type-safe responses
Python
- Class inheritance pattern
- Requests library integration
- Query parameter support
- JSON handling
Java
- Class extension pattern
- HttpClient integration (Java 11+)
- Jackson JSON processing
- URL encoding support
Rust
- Trait implementation pattern
- Reqwest HTTP client
- Async/await support
- Error handling
Template System
The generator uses Handlebars templates for maximum flexibility. You can create custom templates or modify existing ones:
// Example template structure
{{#each endpoints}}
pub async fn {{this.name}}(
{{#each this.params}}{{this.name}}: {{this.ty}}, {{/each}}
) -> Result<{{this.response_type}}, Error> {
// Generated implementation
}
{{/each}}
Type Mapping
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> |
Examples
Input OpenAPI Specification
Generated Flutter/Dart Code
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;
}
}
}
Contributing
- 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
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
v0.1.0
- 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)