Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions docs/api-reference/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ Entry point for creating schemas. See [Schema Types](../core-concepts/schemas.md
- `Ack.any()`: Creates an `AnySchema` that accepts any non-null JSON-safe
value. Chain `.nullable()` to allow `null`.
- `Ack.fromJsonSchema(Object document, {Uri? baseUri, Map<Uri, Object>
documents = const {}})`: Strictly imports a decoded draft 2020-12
JSON Schema. Referenced documents must be supplied explicitly; Ack never
fetches files or URLs. The supported `date-time` format is asserted; see
[format import](../guides/json-schema-integration.mdx#importing-format).
documents = const {}, bool assertFormats = false})`: Imports a decoded draft 2020-12 JSON
Schema. Referenced documents must be supplied explicitly; Ack never fetches
files or URLs. Formats are annotations unless assertions are enabled.
- `Ack.map(AckSchema valueSchema)`: Creates a `MapSchema` for a JSON object
with arbitrary string keys whose values all match `valueSchema`. Use
`Ack.map(Ack.any().nullable())` for a `JsonMap`.
Expand Down Expand Up @@ -121,10 +120,16 @@ For non-`num` boundary types (e.g. numeric strings), use

### Utility Methods

- `Map<String, Object?> toJsonSchema()`: Returns a Draft-7 JSON Schema map via
the canonical `AckSchemaModel` boundary.
- `Map<String, Object?> toJsonSchema()`: Returns a JSON Schema representation
via the canonical `AckSchemaModel` boundary, preserving imported Draft 2020-12
resources by default and emitting Draft-7 for native schemas.
- `Map<String, Object?> toJsonSchemaDraft7()`: Exports imported schemas using
the legacy Draft-7 `definitions` / `$ref` lowering when possible.
- `AckSchemaModel toSchemaModel()`: Returns the canonical, target-independent
boundary model for schema adapters, including export warnings.
boundary model for schema adapters, preserving imported Draft 2020-12
resources by default.
- `AckSchemaModel toSchemaModelDraft7()`: Returns the matching model for the
legacy Draft-7 lowering.
- `Map<String, Object?> toMap()`: Serializes the schema for debugging.

See also [Schema Types](../core-concepts/schemas.mdx) for detailed usage examples.
Expand Down Expand Up @@ -499,7 +504,7 @@ Canonical export model for Ack schemas.

- Created by `schema.toSchemaModel()`.
- Represents the boundary/export shape, JSON-compatible defaults, discriminator metadata, target-independent constraints, and export warnings.
- `schema.toSchemaModel().toJsonSchema()` returns the same Draft-7 map as `schema.toJsonSchema()`.
- `schema.toSchemaModel().toJsonSchema()` returns the same JSON Schema map as `schema.toJsonSchema()`. Use `toSchemaModelDraft7()` for legacy Draft-7 lowering of imported schemas.
- Adapters that need a JSON map should call `schema.toJsonSchema()`; adapters for non-JSON targets should convert from `AckSchemaModel` rather than traversing `AckSchema` subclasses directly.

### `AnySchema`
Expand Down
8 changes: 8 additions & 0 deletions packages/ack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

### Added

* `Ack.fromJsonSchema()` now validates and round-trips the complete required
Draft 2020-12 test suite, including dynamic references, unevaluated keywords,
and offline standard meta-schemas. `assertFormats: true` enables optional
format assertions.
* `toJsonSchema()` and `toSchemaModel()` now preserve imported Draft 2020-12
resources by default. `toJsonSchemaDraft7()` and `toSchemaModelDraft7()`
retain the legacy 1.x Draft-7 lowering for imported schemas when compatible;
imports that require 2020-12-only semantics reject Draft-7 lowering explicitly.
* `Ack.fromJsonSchema()` now supports `multipleOf` for `number` and `integer`
schemas. Non-positive or non-numeric `multipleOf` values fail import with an
`invalid_schema` diagnostic.
Expand Down
8 changes: 6 additions & 2 deletions packages/ack/lib/src/ack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ final class Ack {
///
/// [document] must be a map or boolean, not a JSON string. Referenced
/// [documents] are supplied by retrieval URI; no files or URLs are fetched.
/// The supported `date-time` format is asserted. Other formats remain
/// unsupported. Unsupported semantics throw [JsonSchemaImportException].
/// [assertFormats] opts into format assertions under the standard dialect;
/// a supplied dialect requiring the format-assertion vocabulary also enables
/// them. Unknown asserted formats are rejected when compiling.
/// Unsupported semantics throw [JsonSchemaImportException].
static AckSchema<Object, Object> fromJsonSchema(
Object document, {
Uri? baseUri,
Map<Uri, Object> documents = const {},
bool assertFormats = false,
}) => ImportedJsonSchema.fromDocument(
document,
baseUri: baseUri,
documents: documents,
assertFormats: assertFormats,
);

/// Creates a string schema. Boundary and runtime are both `String`.
Expand Down
Loading
Loading