ruby-grape / ruby-grape/grape-swagger
Array of entities in request body
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.1k
- Forks
- 479
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 6
Description
Related issue: https://github.com/ruby-grape/grape-entity/issues/252
As for example above, we want request body to be:
{
"accounts": [
{
"cma": 0,
"name": "string",
"environment": "string",
"sites": 0,
"username": "string",
"password": "string"
}
]
}
But actually:
[
{
"cma": 0,
"name": "string",
"environment": "string",
"sites": 0,
"username": "string",
"password": "string"
}
]
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. https://github.com/ruby-grape/grape/issues/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 use object_type fixes the issue.
Is this reasonable fix?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/grape-swagger/doc_methods/move_params.rb at MoveParams#build_definition, then read the related issue and the request-body examples. Compare the generated specification with Grape's requirement for an object containing the array under a top-level key. Done means the specification represents the intended JSON object without requiring a dummy optional parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100