Repository navigation
Conversation
Length limits were parsed but omitted when body parameters became schema properties. Copy string and array bounds during conversion and cover POST, PUT, PATCH, nested objects, and zero minimums with regression tests.
Danger ReportNo issues found. |
The array path in MoveParams kept its own inline key list next to the shared property_keys, so a new keyword has to be remembered in two spots. Naming the array keys puts both lists side by side. The specs now cover arrays of objects and assert the nested properties exactly. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The keys belong to the array schema itself, while property_keys is also used to build the array's items, so the old name suggested the opposite split.
numbata
marked this pull request as ready for review
October 26, 2026 11:46
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.
Summary
Length limits that API authors declare on JSON body fields, such as a name capped at 50 characters or a list capped at three entries, were missing from the generated Swagger document, so consumers could not see the rules the API actually enforces. This change publishes those limits for string and array fields in request bodies, including fields inside nested objects and arrays of objects. API owners do not need to change any declarations; the limits appear after regenerating the documentation.
Root cause
grape-swagger already extracts the limits correctly. When a Grape param declares
length: { min:, max: },ParseParamsemitsminLength/maxLengthfor strings andminItems/maxItemsfor arrays. For POST, PUT and PATCH,MoveParamsthen moves body params out ofparametersand rebuilds them as a schema underdefinitions. That rebuild copies keys through an allowlist and silently drops everything not on it, and the four length keys were not on it. Query and path params never go through this step, which is why only body fields lost their limits. Fixes #1010.What changes
minLengthandmaxLengthare added to the keys copied onto string properties in a body definition.minItemsandmaxItemsare copied onto the array schema itself, where they describe the number of entries. They are not copied ontoitems, so an item-count limit never turns into a per-string character limit.min: 0) are kept; the keys are copied by presence, not truthiness.Array[JSON]with a block) get the same treatment, because they go through the same conversion.array_schema_keysmethod next toproperty_keys, so both allowlists are visible in one place.Benefits
length:declarations, so there is a single source of truth and nothing to repeat indocumentation:options.Drawbacks and nuances
minLength/maxLength/minItems/maxItemsentries. Schema-aware tools may begin enforcing limits that were previously absent from the document, and how they do so is up to each tool. API owners should review regenerated artifacts and schema snapshots when upgrading.ParseParamsmay add in the future (for examplepatternoruniqueItems) still need to be added to the allowlists by hand. This PR makes those lists easier to find but does not remove the need to maintain them.$refand, with this change, also any length keys on the same object. Swagger 2.0 ignores siblings of$ref, so those keys have no effect there. Puttinglength:on an entity-typed param is unusual, anddescriptionalready behaves the same way.move_methods, but DELETE bodies are rare and are not exercised.Alternatives considered
in,name,required, and so on), changing output well beyond the four limits. It is a larger behavior change than this fix warrants.items. Merging them would risk putting item counts onitemsor character limits on the array. Keeping the array keys in a named method next to the property keys keeps the distinction while making both lists easy to find.documentation:options. This duplicates information that is already declared and would leave every existing API with the gap.