api_contract 0.2.0
api_contract: ^0.2.0 copied to clipboard
Runtime API response contract validator for Flutter/Dart. Detect API mismatches before they crash your app. Works with any HTTP client.
0.2.0 #
✨ New Features #
- Code Generation Support: Auto-generate contracts from model classes using
@ApiContractSchemaannotation - Built-in Types: Auto-detection for
DateTime,Uri,Duration,BigInt, andRegExp - Field Annotations:
@optionaland@nullableannotations for fine-grained control - Repository Pattern: Clean integration examples for repository layer validation
- Enum Support:
ContractModeis now an enum instead of string-based - Added
ApiContract.fromJson()to auto-generate contracts from sample JSON responses - Added
ApiContract.fromJsonSchema()to generate contracts from JSON Schema / OpenAPI / Swagger schemas - Support for
$refresolution in JSON Schema
🔧 Improvements #
- Removed Dio interceptor dependency - validation now works with any HTTP client
- Moved
dioto dev_dependencies (only needed for examples) - Better handling of nullable types in code generation
- Improved error messages for contract violations
- Updated documentation with comprehensive examples
🐛 Bug Fixes #
- Fixed nullable type name generation (e.g.,
OwnerModel?→ownerModelContract) - Fixed field annotation priority in code generator
- Corrected enum mode reading in annotation processor
- Fixed
@nullableannotation not being respected infromModelmode
📚 Documentation #
- Complete rewrite of README with modern examples
- Added repository pattern integration guide
- Added CI/CD integration examples
- Improved API reference documentation
⚠️ Breaking Changes #
ContractModeis now an enum: useContractMode.strictinstead of'strict'- Removed
ContractInterceptorandRequestContractInterceptor(Dio-specific) - Package focuses on repository pattern instead of interceptors
0.1.0 #
Initial Release #
- Core contract validation with
ApiContract,ContractField, andValidator - Support for
string,number,boolean,list,map, andanyfield types - Nested object and list item validation
- Strict and lenient validation modes
ContractConfigfor global violation behavior configurationReporterfor configurable violation reportingContractValidationResultwithwhen()andthrowIfInvalid()- Contract versioning and
upgrade()method