Skip to content

Add maxDepth support to lazy schemas#122

Merged
leoafarias merged 2 commits into
mainfrom
fix/max-depth
Jul 4, 2026
Merged

Add maxDepth support to lazy schemas#122
leoafarias merged 2 commits into
mainfrom
fix/max-depth

Conversation

@leoafarias

@leoafarias leoafarias commented Jul 4, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds maxDepth support to Ack.lazy and LazySchema for bounded recursive parse, runtime validation, and encode paths.
  • Every Ack.lazy schema now defaults to a LazySchema.defaultMaxDepth cap of 100; pass a custom maxDepth (>= 1) to override it. There is no unlimited/uncapped opt-out.
  • Returns a schema constraint error when the active lazy-schema recursion depth exceeds the configured cap.
  • Preserves maxDepth through fluent copies, equality, hashing, runtime constraint counts, and schema maps.
  • Bumps ack to 1.0.1 and documents the change with a link-only changelog entry, matching the 1.0.0 entry's style.

Validation

  • dart test test/schemas/lazy_schema_test.dart
  • dart analyze . --fatal-infos
  • git diff --check

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) to LazySchema and expose it via Ack.lazy(..., {maxDepth}), enforcing a depth check during parse, runtime validation, and encode.
  • Preserve maxDepth across fluent copies, toMap, equality/hashCode, and schema-model runtime-check warning counts.
  • Add/adjust tests for maxDepth behavior and bump ack version + 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.

Comment thread packages/ack/pubspec.yaml
name: ack
description: A simple validation library for Dart
version: 1.0.0
version: 1.0.1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines +12 to +15
/// Default recursion cap applied to `Ack.lazy` schemas that do not
/// specify their own [maxDepth].
static const defaultMaxDepth = 100;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@leoafarias
leoafarias merged commit 527cd4f into main Jul 4, 2026
2 checks passed
@leoafarias
leoafarias deleted the fix/max-depth branch July 4, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants