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

@RequestPart that are in the body aren't represented correctly #836

Closed
dilipkrish opened this issue Jul 7, 2015 · 5 comments
Closed

@RequestPart that are in the body aren't represented correctly #836

dilipkrish opened this issue Jul 7, 2015 · 5 comments

Comments

@dilipkrish
Copy link
Member

    @RequestMapping(value = "addContactWithFile", method = RequestMethod.POST)
    @ApiOperation(value = "Add a new contact with file attachment")
    public ResponseEntity<Void> addContactWithFile(@RequestPart Contact contact, @RequestPart MultipartFile singleFile) {
        log.debug(contact.toString());
        log.debug(singleFile.getName());
        return new ResponseEntity<>(HttpStatus.OK);
    }

Causes an incorrect output
swagger_ui

Thanks for reporting @RizziCR!

@dilipkrish dilipkrish added the bug label Jul 7, 2015
@dilipkrish dilipkrish modified the milestones: 2.0.4, 2.1 Jul 7, 2015
@dilipkrish
Copy link
Member Author

Looks like swagger-core doesn't support multipart-formData very well. This is a limitation with the swagger models so that it doesn't allow one to express request-parts to be expressed in as form bodys

@dilipkrish dilipkrish modified the milestones: 2.0.4, 2.1 Jul 7, 2015
@dilipkrish dilipkrish modified the milestones: 2.1, 2.0.4 Jul 7, 2015
@dilipkrish
Copy link
Member Author

@RizziCR After a little bit of research here it seems like swagger-ui only supports the notion of form variables that are primitive types string, int etc. and not complex types that can be a @RequestPart

It appears the swagger-core is doing the right thing by not exposing the schema in a FormParameter. While http spec allows you to specify content types in a multipart/form-data request, its not common and it doesn't appear that its supported by tools like Postman. So until someone can tell me any different, really changing it to this style is your best bet as far as this issue is concerned.

@RequestMapping(value = "addContactWithFile", method = RequestMethod.POST)
    @ApiOperation(value = "Add a new contact with file attachment")
    public ResponseEntity<Void> addContactWithFile(@RequestPart String contactId, @RequestPart MultipartFile singleFile) {
        log.debug(contactId); //<-- String variable
        log.debug(singleFile.getName());
        return new ResponseEntity<>(HttpStatus.OK);
    }

We can revisit this at a later point in time

@dilipkrish dilipkrish modified the milestones: 2.2.0, 2.3.0 Aug 14, 2015
@dilipkrish
Copy link
Member Author

Closing this as its a very esoteric feature which has a work around. Feel free to reopen if required

@ttww
Copy link

ttww commented Nov 3, 2017

I'v got the same problem. This case is not esoteric (:-)).
It is well supported by curl and useful for transferring meta data to an image.
If you use a simple string you lose the Swagger-GUI for easy testing and the code generation for the clients (like in our case 👎 )
So the real workaround is to change your api if you don't want to lose the code generation... :-(
How can I reopen this bug?

@dilipkrish
Copy link
Member Author

I think swagger-ui doesnt support this feature. Im happy to reopen it but I don't think it belongs in this project. it should be reported in swagger-ui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants