feat(ack): import JSON Schema pattern and propertyNames - #158
Merged
Merged
Conversation
Ack.fromJsonSchema() now compiles the `pattern` and `propertyNames` keywords. `pattern` is stored as its raw source string and applied to strings only as an unanchored ECMA-262 search, and is rejected at import time when it is not a valid regular expression string. `propertyNames` validates every key of an object instance against its subschema. Ack already emitted both keywords from `Ack.string().matches(...)` and from keyed maps, so until now it could not re-import its own export. The generic Draft-7 renderer needs no change: `pattern` round-trips as its raw string and `propertyNames` as a `$ref`, so the export path is untouched. The pinned upstream conformance selection grows to 186 groups / 631 instance cases. The one upstream `pattern` group requiring unicode mode stays out, since Dart's default RegExp does not match it. Also documents that the dialect gate only inspects the declared `$schema` string, and names the two Draft-7 shapes that do not survive the swap. No public API change: `dart scripts/api_check.dart ack v1.6.1` reports no changes. Versioning is left to the coordinated release PR.
The excluded upstream group is a semantic deviation, not an unsupported keyword: its schema imports cleanly and only the match result differs. Recording it in the fixture README and the guide keeps it from reading as a silent skip, which that README forbids.
leoafarias
deleted the
feat/json-schema-import-pattern-property-names
branch
September 22, 2026 23:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Ack.fromJsonSchema()now compiles thepatternandpropertyNameskeywords.pattern— stored as its raw source string and applied to strings only, as an unanchored ECMA-262 search (JSON Schema §6.3.3, the same semanticsPatternConstraint.regexalready uses). Rejected at import time when it is not a valid regular expression string, matching the existing "rejects malformed supported keywords" contract.propertyNames— validates every key of an object instance against its subschema. Type-specific as usual: skipped, never failed, for non-objects.The implementation stays within the existing compiler and validator. No new public API or
fromJsonSchemaoption, and no change torender.Why
Ack already emitted
patternfromAck.string().matches(...), but could not read it back:Ack.fromJsonSchema(schema.toJsonSchema())threw on that native output.propertyNamesis a standard keyword in external schemas that the importer also lacked. NativeAck.map(valueSchema)exportsadditionalProperties; it does not emitpropertyNames. This change closes the nativepatternround-trip hole and adds strict import support forpropertyNames.The concrete driver:
mix_protocolpublishes Draft-7 schemas exported from Ack and validates them with an independent Node/Ajv job. All four of its suites failed to re-import onpattern. With this change all 284 checked-in fixture documents import and agree with Ajv on every accept/reject verdict in that set, 0 mismatches. This is fixture-specific: default Ajv enables the Unicodeuflag, while Ack's default DartRegExpdoes not. For example, `^.### DescriptionAck.fromJsonSchema()now compiles thepatternandpropertyNameskeywords.pattern— stored as its raw source string and applied to strings only, as an unanchored ECMA-262 search (JSON Schema §6.3.3, the same semanticsPatternConstraint.regexalready uses). Rejected at import time when it is not a valid regular expression string, matching the existing "rejects malformed supported keywords" contract.propertyNames— validates every key of an object instance against its subschema. Type-specific as usual: skipped, never failed, for non-objects.The implementation stays within the existing compiler and validator. No new public API or
fromJsonSchemaoption, and no change torender.Why
Ack already emitted
patternfromAck.string().matches(...), but could not read it back:Ack.fromJsonSchema(schema.toJsonSchema())threw on that native output.propertyNamesis a standard keyword in external schemas that the importer also lacked. NativeAck.map(valueSchema)exportsadditionalProperties; it does not emitpropertyNames. This change closes the nativepatternround-trip hole and adds strict import support forpropertyNames.The concrete driver:
mix_protocolpublishes Draft-7 schemas exported from Ack and validates them with an independent Node/Ajv job. All four of its suites failed to re-import onpattern. has a different verdict for😀. Test patterns in both validators when cross-runtime agreement is required.Export
Unchanged, deliberately.
_ImportedNode.renderalready emitskeywordsverbatim and everychildrenentry as a$ref, sopatternround-trips as its raw string andpropertyNamesas a$ref. Draft-7 supports both, so re-import of the export is lossless with zero export code.Tests
80c87e8fca8b207a7a7ae944b875f0fcf889f46aof the upstream suite, keeping the existing conventions.json_schema_import_conformance_test.dartneeded no edit — it already asserts parse, encode, and re-import-of-export for every case.pattern with Unicode property escape requires unicode mode. Dart's defaultRegExpdoes not match\p{Letter}the way that group expects, so it is represented by absence rather than a silent skip, per the fixture README's rule.patternrejection, behaviour + export shape + re-import, and thepropertyNameserror path and offending key value.Versioning
None.
version:stays at 1.6.1 and the changelog entry sits under## Unreleased, perPUBLISHING.md— the coordinated release PR picks the number and bumps all six packages together.dart scripts/api_check.dart ack v1.6.1reports no public API changes.Verification
On commit
a87ad707, all PR checks passed: