Skip to content

JSON Schema: consolidate reference rewriting, table lookups, and constraint encoding #276

Backlog

Description

@leoafarias

Follow-up to the 2.0.0 release-readiness PR #271. Do this after the 2.0.0 PRs merge. Each item is internal: exported JSON, validation results, and the public API must stay the same. Paths are under packages/ack/lib/src; search by symbol because line numbers will move.

Duplicated logic

  • Three $ref-rewriting passes: _relocateRootPointers (schema_model/ack_schema_model.dart), _shareImportedResources with _mapImportedChildren (schema_model/ack_schema_model_builder.dart), and the reference loop in export2020Document (schemas/imported_json_schema.dart). Each walks indexed schemas, tracks the $id base, tolerates FormatException, and rewrites. One helper taking (root, indexed, base, rewrite) covers all three. Keep: only indexed maps are edited, malformed $id/$ref values stay as they are, and $schema is rewritten only in the export pass.
  • Four copies of one binary search in the generated Unicode tables (json_schema/unicode_bidi.dart, unicode_contextj.dart, unicode_idna.dart, unicode_idna_scripts.dart), and _isIdnaMark is a linear scan. Use one generic range lookup; update the generators under scripts/generate_unicode_*.dart.
  • _jsonInstanceHashCode (constraints/list_unique_items_constraint.dart) duplicates deepHashCode now that equality uses deepEquals. Use LinkedHashSet(equals: deepEquals, hashCode: deepHashCode), as the compiler already does for enum. Keep 1 == 1.0 and key-order independence.
  • _copyImportJson (json_schema/json_schema_compiler.dart) duplicates the JSON copy mode of the collection walker, apart from the depth bound.
  • _warningsAt re-derives the nullable and composition rendering layout separately from _finishTypeJson and _finishCompositionJson. Share one child-pointer helper so warning paths cannot drift from the export.

Simpler constraint encoding

  • ComparisonConstraint: multipleOf is encoded as eq plus multipleValue plus key checks in three places, and _categorize guesses the category from key prefixes. Let each factory pass its JSON Schema keywords. Two branches are dead: the default multipleOf message (a custom builder is always set) and numeric eq → const (no factory creates it).
  • PatternConstraint: the PatternType.format empty-map fallback is dead.

Performance

  • _isHostname and _isEmail (json_schema/json_schema_formats.dart) build their RegExps on every call, and once per label. Make them static finals.

Done when

The duplicates above are gone, cd packages/ack && dart test and the CI Chrome conformance list pass unchanged, the official format suite results are unchanged on the VM and in Chrome, and dart scripts/api_check.dart reports no API change.


Generated by Claude Code

Activity

  1. added
    enhancement
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions