Repository navigation
Preserve length limits in body parameter definitions and map them by type - #1011
Merged
Merged
Conversation
numbata
added a commit
that referenced
this pull request
Oct 26, 2026
Danger ReportNo issues found. |
numbata
added a commit
that referenced
this pull request
Nov 3, 2026
## Summary The Danger check that runs on every pull request fails in CI before it reviews anything, so contributors get no automated feedback. This change keeps the bundle on a version of the `git` library that Danger can load, so the check runs again. Contributors and maintainers need no change to their workflow. ## Root cause CI runs `bundle exec danger`. With no upper bound on `git`, the bundle resolves `git` 6, which removed the `Git::Base` constant. Danger 9.6.1 references that constant while it loads (`scm_source/git_repo.rb:209`), so the job exits with `uninitialized constant Git::Base` before any pull request is checked. See the failing run on #1011: https://github.com/ruby-grape/grape-swagger/actions/runs/41628597475/job/125892119818 ## What changes `git` is capped below 6 in the `test` group of the Gemfile, next to `danger`, with a comment explaining why. The gem is only used by Danger, so the constraint does not reach the gem's runtime or the supported Grape and Ruby matrix. ## Drawbacks and nuances - The cap needs lifting once a Danger release supports `git` 6. The fix is in progress upstream (danger/danger#1560, with the proposed fix in danger/danger#1561), but it is neither merged nor released; the latest release, 9.6.1, still fails. Until then the cap holds the dependency back on purpose. - The `Gemfile` is not locked in this repo, so the cap takes effect on the next resolution in CI. ## Alternatives considered - **Wait for a Danger release that supports `git` 6.** This leaves the check broken for every open PR in the meantime, with no release date to plan around. - **Point `danger` at the upstream fix branch.** Depending on an unreviewed, unmerged pull request from a fork would be less stable than a one-line cap. - **Pin `danger` itself.** The failure comes from `git` 6, and an older Danger does not guarantee it avoids the same constant.
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.
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.
A length on a Hash or Float body param would otherwise emit maxLength on an object or number schema, where the keyword has no meaning.
Grape's length validator counts characters for strings, entries for arrays and keys for hashes, and ignores other types. Emit minLength/maxLength only for strings and minProperties/maxProperties for objects, so numbers and objects no longer get a meaningless maxLength, and let body definitions carry the new keys.
numbata
force-pushed
the
fix/body-param-length-limits
branch
from
November 3, 2026 12:03
0f72479 to
fd98ff9
Compare
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 with
length:, such as a name capped at 50 characters, a list capped at three entries or an object capped at five keys, were missing from the generated Swagger document for request bodies, so consumers could not see the rules the API actually enforces. This change publishes those limits for string, array and object fields in request bodies, including fields inside nested objects and arrays of objects. It also makes each limit use the keyword that matches the field type, so numbers and other types no longer receive a meaningless length keyword. API owners do not need to change any declarations; the limits appear after regenerating the documentation.Root cause
Two separate problems:
MoveParamsmoves body params out ofparametersand rebuilds them as a schema underdefinitions. That rebuild copies keys through an allowlist, and the 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 Length limits (minLength/maxLength, minItems/maxItems) are dropped from body params moved into a definition #1010.ParseParams#document_length_limitsemittedminItems/maxItemsfor arrays andminLength/maxLengthfor every other type. Grape'slength:validator counts characters for strings, entries for arrays and keys for hashes, and ignores any value withoutlength. A hash or a number withlength:therefore got amaxLengththat has no meaning in Swagger 2.0.What changes
ParseParamspicks the keyword by type:minItems/maxItemsfor arrays,minLength/maxLengthfor strings,minProperties/maxPropertiesfor objects, and nothing for other types, which Grape does not validate either.MoveParamscopiesminLength,maxLength,minPropertiesandmaxPropertiesonto body properties.minItems/maxItemsare copied onto the array schema itself, where they describe the number of entries, and not ontoitems. They live in a namedarray_schema_keysmethod next toproperty_keys.min: 0) are kept; keys are copied by presence, not truthiness.Array[JSON]with a block) get the same treatment, because they go through the same conversion.Benefits
length:declarations, so there is a single source of truth and nothing to repeat indocumentation:options.Drawbacks and nuances
minLength/maxLength/minItems/maxItems/minProperties/maxPropertiesentries. Schema-aware tools may begin enforcing limits that were previously absent, and how they do so is up to each tool. API owners should review regenerated artifacts when upgrading.length:no longer getsminLength/maxLength, and a hash now getsminProperties/maxPropertiesinstead. The old output was not valid for those types and Grape never enforced a length on them, but it is a visible change.ParseParamsmay add in the future (for examplepatternoruniqueItems) still need to be added to the allowlists by hand.$refand 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 length limits.items. Merging them would risk putting item counts onitemsor character limits on the array.MoveParams, copying string keys just for string types. This was the first approach. It fixed body schemas but left the wrong keywords in query output and had no place forminProperties/maxProperties, so the type mapping moved toParseParams, where the keywords are produced.documentation:options. This duplicates information that is already declared and would leave every existing API with the gap.