Migrating APIs
API migrations are a common task in large codebases. Whether you’re updating a deprecated function, changing parameter names, or modifying return types, Codegen makes it easy to update all call sites consistently.
Common Migration Scenarios
Renaming Parameters
When updating parameter names across an API, you need to update both the function definition and all call sites:
Adding Required Parameters
When adding a new required parameter to an API:
Changing Parameter Types
When updating parameter types:
Deprecating Functions
When deprecating an old API in favor of a new one:
Bulk Updates to Method Chains
When updating chained method calls, like database queries or builder patterns:
Handling Breaking Changes
When making breaking changes to an API, it’s important to:
- Identify all affected call sites
- Make changes consistently
- Update related documentation
- Consider backward compatibility
Here’s a comprehensive example:
Best Practices
-
Analyze First: Before making changes, analyze all call sites to understand usage patterns
-
Make Atomic Changes: Update one aspect at a time
-
Maintain Backwards Compatibility:
-
Document Changes:
Remember to test thoroughly after making bulk changes to APIs. While Codegen ensures syntactic correctness, you’ll want to verify the semantic correctness of the changes.
Was this page helpful?