api_contract_generator 0.2.0 copy "api_contract_generator: ^0.2.0" to clipboard
api_contract_generator: ^0.2.0 copied to clipboard

Annotation-based code generator for api_contract. Automatically generate API contract definitions from annotated Dart classes.

Changelog #

0.2.0 #

Features #

  • Code generation from model classes: Use @ApiContractSchema annotation on Dart classes to auto-generate contracts
  • Type inference: Automatically detects field types from model structure (int, String, DateTime, nested models, etc.)
  • Built-in type support: Handles DateTime, Uri, Duration, BigInt, RegExp and maps them to appropriate JSON types
  • ContractMode enum: Use ContractMode.strict or ContractMode.lenient instead of string values
  • Field annotations: Fine-grained control with @optional and @nullable annotations
  • Multiple generation modes:
    • fromModel - infers contracts from model class structure (recommended)
    • fromJson - generates from JSON with callback
    • fromJsonSchema - generates from schema map
  • Nested contract support: Automatically generates contracts for referenced model classes
  • Nullable type handling: Proper handling of nullable types (e.g., Profile?profileContract, not profile?Contract)

Improvements #

  • Removed dependency on path-based api_contract, now uses published package ^0.2.0
  • Better error messages in generated code
  • Cleaner generated output with proper formatting
  • Annotation priority: Explicit @optional/@nullable annotations override type inference

Bug Fixes #

  • Fixed nullable type name generation (removed ? from variable names)
  • Fixed enum mode reading in annotation processor
  • Fixed annotation priority in fromModel mode
  • Fixed duplicate ContractMode enum issue

Breaking Changes #

  • Package renamed from http_contract_tester_generator to api_contract_generator
  • Updated to work with api_contract 0.2.0 (renamed from http_contract_tester)
  • ContractMode is now an enum, not a string
  • Simplified annotation system - removed verbose field-level annotations in favor of model-based generation

0.1.0 #

  • Initial release
  • Basic contract generation from annotations
0
likes
140
points
75
downloads

Publisher

unverified uploader

Weekly Downloads

Annotation-based code generator for api_contract. Automatically generate API contract definitions from annotated Dart classes.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, api_contract, build, source_gen

More

Packages that depend on api_contract_generator