Skip to content

Check the pattern of array items - #172

Merged
cubahno merged 1 commit into
mainfrom
ig/check-arr-pattern
Oct 14, 2026
Merged

cubahno merged 1 commit into
mainfrom
ig/check-arr-pattern

Conversation

@cubahno

@cubahno cubahno commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

An array whose items $ref a 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/mutual now checks required on File_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

@cubahno
cubahno marked this pull request as ready for review October 14, 2026 08:10
@cubahno
cubahno merged commit 1e59da9 into main Oct 14, 2026
3 checks passed
@cubahno
cubahno deleted the ig/check-arr-pattern branch October 14, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Array items with $ref to a primitive schema skip pattern validation

1 participant