| Crates.io | ru-openapi-cg |
| lib.rs | ru-openapi-cg |
| version | 0.1.4 |
| created_at | 2025-06-22 04:59:55.815298+00 |
| updated_at | 2025-09-07 09:40:38.244313+00 |
| description | A powerful OpenAPI 3.0 code generator written in Rust that supports multiple programming languages and frameworks |
| homepage | https://github.com/yourusername/ru-openapi-cg |
| repository | https://github.com/yourusername/ru-openapi-cg |
| max_upload_size | |
| id | 1721292 |
| size | 160,544 |
A powerful OpenAPI 3.0 code generator written in Rust that supports multiple programming languages and frameworks.
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/implementationThe 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}}
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;
}
}
}
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.