Skip to content

Hide nested params of a hidden Hash parameter - #1016

Merged
numbata merged 5 commits into
masterfrom
issue-1015-hidden-hash-children
Nov 4, 2026
Merged

numbata merged 5 commits into
masterfrom
issue-1015-hidden-hash-children

Conversation

@numbata

@numbata numbata commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hiding a Hash parameter from the documentation now also hides its nested fields. Before, the parent disappeared but its children still showed up as separate query parameters pointing at something that no longer existed.

Root cause

Nested params arrive as separate parent[child] entries whose options don't carry the parent's documentation, so hidden: true was never applied to them.

The parameter-level hidden: proc is now evaluated with the resolved token_owner (looked up at most once per route, and only when a proc needs it), the same way route visibility is, so hidden: ->(user) { ... } no longer raises when token_owner is configured. As for route-level procs, a configured token_owner method that does not exist now raises TokenOwnerNotFound for parameter-level procs too.

Drawbacks

The match is by name prefix (parent[), so a hidden filters also hides any param literally named filters[...], which is the set Grape produces for its children. Siblings such as filters_extra are unaffected. It also relies on parsers merging into the accumulator rather than removing keys from it.

Rejected alternatives

Resolving each child's parent through route.params would need to be repeated in every parser. Filtering once in params_object covers every parser.

Closes #1015

Children of a Hash parameter arrive as separate parent[child] entries
that do not carry the parent's documentation, so hidden: true on the
parent left orphaned query parameters in the document. Skip entries
nested under a hidden parent as well.
@numbata
numbata force-pushed the issue-1015-hidden-hash-children branch from 257ced7 to 450c74b Compare November 4, 2026 17:40
@numbata
numbata marked this pull request as ready for review November 4, 2026 17:44
@numbata
numbata requested a lite review from Copilot November 4, 2026 17:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain, and the change includes regression coverage for filtering nested parameters under hidden Hash roots.

No open issues 🎉

What changed in this PR

This pull request fixes Swagger documentation generation so hiding a Hash parameter also hides its nested query parameters, preventing orphaned child fields from appearing.

Changes:

  • Tracks hidden top-level parameters and filters their nested descendants.
  • Adds regression coverage for nested and deeply nested Hash parameters.
  • Documents the fix in the changelog.
File Description
spec/​issues/​1015_hidden_hash_children_spec.rb Verifies hidden Hash children are excluded while visible parameters remain.
lib/​grape-swagger/​endpoint.rb Filters hidden Hash roots and their nested parameters during documentation generation.
CHANGELOG.md Documents the hidden nested-parameter fix.

Review effort: Lite

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Danger Report

No issues found.

View run

Deciding whether a parent is hidden now goes through the same token
owner aware evaluation as route visibility, so a hidden: proc taking
the token owner no longer raises. Specs cover prefix siblings, array
parents, proc-hidden parents and the body definition.
Hidden procs previously triggered a token owner lookup per parameter,
which scales badly if the lookup hits a database or auth service. The
owner is now resolved lazily and at most once per params_object call.
@numbata
numbata merged commit d2d6d4d into master Nov 4, 2026
64 checks passed
@numbata
numbata deleted the issue-1015-hidden-hash-children branch November 4, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

documentation: { hidden: true } on a Hash parameter doesn't hide its nested query parameters

2 participants