swagger-api / swagger-api/swagger-codegen
Missing annotation for Jax-Rs (jersey) multipart file upload server stub
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When generating a Jax-Rs server stub (jersey2) for Multipart file upload. There is an annotation missing to retrieve the Content-Type of the payload.
The request payload looks something like this:
------WebKitFormBoundaryPebYGXB6tjmvtwWV
Content-Disposition: form-data; name="document"; filename="myfile.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryPebYGXB6tjmvtwWV--
But with the following annotations in the src\gen\java\io\swagger\api\FileApi.java
@FormDataParam("document") InputStream documentInputStream,
@FormDataParam("document") FormDataContentDisposition documentDetail
I only get the file stream and the FormDataContentDisposition, but not the Content-Type.
This would need another Annotation:
@FormDataParam("document") FormDataBodyPart bodyPart
Now you would be able to read the Content-Type:
bodyPart.getMediaType();
Swagger-codegen version
2.2.1
Swagger declaration file content or url
swagger: '2.0'
info:
title: Sample Application
description: Upload Sample
version: "0.0.1"
host: localhost
schemes:
- http
basePath: /
produces:
- application/json
consumes:
- application/json
paths:
/file:
post:
summary: upload a file
consumes:
- multipart/form-data
parameters:
- name: document
in: formData
required: true
type: file
description: a file
responses:
200:
description: OK
Command line used for generation
java -jar swagger-codegen-cli-2.2.1.jar generate -l jaxrs -i swagger.yaml --library jersey2
Suggest a Fix
Just add the extra annotation so it looks like this:
@FormDataParam("document") InputStream documentInputStream,
@FormDataParam("document") FormDataContentDisposition documentDetail
@FormDataParam("document") FormDataBodyPart bodyPart
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the Jersey2 server stub with the provided Swagger declaration and command, then inspect src/gen/java/io/swagger/api/FileApi.java. Compare the multipart parameters with the requested FormDataBodyPart annotation and trace the generator template responsible for this method. Done means the generated signature exposes the body part so its media type can be retrieved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100