dart_swagger_to_models 0.6.0
dart_swagger_to_models: ^0.6.0 copied to clipboard
Generate null-safe Dart models from Swagger/OpenAPI specs with multiple styles, validation, test data and per-file output.
0.6.0 #
Added #
- Advanced OpenAPI
oneOf/anyOfsupport:- Dynamic wrappers for
oneOf/anyOfwithout discriminator. - Discriminator-aware union-style classes (single class with discriminator field, nullable variant fields and
when/maybeWhenhelpers) when thediscriminator+ enum pattern is detected. - Detailed design notes in
doc/en/UNION_TYPES_NOTES.md.
- Dynamic wrappers for
- Runtime validation helpers:
- Optional
generateValidation: trueflag indart_swagger_to_models.yaml. validate()extension methods generated per model, based on schema constraints:minimum/maximum(ormin/max) for numeric fields,minLength/maxLengthfor string lengths,minItems/maxItemsfor array lengths.
- Optional
- DartDoc generation:
- Optional
generateDocs: trueflag indart_swagger_to_models.yaml. - Class-level and field-level DartDoc comments from OpenAPI/Swagger
description/example.
- Optional
- Test data helpers:
- Optional
generateTestData: trueflag indart_swagger_to_models.yaml. - Simple test data factories per model (e.g.
User createUserTestData(...)) with sensible defaults for primitive fields.
- Optional
- DX improvements:
--watchmode for automatic regeneration when the input spec file changes.--interactivemode that shows the list of schemas and asks for confirmation before generation.- New developer guides:
doc/en/DEVELOPERS.mdanddoc/ru/DEVELOPERS.md.
0.5.2 #
Added #
- Spec linting (spec quality hints)
- Configurable lint rules in
dart_swagger_to_models.yaml - Ability to enable/disable individual rules
- Configurable severity level (warning vs error) for each rule
- Available rules:
missing_type- field without type and without $refsuspicious_id_field- suspicious id field (not required and not nullable)missing_ref_target- missing target for $reftype_inconsistency- type inconsistency (for example, integer with format)empty_object- empty object (no properties and no additionalProperties)array_without_items- array without itemsempty_enum- enum without values
- Example configuration:
lint: enabled: true rules: missing_type: error suspicious_id_field: warning missing_ref_target: error type_inconsistency: warning empty_object: off array_without_items: warning empty_enum: warning
- Configurable lint rules in
0.5.1 #
Added #
- Incremental generation
- Cache system for tracking schema changes:
- Caches schema hashes in
.dart_swagger_to_models.cachefile - Uses SHA-256 hashes to detect schema changes
- Automatically handles new, modified, and deleted schemas
- Caches schema hashes in
--changed-onlyCLI flag:- Regenerates only schemas that have changed since last run
- Significantly improves performance for large specifications
- Automatically removes files for deleted schemas
- Comprehensive tests:
- First run (generates all schemas)
- Incremental run (only changed schemas)
- Adding new schemas
- Removing schemas
- Modifying single schema in large spec
- Example usage:
# First run - generates all schemas dart run dart_swagger_to_models:dart_swagger_to_models \ --input api.yaml \ --changed-only # Subsequent runs - only changed schemas dart run dart_swagger_to_models:dart_swagger_to_models \ --input api.yaml \ --changed-only
- Cache system for tracking schema changes:
0.4.2 #
Added #
- Improved DX and logging
- CLI flags
--verbose/-vfor detailed logs - CLI flag
--quiet/-qfor minimal output - Human-friendly error messages for missing
$reftargets - Warnings about unsupported or ambiguous schema constructs
- Warnings about suspicious specs (e.g.,
idwithoutnullable: truebut norequired) - Summary after generation showing:
- Number of processed schemas
- Number of processed enums
- Number of created/updated files
- Total files generated
- CLI flags
0.4.1 #
Added #
- build_runner integration
SwaggerBuilderclass for generating models as part of build_runner pipeline- Automatic detection of OpenAPI/Swagger specification files in
swagger/,openapi/, orapi/directories - Configuration via
build.yamlfile - Support for all generation styles (plain_dart, json_serializable, freezed)
- Example projects:
example/dart_example/- Pure Dart project demonstrating build_runner integrationexample/flutter_example/- Flutter project with HTTP client integration
- Documentation:
- Added section "Integration with build_runner" to
doc/en/USAGE.md
- Added section "Integration with build_runner" to
- Added section "Integration with build_runner" to
doc/ru/USAGE.md - Usage:
# build.yaml targets: $default: builders: dart_swagger_to_models|swaggerBuilder: enabled: true generate_for: - swagger/** - openapi/** - api/**# Run build_runner dart run build_runner build # or for Flutter flutter pub run build_runner build - Features:
- Automatic model generation when specifications change
- Seamless integration with other code generators (e.g., json_serializable)
- Works with all configuration options (defaultStyle, outputDir, useJsonKey, etc.)
- Generated files are part of project structure for IDE support
0.3.2 #
Added #
@JsonKeygeneration for snake_case JSON keys- Global config option
useJsonKey: true/false - Per-schema override
useJsonKeyin schema overrides - Works with both
json_serializableandfreezedstyles - Automatically detects when JSON key differs from Dart field name
- Global config option
0.3.1 #
Added #
- Pluggable styles
- Public API for registering custom generation styles:
StyleRegistryclass for registering custom stylesStyleRegistry.register()method to register a custom styleStyleRegistry.createCustomStrategy()to create a strategy instance- Support for custom style names in configuration files
- Support for custom style names via CLI
--styleoption
- Example custom style:
example/custom_style_equatable.dart- Complete example of an Equatable style generator
- Documentation:
doc/en/CUSTOM_STYLES.md- Step-by-step guide on creating custom stylesdoc/ru/CUSTOM_STYLES.md- Step-by-step guide in Russian
- Usage:
// Register a custom style StyleRegistry.register('my_style', () => MyCustomGenerator()); // Use in config file // dart_swagger_to_models.yaml: // defaultStyle: my_style // Or via CLI // --style my_style - Features:
- External packages can provide their own
ClassGeneratorStrategyimplementations - Style name → strategy mapping via
StyleRegistry - Custom styles work alongside built-in styles (
plain_dart,json_serializable,freezed) - Clear error messages when using unregistered styles
- External packages can provide their own
- Public API for registering custom generation styles:
0.2.2 #
Added #
- Configuration file support (
dart_swagger_to_models.yaml)- Global options:
defaultStyle,outputDir,projectDir - Per-schema overrides:
className,fieldNames,typeMapping
- Global options:
- CLI option
--config/-cfor specifying custom config file path - Priority system: CLI arguments > config file > defaults
0.2.1 #
Added #
- Improved OpenAPI handling
- Enhanced
oneOf/anyOfsupport:- Safer
dynamicwrappers with clear error messages - Architecture prepared for future union-type generation (especially with
discriminator) - Verbose logging about possible types in
oneOf/anyOfschemas - Detection and logging of
discriminatorusage
- Safer
- Extended
allOfsupport:- Recursive handling of nested
allOfcombinations - Support for multiple inheritance cases
- Detection and prevention of circular dependencies
- Verbose logging for nested
allOfprocessing
- Recursive handling of nested
- Comprehensive tests for complex composed schemas:
- Nested
allOfcombinations - Multiple inheritance through
allOf oneOf/anyOfwith discriminator- Circular dependency handling
- Nested
- Enhanced
