Skip to content

Present multipart object attributes as "formData" #2401

@andyRokit

Description

@andyRokit

Given the existence of the following endpoint:

public class Foo {
    @ApiModelProperty(value = "Bar description", required = true)
    private String bar;
    ...
@PostMapping(value = "/foo", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void postFooAsMultiPart(Foo foo) {
    ...

If I mark Foo as a @RequestBody it will be presented as a single field:

"parameters": [
  {
    "in": "body",
    "name": "foo",
    "description": "foo",
    "required": true,
    "schema": {
      "$ref": "#/definitions/Foo"
    }
  }
],

If I don't mark Foo as @RequestBody its attributes are presented as query fields:

"parameters": [
  {
    "name": "bar",
    "in": "query",
    "description": "Bar description",
    "required": true,
    "type": "string"
}
],

I would like the presence of a multipart form data header to render the request as:

"parameters": [
  {
    "name": "bar",
    "in": "formData",
    "description": "Bar description",
    "required": true,
    "type": "string"
}
],

I'm not sure if this is a bug or a feature or if it even makes sense to do!

Notes

  • Reported behavior on 2.8.0
  • I've posted a question on stackoverflow asking how this should be done, but I'm not optimistic about a positive response (hence this ticket)
  • I assume this change would involve OperationParameterReader.shouldExpand taking account of the consumes header and if multipart, passing data down to ExpandedParameterBuilder that would make the parameterType dynamic rather than hard-coded to "query".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions