Repository navigation
Check minItems and maxItems on inline arrays - #168
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.
With request validation on, an inline array query parameter checked
maxLengthon each item but ignored the array'smaxItems, so 11termvalues reached the service although the schema allows 10.Only a named array schema checked its item count, in its own
Validate(). An inline array has noValidate()of its own, and the struct holding it only checked the items, sominItemsandmaxItemswere never enforced on an inline array, whether a query parameter, a request body property or a response property under response validation.What changes
Validate()checks the length of each inline array property and parameter it holds, the way a named array type checks its own. The request from the issue is now a 400,Query.Term must have at most 10 items, got 11, and doesn't reach the service. This includes an array declared in a component parameter, whose alias (type Terms = []string) has noValidate()either.minItems; an empty one that was sent doesn't.minItems: 0generates nothing.Validate(), and one that usedvalidator.Struct()moves to per-field checks, since no validator tag expresses an item count.required, are checked exactly as before. Named array types, arrays referenced through$refand arrays of inline objects, which already get a named type, generate as before. Across the 454 real-world specs that useminItemsormaxItems, onlyValidate()methods change, in 292 of them, and the output builds.simplevalidation still runsvalidator.Struct()on structs, so it doesn't check item counts. The validation docs saidminItemsandmaxItemsmap tomin/maxtags, which was never the case; they now describe the length checks.Fixes #164