Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger-ui for JSON APIs sends incorrect content-type #721

Closed
dblock opened this issue Oct 30, 2018 · 7 comments
Closed

Swagger-ui for JSON APIs sends incorrect content-type #721

dblock opened this issue Oct 30, 2018 · 7 comments
Labels

Comments

@dblock
Copy link
Member

dblock commented Oct 30, 2018

Coming from swagger-api/swagger-ui#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?

@hardywu
Copy link

hardywu commented Nov 10, 2018

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

@mcfoton
Copy link

mcfoton commented Sep 1, 2019

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

@henrytseng
Copy link

henrytseng commented Jan 7, 2020

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/

@tristil
Copy link

tristil commented Mar 6, 2020

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

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

@tristil
Copy link

tristil commented Mar 6, 2020

Relevant lines are

param_type = value_type[:documentation][:param_type]

and

@parsed_param[:in] = param_type || 'formData'

@spaceraccoon
Copy link
Contributor

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

@dhruvCW
Copy link
Contributor

dhruvCW commented May 11, 2024

fixed in #927

@LeFnord LeFnord closed this as completed May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants