Skip to content
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

Handle arrays in Grape::Endpoint#expose_params #742

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
11 changes: 7 additions & 4 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,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

Expand Down
4 changes: 2 additions & 2 deletions spec/swagger_v2/api_documentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down