Add maxDepth support to lazy schemas#122
Conversation
Make LazySchema.maxDepth non-nullable with a 100-level default cap instead of unlimited recursion, validate it's >= 1 at construction, and bump the package to 1.0.1 with a link-only changelog entry.
There was a problem hiding this comment.
Pull request overview
Adds recursion-depth bounding to Ack.lazy / LazySchema to prevent unbounded recursive parse/validate/encode by enforcing a maxDepth limit, and updates schema-model export metadata/tests accordingly.
Changes:
- Add
maxDepth(defaulted) toLazySchemaand expose it viaAck.lazy(..., {maxDepth}), enforcing a depth check during parse, runtime validation, and encode. - Preserve
maxDepthacross fluent copies,toMap, equality/hashCode, and schema-model runtime-check warning counts. - Add/adjust tests for maxDepth behavior and bump
ackversion + changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ack/lib/src/schemas/lazy_schema.dart | Implements maxDepth storage + enforcement and includes it in schema metadata/equality. |
| packages/ack/lib/src/ack.dart | Extends Ack.lazy API/docs to accept maxDepth and explains export warning behavior. |
| packages/ack/test/schemas/lazy_schema_test.dart | Updates warning-count expectation and adds maxDepth-focused tests. |
| packages/ack/pubspec.yaml | Bumps package version. |
| packages/ack/CHANGELOG.md | Adds a new release entry for the bumped version. |
| name: ack | ||
| description: A simple validation library for Dart | ||
| version: 1.0.0 | ||
| version: 1.0.1 |
There was a problem hiding this comment.
Good catch — the PR description was stale from an earlier draft. Updated it to say 1.0.1 (matching pubspec.yaml and CHANGELOG.md, both already correct).
| /// Default recursion cap applied to `Ack.lazy` schemas that do not | ||
| /// specify their own [maxDepth]. | ||
| static const defaultMaxDepth = 100; | ||
|
|
There was a problem hiding this comment.
Confirmed intentional, not a bug: the 100-level cap is now the default for every Ack.lazy schema, with no unlimited/uncapped opt-out — that's a deliberate design decision for this PR (not a regression to fix). Updated the PR description to describe this default-cap behavior accurately instead of the old 'uncapped unless configured' wording.
Summary
maxDepthsupport toAck.lazyandLazySchemafor bounded recursive parse, runtime validation, and encode paths.Ack.lazyschema now defaults to aLazySchema.defaultMaxDepthcap of100; pass a custommaxDepth(>= 1) to override it. There is no unlimited/uncapped opt-out.maxDepththrough fluent copies, equality, hashing, runtime constraint counts, and schema maps.ackto1.0.1and documents the change with a link-only changelog entry, matching the1.0.0entry's style.Validation
dart test test/schemas/lazy_schema_test.dartdart analyze . --fatal-infosgit diff --check