Repository navigation
Check the pattern of array items - #172
Merged
Merged
Conversation
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.
An array whose items
$refa string schema with a pattern skipped that pattern, while the same $ref used as a property was checked.{"one":"a:1","refs":["bad"]}passed validation.A referenced primitive is generated as an alias (type ItemID = string), which has no Validate() of its own, and the struct treated its items as needing no validation, so neither the pattern nor the Validate() fallback ran.
What changes
A struct's
Validate()now checks the pattern of each array item and map value that references a primitive schema, the same way it does for an inline item schema.The request above fails with Refs[0] in the error.
Map values (
additionalProperties: {$ref: ...}) had the same gap and are fixed too.An array property that also has its own validation tags, such as required, now has them checked in the same Validate().
Before, an array whose items were validated lost its own required check; this only mattered for inline items with a pattern or Validate(), and would have started to matter for referenced ones with this fix.
One example changes as a result:
examples/circular/mutualnow checks required onFile_Links.Data.A referenced primitive without a pattern is unchanged: no per-item check is generated.
Other constraints on a referenced primitive item (e.g. minLength) are still not checked per item; only the pattern is in scope here.
Fixes #169