Skip to content

Check minProperties and maxProperties on inline map properties - #175

Merged
cubahno merged 1 commit into
mainfrom
ig/check-map-prop-cnt
Oct 14, 2026
Merged

cubahno merged 1 commit into
mainfrom
ig/check-map-prop-cnt

Conversation

@cubahno

@cubahno cubahno commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

A required object property with additionalProperties accepted a missing value, null or too many keys, and minProperties / maxProperties were never checked on it.
Only a named map type checked its size, in its own Validate().
An inline map has no Validate() of its own and the struct holding it only checked the values, so the bounds were ignored, whether in a request body property or a response property under response validation.
It is the map counterpart of #168 for arrays.

What changes
A struct's Validate() checks the number of keys of each inline map property against minProperties and maxProperties, the way a named map type checks its own: Labels must have at least 1 properties, got 0.

A map that wasn't sent is nil. A required map that isn't nullable fails minProperties (nil is zero keys), as a named map type already does, while an optional or nullable one passes. A property that is only readOnly or writeOnly isn't treated as required, as elsewhere.

A struct whose only constraint is a property count now gets a Validate(), and one that used validator.Struct() moves to per-field checks. Values bound by a pattern or Validate() are still checked after the count.
A required map with no minProperties is still not rejected when missing: object types are left to Validate() and carry no required tag. That is unchanged.

make generate changes only examples/requests/array-item-counts, which now covers missing, null, empty and oversized maps, and an optional map that is empty.

Fixes the bug found while checking #171.

@cubahno
cubahno marked this pull request as ready for review October 14, 2026 10:43
@cubahno
cubahno merged commit 0b6b433 into main Oct 14, 2026
3 checks passed
@cubahno
cubahno deleted the ig/check-map-prop-cnt branch October 14, 2026 10:46
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.

1 participant