ruby-grape / ruby-grape/grape-swagger

Include array responses in http_codes?

Open
#323 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi everyone,

I found the is_array in the desc parameter for an API endpoint to specify an array as response. But I didn't find how to specify that in the http_codes part, something like:

          desc "List All Delivery",
            is_array: true,
            entity: ::Delivery::Entity,
            http_codes: [
              [200, 'OK', ::Delivery::Entity],
              [401, 'Unauthorized', API::Entities::Error],
              [403, 'Forbidden', API::Entities::Error]
          ]
          get do
            present(paginate(::Delivery.all),
                    with: ::Delivery::Entity)
          end

The generated Swagger documentation is my code makes you think the 200 response will give you a Hash but it won't, it's an array. Is there a way to do that?

Thanks.

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

Start from the desc declaration and its is_array and http_codes options shown in the issue, then trace how the generated Swagger/OpenAPI response schema is formed. Done means the 200 response is documented as an array while the 401 and 403 responses remain error entities; the issue names no file or test path.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, ruby
Domain
api, documentation
Issue type
Feature
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.