Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Custom mime types ignored in `produces`

Đang mở
#700 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
openapi, ruby
Lĩnh vực
api, documentation

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Ruby
Star
1.1k
Fork
477
Merge trung bình
5 giờ 25 phút
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby-grape/grape-swagger

Tất cả issue của ruby-grape/grape-swagger

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.