grape-swagger icon indicating copy to clipboard operation
grape-swagger copied to clipboard

Swagger-ui for JSON APIs sends incorrect content-type

Open dblock opened this issue 6 years ago • 6 comments

Coming from https://github.com/swagger-api/swagger-ui/issues/4981

Swagger UI produces multipart bodies on POST tries. I believe this is because the swagger API produces fields with in: 'formData'. It seems that the code does that for any primitive type, instead of doing in: 'body'. Doesn't seem right.

Monkey patching this works around the problem.

module GrapeSwagger
  module DocMethods
    class DataType
      class << self
        def request_primitive?(type)
          false
        end
      end
    end
  end
end

But probably not the right solution?

dblock avatar Oct 30 '18 20:10 dblock

A related issue #623. It should be either setting default consume to 'application/x-www-form-urlencoded', or setting default params_type to 'body'. Otherwise, Swagger-UI will be unusable without a patch to this gem for semantic errors like:

      consumes:
        - application/json
      parameters:
        - in: formData

hardywu avatar Nov 10 '18 18:11 hardywu

Have the same issue, would love to see this resolved 👀

mcfoton avatar Sep 01 '19 12:09 mcfoton

Just a quick ping on this issue. Looks like it should be following: https://swagger.io/docs/specification/2-0/describing-request-body/

And v3: https://swagger.io/docs/specification/describing-request-body/

henrytseng avatar Jan 07 '20 22:01 henrytseng

My workaround FYI is to add documentation: { param_type: 'body' } like this:

   requires(
            :data,
            type: Array[JSON],
            documentation: { param_type: 'body' }
          ) do
  end

tristil avatar Mar 06 '20 20:03 tristil

Relevant lines are

https://github.com/ruby-grape/grape-swagger/blob/564b486430881a68fef0cb12dcff583503fd8911/lib/grape-swagger/doc_methods/parse_params.rb#L67

and

https://github.com/ruby-grape/grape-swagger/blob/564b486430881a68fef0cb12dcff583503fd8911/lib/grape-swagger/doc_methods/parse_params.rb#L89

tristil avatar Mar 06 '20 20:03 tristil

Hi all, I've made a PR fixing this default behaviour at #880

spaceraccoon avatar Nov 11 '22 03:11 spaceraccoon

fixed in #927

dhruvCW avatar May 11 '24 08:05 dhruvCW