Skip to content

Fix issue where array params are sometimes omitted when array_use_braces is true #957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

olivier-thatch
Copy link
Contributor

Fixes #952.

The fix consists of removing the [] suffix at the end of a parameter's name if the parameter is an array and it's a body param.

This fix is very hacky: ideally, [] shouldn't be added in the first place. But I don't think that can be achieved without significantly refactoring the code.

@dblock @numbata Curious if you have any thoughts on this approach.

@dblock
Copy link
Member

dblock commented May 24, 2025

CI was fixed in #958, rebase please?

@olivier-thatch olivier-thatch force-pushed the fix-array-use-braces branch from e4b3778 to eba362d Compare May 28, 2025 16:31
@olivier-thatch olivier-thatch changed the title Fix issue where array params are sometimes omitted when array_use_braces is true Fix issue where array params are sometimes omitted when array_use_braces is true May 29, 2025
@numbata
Copy link
Contributor

numbata commented May 31, 2025

Hi @olivier-thatch, a quick fix for this PR could be:

diff --git a/lib/grape-swagger/doc_methods/move_params.rb b/lib/grape-swagger/doc_methods/move_params.rb
index c8417ce..12c6477 100644
--- a/lib/grape-swagger/doc_methods/move_params.rb
+++ b/lib/grape-swagger/doc_methods/move_params.rb
@@ -136,7 +136,7 @@ module GrapeSwagger
           return if value.blank?
 
           definition[:required] ||= []
-          definition[:required].push(*value)
+          definition[:required].push(*value).uniq!
         end
 
         def build_body_parameter(name, options)

I considered using a Set.new for definition[:required] to enforce uniqueness, but that would change the interface (as example, Set doesn’t support .push) and could introduce side effects for other grape-swagger-* gems.

@olivier-thatch olivier-thatch force-pushed the fix-array-use-braces branch from d19daf7 to 003b77f Compare June 2, 2025 18:29
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.

Bug report: omitted array parameters with array_use_braces: true
3 participants