-
Notifications
You must be signed in to change notification settings - Fork 476
Array of entities in request body #666
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
Comments
I just ran into the same bug. Really don't want to go the dummy parameter route, but looks like it's not possible right now. |
The issue seems to be with the I have this param contract. requires :members, type: Array, documentation: {param_type: 'body'} do
requires :user_id, type: Integer, desc: 'User ID'
requires :role, type: Symbol, values: [:viewer, :user, :manager, :remove], desc: 'Role for the user.'
end And it yields incorrect swagger docs expecting this. [
{
"members": [
{
"user_id": 0,
"role": "string"
}
]
}
] When it should be like this. {
"members": [
{
"user_id": 0,
"role": "string"
}
]
} |
Hey, did you guys find out a workaround for the problem mentioned in this issue? |
@swistaczek what I have been doing to work around this issue is the following. params do
requires :members, type: Array, documentation: {param_type: 'body'} do
requires :user_id, type: Integer, desc: 'User ID'
requires :role, type: Symbol, values: [:viewer, :user, :manager, :remove], desc: 'Role for the user.'
end
optional :ignored, type: Boolean, desc: 'Workaround for https://github.com/ruby-grape/grape-swagger/issues/666'
end not the most elegant solution at the moment. Note that I am in the middle of doing an upgrade to grape-swagger 1.0/grape 1.3.x and have not verified this yet against that version. |
So.. I just tested on grape 1.3.x/ grape-swagger 1.1.0 and this issue appears to be resolved now. |
@swistaczek I'm using a similar workaround: params do
requires :contacts, type: Array[API::V2::Entities::Contact], documentation:
{ desc: 'Contacts', is_array: true, in: 'body' }
optional :hack, documentation: { in: 'body', desc: 'Hack to bypass Grape bug' }
end @urkle I just tried (quickly) to upgrade to grape With the "hack" the expected JSON is:
Without the "hack" it (still) becomes:
|
So, this issue is fixed when the nested is an object, but when the nested is a scalar it still occurs. params do
requires :members, type: Array, documentation: {param_type: 'body'} do
requires :user_id, type: Integer, desc: 'User ID'
requires :role, type: Symbol, values: [:viewer, :user, :manager, :remove], desc: 'Role for the user.'
end
end works, but this does not work and instead creates a completely unusable expected input of [1,2,3] (with no key name). params do
requires :rule_ids, type: Array[Integer], desc: 'blah', documentation: {param_type: 'body'}
end Also, using in: 'body' does not work ANYWHERE For me, I have to use param_type: 'body' |
Related bug #725 |
Hi there, I have read the solutions provided by different guys but my scenario is about filters. Which means there could be array of users like 1,4 or 10 or so on etc. How can i manage this? |
Related issue: ruby-grape/grape-entity#252
As for example above, we want request body to be:
But actually:
Grape also wants the array to be in the key of top level JSON object.
( Top level array data cannot be handled by Grape out of the box ( cf. ruby-grape/grape#1730 ). )
So it seems the generated specification is broken.
A workaround is to adding dummy optional parameter.
It forces the request body to be a JSON object.
I've found that making
MoveParams#build_definition
to always useobject_type
fixes the issue.Is this reasonable fix?
The text was updated successfully, but these errors were encountered: