Skip to content

Require exactly one name for a requires or optional block - #2991

Merged
ericproulx merged 1 commit into
masterfrom
fix/group-block-needs-one-name
Sep 23, 2026
Merged

ericproulx merged 1 commit into
masterfrom
fix/group-block-needs-one-name

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

A requires or optional given a block silently declares something other than what it reads unless it names exactly one parameter.

No name. The block's params are declared one level up, and under optional they are still required:

params do
  optional type: Hash do
    requires :x
  end
end
# POST {}        => 400 "x is missing"
# POST {"x": 1}  => 201, declared {"x": 1}

Several names. Every name is required, but only the first gets the block's params, and the rest are left out of declared:

params do
  requires :a, :b, type: Hash do
    requires :x
  end
end
# POST {"a": {"x": 1}, "b": {}}        => 201, declared {"a": {"x": 1}}
# POST {"a": {"x": 1}, "b": {"x": 2}}  => 201, declared {"a": {"x": 1}}

DSL::Parameters#declare now raises ArgumentError ("a params block needs exactly one parameter name, got n") for either form.

ParamsScope#new_scope guarded its group-type check with if element, which could only be false for a block with no name. The branch was never covered, and it is how this came up. With the name now enforced, the check always runs, and the type || Array fallback after it is gone.

UPGRADING explains how to rewrite either form. Specs cover both forms for requires and optional; all four fail on master.

🤖 Generated with Claude Code

@ericproulx
ericproulx force-pushed the fix/group-block-needs-one-name branch 2 times, most recently from 4946e74 to eae5bab Compare September 22, 2026 22:39
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

A `requires` or `optional` given a block declared something other than
it read when it did not name exactly one parameter:

- With no name, the block's params were declared one level up, and
  under `optional` they were still required.
- With several names, all of them were required, but only the first got
  the block's params, and the others were left out of `declared`.

`DSL::Parameters#declare` now raises ArgumentError for either. That makes
`ParamsScope#new_scope`'s `if element` guard around the group-type check
unreachable, so the check always runs, and the `type || Array` fallback
behind it goes too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ericproulx
ericproulx force-pushed the fix/group-block-needs-one-name branch from eae5bab to 6a34566 Compare September 23, 2026 15:04
@ericproulx
ericproulx merged commit 8555c48 into master Sep 23, 2026
33 checks passed
@ericproulx
ericproulx deleted the fix/group-block-needs-one-name branch September 23, 2026 19:46
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.

2 participants