ruby-grape / ruby-grape/grape-swagger

Custom mime types ignored in `produces`

Open
#700 0 comments 0 reactions 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

The default content types can be overridden using the DSL content_type, which adds to a :content_types Hash in the settings, which takes precedence over the default CONTENT_TYPES.

However, when generating documentation Grape::Endpoint#produces_object employs GrapeSwagger::DocMethods::ProducesConsumes to lookup mime types by symbol, and that goes directly to CONTENT_TYPES, bypassing any customisation.

class MyApi < Grape::API
  content_type :jsonapi, 'application/vnd.api+json'

  resource :foo do
    desc '/fooey', { produces: [:jsonapi] }

    get do
      {
        # My JSON API response...
      }
    end
  end
end

The generated Swagger will say

...
"paths": {
  "/fooey": {
    "get": {
      "produces": ["jsonapi"]
    }
  }
}
...

rather than the expected "produces": ["application/vnd.api+json"]. You have to explicitly specify the mime type rather than the symbol to workaround.

I assume that consumes is similarly affected.

... Or is this as intended?

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 in grape-swagger/endpoint.rb at Grape::Endpoint#produces_object and follow the lookup into doc_methods/produces_consumes.rb. Compare that lookup with the custom :content_types settings described in the issue, then check the corresponding consumes path. Done means custom symbols produce their configured MIME values in the generated Swagger output for both produces and consumes.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.