ruby-grape / ruby-grape/grape-swagger

Bug report: omitted array parameters with `array_use_braces: true`

Open
#952 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.1k
Forks
479
Avg merge
2d 14h
Merged PRs (30d)
6

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example using add_swagger_documentation(array_use_braces: true) with the shared params and compare the generated specification. Trace how the array parameters are classified for GET versus POST/PUT/PATCH body parameters; done means the implicitly body-scoped param1 is included while the explicitly documented param2 remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.