Set default parameter location based on consumes #880
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As per #721,
grape-swagger
sets the defaultconsumes
to['application/json']
inlib/grape-swagger/doc_methods/produces_consumes.rb
:However, it also sets the default
in
of parameters toformData
inlib/grape-swagger/doc_methods/parse_params.rb
:Here,
DataType.request_primitive
simply checks if the parameter's data type is one ofinteger long float double byte date dateTime binary password email uuid object string boolean file json array
, in which case its location is set toformData
. As such, this leads to a situation where most parameters are set toformData
by default while their endpoint is also set toconsumes
application/json
by default:However, as described in the OpenAPI V2 documentation (also here),
the payload of the application/x-www-form-urlencoded and multipart/form-data requests is described by using form parameters, not body parameters
andformData
should only be used forapplication/x-www-form-urlencoded
andmultipart/form-data
requests. Currently, the default output ofgrape-swagger
will lead to OpenAPI validation errors.This MR adds logic to set the default parameter location (
in
) based on theconsumes
object, setting it toformData
ifconsumes
isapplication/x-www-form-urlencoded
ormultipart/form-data
andbody
if otherwise forPUT POST PATCH
requests. This can still be overriden by endpoint-specific options as is the usual behaviour.However, since several specs relied on this invalid output previously, it is necessary to make some changes to ensure passing.