You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api-reference/index.mdx
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ This page provides a quick reference for the core Ack classes, methods, and anno
6
6
7
7
## Core `Ack` Class
8
8
9
-
Entry point for creating schemas. See [Schema Validation](../core-concepts/typesafe-schemas.mdx).
9
+
Entry point for creating schemas. See [Schema Types](../core-concepts/schemas.mdx).
10
10
11
11
-`Ack.string()`: Creates a `StringSchema` for validating strings.
12
12
-`Ack.integer()`: Creates an `IntegerSchema` for validating integers.
@@ -54,7 +54,7 @@ Base class for all schema types.
54
54
-`Map<String, Object?> toJsonSchema()`: Converts the schema to a JSON Schema Draft-7 representation.
55
55
-`Map<String, Object?> toMap()`: Serializes the schema for debugging.
56
56
57
-
See also [Schema Validation](../core-concepts/typesafe-schemas.mdx) for detailed usage examples.
57
+
See also [Schema Types](../core-concepts/schemas.mdx) for detailed usage examples.
58
58
59
59
## `StringSchema`
60
60
@@ -107,6 +107,8 @@ Schemas for validating numbers. See [Number Validation](../core-concepts/validat
107
107
108
108
-`min(num limit)`: Minimum value (inclusive)
109
109
-`max(num limit)`: Maximum value (inclusive)
110
+
-`greaterThan(num limit)`: Must be greater than limit (exclusive)
111
+
-`lessThan(num limit)`: Must be less than limit (exclusive)
110
112
-`positive()`: Must be greater than 0
111
113
-`negative()`: Must be less than 0
112
114
-`multipleOf(num factor)`: Must be a multiple of the factor
@@ -121,9 +123,10 @@ Schema for validating booleans. Validates `true` and `false` values, with option
121
123
122
124
Schema for validating arrays. See [List Validation](../core-concepts/validation.mdx#list-constraints).
123
125
124
-
-`minLength(int min)`: Minimum number of items
125
-
-`maxLength(int max)`: Maximum number of items
126
-
-`length(int exact)`: Exact number of items
126
+
-`minItems(int min)`: Minimum number of items (alias: `minLength`)
127
+
-`maxItems(int max)`: Maximum number of items (alias: `maxLength`)
128
+
-`exactLength(int exact)`: Exact number of items (alias: `length`)
129
+
-`nonEmpty()`: List must have at least one item (alias: `notEmpty`)
127
130
-`unique()`: All items must be unique
128
131
129
132
## `ObjectSchema`
@@ -137,6 +140,7 @@ Schema for validating objects (maps). See [Object Validation](../core-concepts/s
137
140
- Use `.partial()` to make all properties optional.
138
141
- Use `.strict()` to disallow additional properties.
139
142
- Use `.passthrough()` to allow additional properties not defined in the schema.
143
+
- Use `.merge(ObjectSchema other)` to combine with another object schema.
140
144
141
145
## `SchemaResult<T>`
142
146
@@ -177,7 +181,7 @@ combinators.
177
181
178
182
## Code Generation Annotations
179
183
180
-
Use the [`ack_generator`](../../packages/ack_generator/README.md) builder to
184
+
Use the [`ack_generator`](https://pub.dev/packages/ack_generator) builder to
181
185
turn annotations into ready-to-use schemas and extension types. After adding
182
186
the annotations below, run:
183
187
@@ -189,11 +193,9 @@ dart run build_runner build
189
193
190
194
**Target**: Dart classes
191
195
192
-
**Generates**: Both a schema constant AND an extension type
196
+
**Generates**: A schema constant only
193
197
194
-
Annotate a Dart class to automatically generate a validation schema and a strongly typed extension type. The generator analyzes your class fields and creates:
195
-
- A schema constant named `<className>Schema` (e.g., `userSchema`)
196
-
- An extension type named `<ClassName>Type` (e.g., `UserType`)
198
+
Annotate a Dart class to automatically generate a validation schema. The generator analyzes your class fields and creates a schema constant named `<className>Schema` (e.g., `userSchema`).
197
199
198
200
**Parameters:**
199
201
-`schemaName`: Custom name for the generated schema constant
@@ -215,11 +217,13 @@ class User {
215
217
216
218
// Generated:
217
219
// - final userSchema = Ack.object({...});
218
-
// - extension type UserType(Map<String, Object?> _data) { ... }
219
220
220
221
// Usage:
221
-
final user = UserType.parse({'name': 'Alice', 'age': 30});
222
-
print(user.name); // Type-safe String access
222
+
final result = userSchema.safeParse({'name': 'Alice', 'age': 30});
223
+
if (result.isOk) {
224
+
final data = result.getOrThrow();
225
+
print(data['name']); // 'Alice'
226
+
}
223
227
```
224
228
225
229
### `@AckType()`
@@ -295,4 +299,4 @@ Every schema can be marked optional through the `optional({bool value = true})`
295
299
- Use `schema.optional(value: false)` to clear the optional flag.
296
300
- Optional affects object-field presence only; combine with `.nullable()` to also allow explicit `null`.
297
301
298
-
*Refer to the [Schema Validation](../core-concepts/typesafe-schemas.mdx) guide for detailed usage and examples.*
302
+
*Refer to the [Schema Types](../core-concepts/schemas.mdx) guide for detailed usage and examples.*
Copy file name to clipboardExpand all lines: docs/core-concepts/configuration.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,9 +95,9 @@ final signUpSchema = Ack.object({
95
95
96
96
## Code Generation Configuration
97
97
98
-
The `ack_generator` package provides automatic schema generation from annotated classes. This feature is production-ready and available at version 1.0.0-beta.1 and later.
98
+
The `ack_generator` package provides automatic schema generation from annotated classes. This feature is production-ready.
99
99
100
-
To use code generation, annotate your classes with `@AckModel`. The generator creates both a validation schema and a type-safe extension type. Use `@AckField` for field-level constraints:
100
+
To use code generation, annotate your classes with `@AckModel`. The generator creates a validation schema from your class structure. Use `@AckField` for field-level constraints:
Copy file name to clipboardExpand all lines: docs/core-concepts/typesafe-schemas.mdx
+12-20Lines changed: 12 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,14 @@ produce these typed views.
9
9
10
10
## Overview
11
11
12
-
-`@AckModel()` goes on a **Dart class** and produces **both** a schema constant (e.g., `userSchema`)**and** an extension type named `<ClassName>Type`.
13
-
-`@AckType()` goes on a **schema variable/getter** and produces **only**an extension type (the schema already exists). The type name is derived from the variable name (e.g., `userSchema` → `UserType`).
12
+
-`@AckModel()` goes on a **Dart class** and produces a **schema constant** (e.g., `userSchema`).
13
+
-`@AckType()` goes on a **schema variable/getter** and produces an **extension type**for type-safe access (the schema already exists). The type name is derived from the variable name (e.g., `userSchema` → `UserType`).
14
14
- Both annotations live in `package:ack_annotations` and are processed by the
15
15
`ack_generator` builder via `dart run build_runner build`.
16
16
17
-
## Typed Schemas from Classes with `@AckModel()`
17
+
## Schema Generation from Classes with `@AckModel()`
18
18
19
-
Use `@AckModel()` when you have a Dart class that should drive schema generation. The generator creates both the validation schema and a typed wrapper.
19
+
Use `@AckModel()` when you have a Dart class that should drive schema generation. The generator creates a validation schema based on your class structure.
|`@AckModel`| Dart class | ✅ Yes |✅ Yes| You have a class definition and want both validation and typed access|
149
-
|`@AckType`| Schema variable | ❌ No (uses existing) | ✅ Yes | You already wrote the schema manually and just want typed access |
140
+
|`@AckModel`| Dart class | ✅ Yes |❌ No| You have a class definition and want schema generation|
141
+
|`@AckType`| Schema variable | ❌ No (uses existing) | ✅ Yes | You have a schema and want type-safe access |
150
142
151
143
**Examples:**
152
144
153
-
- Use **`@AckModel`** when you have a Dart class (or class hierarchy) that should drive schema generation. The generator creates both the schema and the extension type.
145
+
- Use **`@AckModel`** when you have a Dart class (or class hierarchy) that should drive schema generation.
154
146
155
-
- Use **`@AckType`**for hand-written schemas, shared schema fragments, or when you need typed access to a structure that doesn't have a corresponding Dart class.
147
+
- Use **`@AckType`**on schema variables (either hand-written or generated by `@AckModel`) when you want type-safe extension type access.
156
148
157
-
-**Mix both**: You can reference a `@AckType` schema inside an `@AckModel` class field, or use `@AckModel` classes within `@AckType` schema definitions.
149
+
-**Combine both**: Use `@AckModel` to generate the schema from your class, then use `@AckType` on the generated schema variable if you want extension type wrappers.
0 commit comments