Repository navigation
Document array defaults on the array instead of its items - #1013
Merged
Merged
Conversation
Danger ReportNo issues found. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, and the change includes targeted parsing and parameter-move updates with regression coverage for both query and body array defaults.
No open issues 🎉
What changed in this PR
This pull request fixes Swagger 2.0 documentation for array-valued defaults by placing array defaults on the array schema rather than within items, while preserving scalar item-default behavior.
Changes:
- Stores array defaults on the parsed array parameter.
- Preserves array defaults when moving body parameters into schema properties.
- Adds regression coverage for query and body parameters.
- Documents the fix in the changelog.
| File | Description |
|---|---|
spec/issues/950_array_default_spec.rb |
Verifies correct array-default output for query and body parameters. |
lib/grape-swagger/doc_methods/parse_params.rb |
Distinguishes array defaults from scalar item defaults during parsing. |
lib/grape-swagger/doc_methods/move_params.rb |
Preserves array-level defaults when converting body parameters into schema properties. |
CHANGELOG.md |
Documents the array-default placement fix. |
Review effort: Lite
A default such as `%w[8.8.8.8 8.8.4.4]` on a `type: [String]` param was written to `items.default`, where Swagger 2.0 expects a single item value, so tools rendered a nested array. Array defaults now land on the array parameter, or on the array property of a body definition. Scalar defaults keep their existing placement in `items`.
Pins formData, empty, scalar and Array[JSON] defaults, and documents that an Array default moves out of items.default.
numbata
force-pushed
the
issue-950-array-default
branch
from
November 8, 2026 12:08
1ad5780 to
93cf118
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
Array parameters with an array default, like
type: [String], default: %w[8.8.8.8 8.8.4.4], now document that default on the array itself. Previously the whole list was placed underitems, so Swagger tools showed a nested array and the schema was invalid. Scalar defaults keep their current placement.Root cause
ParseParams#parse_array_itemcopieddefaultintoitemsfor every array param, while the array-level default was skipped. An Array value is therefore never valid there (Swagger 2.0 requiresitems.defaultto be a single item value). Body params go through the same method andMoveParamsonly copiedminItems/maxItemsonto the array property, so the fix covers query, formData and body.Drawbacks
Output changes for anyone with an Array default on an array param; consumers reading
items.defaultfor it will no longer find it.Not covered
Defaults that are not plain values are unchanged and still go through the scalar path: a lambda default (
default: -> { %w[a b] }) still emitsitems.default: {}, anddefault: falseon a boolean array is still omitted. Both behave this way on master and are separate from where an Array default is placed.Alternatives considered
Moving every default to the array level was rejected: #650 intentionally documents scalar defaults in
items, and its specs pin that.Closes #950