diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index 6f4becfea2..e03ebed1d4 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -91,10 +91,9 @@ def handle_passed_param(params_nested_path, has_passed_children = false, &_block route_options_params = options[:route_options][:params] || {} type = route_options_params.dig(key, :type) has_children = route_options_params.keys.any? { |k| k != key && k.start_with?(key) } - if type == 'Hash' && !has_children {} - elsif type == 'Array' || type&.start_with?('[') + elsif type == 'Array' || type && type.start_with?('[') && !type.include?(',') [] elsif type == 'Set' || type&.start_with?('#(c) { + if c + if /([0-9]+):([0-9]+):([0-9]+)/ =~ c.to_s + 'HH:MM:SS format' + elsif /\A[0-9]+\.{0,1}[0-9]*\z/ =~ c.to_s + 'Float or Integer format' + else + 'Invalid Time value' + end + end + } + end + end + subject.post('/types') { declared(params)[:bar].first[:foo] } + + post '/types', bar: [{ foo: '00:00:01' }] + expect(last_response.status).to eq(201) + expect(last_response.body).to eq('HH:MM:SS format') + + post '/types', bar: [{ foo: 1 }] + expect(last_response.status).to eq(201) + expect(last_response.body).to eq('Float or Integer format') + + post '/types', bar: [{ foo: 1.0 }] + expect(last_response.status).to eq(201) + expect(last_response.body).to eq('Float or Integer format') + + post '/types', bar: [{ foo: nil }] + expect(last_response.status).to eq(201) + expect(last_response.body).to eq('') + end + end + context 'when using custom types' do module ParamsScopeSpec class CustomType