Repository navigation
Check minProperties and maxProperties on inline map properties - #175
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.
A required object property with
additionalPropertiesaccepted 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 againstminPropertiesandmaxProperties, 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 usedvalidator.Struct()moves to per-field checks. Values bound by a pattern orValidate()are still checked after the count.A required map with no
minPropertiesis still not rejected when missing: object types are left toValidate()and carry no required tag. That is unchanged.make generatechanges onlyexamples/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.