fix(schema): handle constraints that reduce to root nodes#1567
Merged
ssalbdivad merged 2 commits intoarktypeio:mainfrom Dec 21, 2025
Merged
fix(schema): handle constraints that reduce to root nodes#1567ssalbdivad merged 2 commits intoarktypeio:mainfrom
ssalbdivad merged 2 commits intoarktypeio:mainfrom
Conversation
ssalbdivad
approved these changes
Dec 21, 2025
Member
ssalbdivad
left a comment
There was a problem hiding this comment.
Hey this is great! Hadn't considered how these constraints within ArkType would affect parsing from JSON Schema- thanks for the fix!
ssalbdivad
pushed a commit
to shaungrady/arktype
that referenced
this pull request
Dec 21, 2025
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.
Fixes minLength: 0 (and similar trivially-satisfied constraints) causing parse errors when used in JSON schemas.
Example JSON Schema:
The
minLength reducercorrectly identifies a minLength of 0 as trivially satisfied and returns$ark.intrinsic.unknownHowever,
constraintKeyParserdidn't really account for the possibility that we might be dealing with a root node after the reducer's done its thing, instead treating it as a constraint. It would then be added to the intersection schema as 'intersection', which is invalid.This PR changes
constraintKeyParserto returnundefinedwhen constraints are trivially satisfied, ultimately removing them from the generated schema.The test suite then caught another bug and perhaps an implicit workaround for that bug.
pipe.test.tscontains a test that looks for the following error:Of note is the whitespace after
stringinLeft:that isn't there inRight:This is addressed in the change to
ark/schema/roots/intersection.tsAnd, because that change made the above test fail, I've updated the expected error message in that test.
Finally, I've added a test to the
json-schemasuite to ensure that a string-type schema can accept aminLengthof 0mainbranchpnpm prCheckslocally