Releases: btwld/ack
v0.3.0-beta.1
What's Changed
✨ New Features
- Discriminated Union Schemas: New schema type for polymorphic validation based on discriminator fields
- Dart Mappable Integration: Seamless field name synchronization for model generation
- Unified API Compatibility Checking: Single
melos api-checkcommand replaces 19 complex shell commands
🔄 API Modernization & Deprecations
Multiple constraint classes have been deprecated in favor of unified ComparisonConstraint and PatternConstraint implementations:
String Constraints (use PatternConstraint instead):
StringDateTimeConstraint→PatternConstraint.dateTime()StringDateConstraint→PatternConstraint.date()StringEnumConstraint→PatternConstraint.enumValues()StringEmailConstraint→PatternConstraint.email()StringRegexConstraint→PatternConstraint.regex()StringJsonValidator→PatternConstraint.json()
Numeric Constraints (use ComparisonConstraint instead):
NumberMinConstraint→ComparisonConstraint.numberMin()NumberMaxConstraint→ComparisonConstraint.numberMax()NumberRangeConstraint→ComparisonConstraint.numberRange()NumberExclusiveMinConstraint→ComparisonConstraint.numberExclusiveMin()NumberExclusiveMaxConstraint→ComparisonConstraint.numberExclusiveMax()NumberMultipleOfConstraint→ComparisonConstraint.numberMultipleOf()
Collection Constraints (use ComparisonConstraint instead):
StringMinLengthConstraint→ComparisonConstraint.stringMinLength()StringMaxLengthConstraint→ComparisonConstraint.stringMaxLength()ListMinItemsConstraint→ComparisonConstraint.listMinItems()ListMaxItemsConstraint→ComparisonConstraint.listMaxItems()ObjectMinPropertiesConstraint→ComparisonConstraint.objectMinProperties()ObjectMaxPropertiesConstraint→ComparisonConstraint.objectMaxProperties()
🛠️ Schema API Changes
- SchemaRegistry: Simplified type signatures - removed model type parameter
- SchemaModel: Method signature updates for
parse()andtryParse() - Extension Methods: Deprecated legacy method names on schema extensions
📚 Documentation & Tooling
- Consolidated API documentation and tooling
- Enhanced constraint migration guidance
- Simplified development workflow with unified commands
All deprecated APIs remain functional with migration guidance. See the deprecations for detailed migration paths.
Full Changelog: v0.2.0-beta.1...0.3.0-beta.1
v0.2.0-beta.1
Release v0.2.0-beta.1
This release introduces significant improvements to the SchemaModel API, enhanced string validation, and better OpenAPI integration.
Key Features
- Code Generation: Generate schema classes from your models
- Type-safe Schema Access: Direct property getters with proper types
- Automatic Validation: Validation happens during construction
- Multiple Validation Approaches: Choose what fits your workflow
- Improved String Validation: New pattern matching options
- JSON Schema Integration: Generate API specifications automatically
Code Generation
Define Your Models
Annotate your models with validation rules:
@Schema()
class Product {
@IsNotEmpty()
final String id;
@MinLength(3)
final String name;
final double price;
final Category category;
Product({
required this.id,
required this.name,
required this.price,
required this.category,
});
}Run the Generator
Use the build_runner to generate schema classes:
dart run build_runner build --delete-conflicting-outputsThis creates a .schema.dart file with your generated schemas.
SchemaModel API
Creating Schemas
The constructor now validates data automatically:
// Create schema with automatic validation
final schema = ProductSchema({
'id': '123',
'name': 'Test Product',
'price': 19.99
});
// Check if valid
bool valid = schema.isValid;Accessing Schema Values
Access validated data with type-safe getters:
// Type-safe access to properties
String id = schema.id;
String name = schema.name;
double price = schema.price;
// Access nested schema objects
CategorySchema category = schema.category;
String categoryName = category.name;Handling Validation Errors
Get detailed error information when validation fails:
if (!schema.isValid) {
SchemaError? error = schema.getErrors();
// Error details
String errorType = error?.name; // e.g., "required_field"
String message = error?.message; // e.g., "Required field is missing"
String? path = error?.path; // e.g., "category.id"
}Converting to Models
Transform schema data to strongly-typed models:
// Convert schema to model instance
Product product = schema.toModel();
// Access model properties
String id = product.id;
Category category = product.category;Alternative Validation Approaches
Choose your preferred validation style:
// Approach 1: Constructor + isValid check
final schema = ProductSchema(data);
if (schema.isValid) {
final product = schema.toModel();
}
// Approach 2: Direct parse (throws on failure)
try {
Product product = ProductSchema.parse(data);
} catch (e) {
// Handle validation error
}
// Approach 3: Try-parse (returns null on failure)
Product? product = ProductSchema.tryParse(data);
if (product != null) {
// Use valid product
}Creating Schema from Model
Convert model instances to schemas for serialization:
// Create schema from model instance
final schema = ProductSchema.fromModel(product);
// Serialize to various formats
Map<String, Object?> map = schema.toMap();
String json = schema.toJson();Enhanced String Validation
Full Pattern Matching
The matches() method now validates entire strings:
// Full string pattern matching (with anchors)
final schema = Ack.string.matches('^[a-z0-9_]{3,16}$');
schema.validate('user_123').isOk; // true
schema.validate('user@123').isOk; // false - contains @Partial String Matching
New contains() method for substring matching:
// Partial string matching
final schema = Ack.string.contains('important');
schema.validate('This is important text').isOk; // true
schema.validate('Nothing here').isOk; // falseJSON Schema Integration
Generate API specifications from your schemas:
// Get JSON Schema
Map<String, Object?> jsonSchema = ProductSchema.toJsonSchema();
// Convert to JSON string
String jsonString = jsonEncode(jsonSchema);Migration Guide
If you're upgrading from 0.1.x, note these changes:
-
Update string pattern validation:
// Old (0.1.x): Matches substrings Ack.string.matches('abc'); // Would match 'abcdef' // New (0.2.0): Matches whole string Ack.string.matches('^abc$'); // Only matches 'abc' exactly Ack.string.contains('abc'); // Matches substrings, like old matches()
-
Use the new validation workflow:
// Create and validate in one step final schema = ProductSchema(data); // Check isValid before using if (schema.isValid) { schema.id; // Access schema properties schema.category.name; // Access nested properties // Or convert to model final product = schema.toModel(); }
Documentation
Full documentation is available at https://docs.page/btwld/ack
0.1.1
Full Changelog: 0.1.0...0.1.1
0.1.0
What's Changed
- Feature/better error handling by @leoafarias in #1
- Chore/ci fix by @leoafarias in #2
New Contributors
- @leoafarias made their first contribution in #1
Full Changelog: 0.0.2...0.1.0
0.0.2
- Better json response parsing for OpenApiSchemaConverter
Full Changelog: 0.0.1...0.0.2
0.0.1
Initial release
Full Changelog: https://github.com/leoafarias/ack/commits/0.0.2