grape-swagger
grape-swagger copied to clipboard
Swagger-ui for JSON APIs sends incorrect content-type
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?
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
Have the same issue, would love to see this resolved 👀
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/
My workaround FYI is to add documentation: { param_type: 'body' }
like this:
requires(
:data,
type: Array[JSON],
documentation: { param_type: 'body' }
) do
end
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
Hi all, I've made a PR fixing this default behaviour at #880
fixed in #927