From 44217ddef12ca53d930f46b80601ae40dd5cb82f Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 9 Oct 2020 09:52:52 -0700 Subject: [PATCH] Fix declared_params regression with multiple allowed types Prior to Grape v1.5.0 and https://github.com/ruby-grape/grape/pull/2103, the following would return `nil`: ``` params do optional :status_code, types: [Integer, String] end get '/' do declared_params end ``` However, now it turns an empty `Array`. We restore the previous behavior by not returning an empty `Array` if multiple types are used. Closes https://github.com/ruby-grape/grape/issues/2115 --- CHANGELOG.md | 1 + lib/grape/dsl/inside_route.rb | 2 +- spec/grape/endpoint/declared_spec.rb | 13 ++++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71a7cde38..ebddceccb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ #### Fixes * Your contribution here. +* [#2115](https://github.com/ruby-grape/grape/pull/2115): Fix declared_params regression with multiple allowed types - [@stanhu](https://github.com/stanhu). ### 1.5.0 (2020/10/05) diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index 6f4becfea..134f1ea24 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -94,7 +94,7 @@ def handle_passed_param(params_nested_path, has_passed_children = false, &_block if type == 'Hash' && !has_children {} - elsif type == 'Array' || type&.start_with?('[') + elsif type == 'Array' || type&.start_with?('[') && !type&.include?(',') [] elsif type == 'Set' || type&.start_with?('#