From 3e69d7ced04c709c9f2f37ae337f59862c127ec7 Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Sat, 16 Feb 2019 15:59:09 +0100 Subject: [PATCH] Handle arrays in Grape::Endpoint#expose_params --- lib/grape-swagger/endpoint.rb | 11 +++++++---- spec/swagger_v2/api_documentation_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/grape-swagger/endpoint.rb b/lib/grape-swagger/endpoint.rb index 79dd3b1a..67b7e564 100644 --- a/lib/grape-swagger/endpoint.rb +++ b/lib/grape-swagger/endpoint.rb @@ -306,14 +306,17 @@ def default_type(params) end def expose_params(value) - if value.is_a?(Class) && GrapeSwagger.model_parsers.find(value) - expose_params_from_model(value) - elsif value.is_a?(String) + case value + when Class + expose_params_from_model(value) if GrapeSwagger.model_parsers.find(value) + when String begin - expose_params(Object.const_get(value.gsub(/\[|\]/, ''))) # try to load class from its name + expose_params(Object.const_get(value)) rescue NameError nil end + when Array + expose_params(value.first) end end diff --git a/spec/swagger_v2/api_documentation_spec.rb b/spec/swagger_v2/api_documentation_spec.rb index ac59f1fb..1a5ff9d1 100644 --- a/spec/swagger_v2/api_documentation_spec.rb +++ b/spec/swagger_v2/api_documentation_spec.rb @@ -27,12 +27,12 @@ 'locale' => { desc: 'Locale of API documentation', required: false, - type: 'Symbol' + type: Symbol }, 'name' => { desc: 'Resource name of mounted API', required: true, - type: 'String' + type: String } } }