Bug report: omitted array parameters with `array_use_braces: true`
When array_use_braces is set to true, array parameters are omitted when they are body parameters but don't explicitly specify documentation: { param_type: "body" }.
Example:
# with add_swagger_documentation(array_use_braces: true)
params do
requires :param1, type: Array[String]
requires :param2, type: Array[Integer], documentation: { param_type: "body" }
end
post :foo do
{ declared_params: declared(params)
end
The spec will look like:
"postFoo": {
"required": ["param2"],
"type": "object",
"properties": {
"param2": {
"type": "array",
"items": { "type": "integer", "format": "int32" }
}
}
}
It is particularly annoying if one wants to share some params between GET and POST/PUT/PATCH endpoints and rely on the implicit behavior to have the params be query params or body params as appropriate.
I didn't spend too much time looking into this, but I think this happens because:
-
array_use_braces: truecauses[]to be appended to array parameter names: https://github.com/ruby-grape/grape-swagger/blob/3e842a138b0f5edd2538d9da4aa23276e63e5d5c/lib/grape-swagger/endpoint/params_parser.rb#L26 -
which in turn causes array parameters to be treated as nested params: https://github.com/ruby-grape/grape-swagger/blob/3e842a138b0f5edd2538d9da4aa23276e63e5d5c/lib/grape-swagger/doc_methods/move_params.rb#L41
Probably the check needs to be updated to exclude foo[] and only treat foo[bar] as nested params?
Please do try to PR a fix!