Thank you for your interest in contributing to Generator! This document provides guidelines and instructions for contributing to the project.
- Code of Conduct
- Getting Started
- Development Setup
- Project Structure
- Making Changes
- Testing
- Submitting Changes
- Coding Standards
- Adding New Languages
By participating in this project, you agree to maintain a respectful and inclusive environment for all contributors.
- Use welcoming and inclusive language
- Be respectful of differing viewpoints and experiences
- Gracefully accept constructive criticism
- Focus on what is best for the community
- Show empathy towards other community members
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/generator.git cd generator - Add upstream remote:
git remote add upstream https://github.com/adi-family/generator.git
- Rust 1.70 or later
- Cargo (comes with Rust)
- Git
# Build in debug mode
cargo build
# Build in release mode
cargo build --release
# Run the binary
./target/debug/generator --help# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run a specific test
cargo test test_name# Generate TypeScript example
cargo run -- -s examples/petstore.yaml -l type-script -o generated/test-ts
# Generate Python example
cargo run -- -s examples/petstore.yaml -l python -o generated/test-py
# Generate Golang example
cargo run -- -s examples/petstore.yaml -l golang -o generated/test-gogenerator/
├── src/
│ ├── main.rs # CLI entry point and orchestration
│ ├── schema_processor.rs # OpenAPI schema processing
│ ├── operation_processor.rs # API operation extraction
│ └── config/
│ └── loader.rs # Configuration loading
├── templates/
│ ├── typescript/ # TypeScript templates
│ ├── python/ # Python templates
│ └── golang/ # Golang templates
├── examples/
│ └── petstore.yaml # Example OpenAPI specs
└── generated/ # Output directory (gitignored)
main.rs: CLI definition, argument parsing, and generator orchestrationschema_processor.rs: Converts OpenAPI schemas to language-specific typesoperation_processor.rs: Extracts API operations and parameters- Templates: Tera templates for each target language
-
Create a branch from
main:git checkout -b feature/your-feature-name
-
Make your changes with clear, focused commits
-
Test your changes thoroughly:
cargo test cargo clippy cargo fmt -
Push to your fork:
git push origin feature/your-feature-name
-
Open a Pull Request on GitHub
Write clear, descriptive commit messages:
Add support for OAuth2 authentication
- Implement OAuth2 flow in schema processor
- Add OAuth2 configuration to generated clients
- Update templates for all languages
- Add tests for OAuth2 support
Fixes #123
Format:
- First line: Short summary (50 chars or less)
- Blank line
- Detailed description with bullet points
- Reference issues/PRs at the end
Add tests for new functionality in the appropriate module:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_schema_conversion() {
// Test implementation
assert_eq!(expected, actual);
}
}After making changes, test with real OpenAPI specs:
- Generate code for all supported languages
- Verify the generated code compiles/runs
- Check type safety and validation work correctly
- Test with edge cases (optional fields, arrays, nested objects)
- Update documentation if needed (README, inline comments)
- Add tests for new functionality
- Ensure all tests pass:
cargo test - Run the formatter:
cargo fmt - Run the linter:
cargo clippy - Update CHANGELOG.md if applicable
- Create Pull Request with a clear description
## Description
Brief description of the changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
How has this been tested?
## Checklist
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code where necessary
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locallyFollow the official Rust style guidelines:
# Format code automatically
cargo fmt
# Check for common mistakes
cargo clippy
# Check for warnings
cargo check- Use meaningful variable names:
schema_namenotsn - Write documentation comments for public APIs:
/// Processes an OpenAPI schema and converts it to a target language type. /// /// # Arguments /// * `schema` - The OpenAPI schema reference /// * `language` - Target programming language /// /// # Returns /// The converted type as a string pub fn process_schema(schema: &Schema, language: &str) -> String { // Implementation }
- Handle errors properly: Use
Result<T, E>andanyhowfor error handling - Keep functions small and focused: One responsibility per function
- Add tests for new functionality
- Use consistent indentation (2 or 4 spaces)
- Add comments explaining complex logic
- Keep templates readable and maintainable
- Test generated code compiles and runs
To add support for a new programming language:
Create templates/<language>/client.<ext>.tera:
templates/
└── java/
└── client.java.tera
In src/schema_processor.rs, add type conversion logic:
"java" => match openapi_type {
"string" => "String",
"integer" => "Integer",
"number" => "Double",
"boolean" => "Boolean",
// ... more mappings
}In src/main.rs, add the language to the enum:
#[derive(Debug, Clone, ValueEnum)]
enum Language {
TypeScript,
Python,
Golang,
Rust,
Java, // New language
}Add generation function in src/main.rs:
fn generate_java_code(
spec: &OpenAPI,
output_dir: &Path,
) -> Result<()> {
// Implementation
}Create an example in the README showing generated code.
List required dependencies for the generated code.
- Generate code from example specs
- Verify generated code compiles
- Test runtime validation works
- Add integration tests
- Issues: Open an issue on GitHub
- Discussions: Use GitHub Discussions for questions
- Email: Contact team@adi-family.com
Contributors will be acknowledged in:
- CHANGELOG.md for significant contributions
- GitHub contributors list
- Release notes
Thank you for contributing to Generator! 🎉