-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for enumString, literal, and enumValues in Ack.object() #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
753ca39
c6852a8
2a08cbb
39e979c
d3c293d
a85b690
80379c4
58b1366
bf17755
530bb13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ Entry point for creating schemas. See [Schema Types](../core-concepts/schemas.md | |||||
| - `Ack.enumString(List<String> values)`: Creates a string schema that only accepts specific values. | ||||||
| - `Ack.anyOf(List<AckSchema> schemas)`: Creates an `AnyOfSchema` for union types. | ||||||
| - `Ack.any()`: Creates an `AnySchema` that accepts any value. | ||||||
| - `Ack.discriminated({required String discriminatorKey, required Map<String, AckSchema> schemas})`: Creates a discriminated union schema. | ||||||
| - `Ack.discriminated({required String discriminatorKey, required Map<String, AckSchema<MapValue>> schemas})`: Creates a discriminated union schema. | ||||||
|
|
||||||
| ## `AckSchema<T>` (Base Class) | ||||||
|
|
||||||
|
|
@@ -285,7 +285,7 @@ Schema for union types (value must match one of several schemas). | |||||
|
|
||||||
| Schema for polymorphic validation based on a discriminator field. | ||||||
|
|
||||||
| - Created using `Ack.discriminated({required String discriminatorKey, required Map<String, AckSchema> schemas})` | ||||||
| - Created using `Ack.discriminated({required String discriminatorKey, required Map<String, AckSchema<MapValue>> schemas})` | ||||||
|
||||||
| - Created using `Ack.discriminated({required String discriminatorKey, required Map<String, AckSchema<MapValue>> schemas})` | |
| - Created using `Ack.discriminated({required String discriminatorKey, required Map<String, AckSchema<Map<String, Object?>>> schemas})` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import 'package:ack_example/schema_types_primitives.dart'; | ||
| import 'package:ack_example/schema_types_simple.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| group('Extension type toJson', () { | ||
| test('object extension type returns map data', () { | ||
| final user = UserType.parse({'name': 'Alice', 'age': 30, 'active': true}); | ||
|
|
||
| expect(user.toJson(), {'name': 'Alice', 'age': 30, 'active': true}); | ||
| expect(user.toJson(), isA<Map<String, Object?>>()); | ||
| }); | ||
|
|
||
| test('primitive extension type returns wrapped value', () { | ||
| final password = PasswordType.parse('mySecurePassword123'); | ||
|
|
||
| expect(password.toJson(), 'mySecurePassword123'); | ||
| expect(password.toJson(), isA<String>()); | ||
| }); | ||
|
|
||
| test('collection extension type returns wrapped list', () { | ||
| final tags = TagsType.parse(['dart', 'ack']); | ||
|
|
||
| expect(tags.toJson(), ['dart', 'ack']); | ||
| expect(tags.toJson(), isA<List<String>>()); | ||
| }); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs now mention
AckSchema<MapValue>, butMapValueisn’t introduced/explained on this page and (from the public exports) may not be importable by consumers without reaching intosrc/. Consider documenting it (and how users should reference it) or keep the signature in docs asMap<String, AckSchema<Map<String, Object?>>>/Map<String, AckSchema<Map<String, Object?>>>to avoid exposing an internal alias.