swagger-api / swagger-api/swagger-ui
Error when optional formData field is not provided using Swagger UI POST Request
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Hello,
I am using swagger version 4.12.0. OpenAPI Spec 2.0.
I have an API POST call where I am sending a formData file type OPTIONAL param in the request. But when using the swagger ui, for the case where I do not select any file for this optional param field. I receive this error: "[java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -8190". The request works when I select a file for the request. It seems to fail before it even reaches my backend code.
I was able to reproduce what I think is the same error on the swagger sample editor:
Steps to reproduce:
- Open https://editor.swagger.io/
- Click Edit > Choose Load Petstore OAS 2.0
- On the right panel, try out POST /pet (Change first property id: from 0 to 100 , leave other fields as is) hit enter
- Go to post /pet/{petId}/uploadImage Try it out, set petId to 100, leave other formData fields empty. Hit enter
- See response: "message": "org.jvnet.mimepull.MIMEParsingException: Missing start boundary"
- On left side code panel, ctrl + F “/pet/{petId}/uploadImage:” the formData fields are both required: false.
This is actually a regression, as before I updated to version 4.12.0, this same API used to work without any errors. I guess at some version level, some additional checking was added to the params where this issue was introduced.
It looks like this fail might be because even though I do not add this optional formData field, the CURL request swagger UI sends still includes this header -> -H 'Content-Type: multipart/form-data'. When I try the curl command myself I see the same error, but if I remove this multipart/form-data contentType header field from the Curl request. It then succeeds.
Thanks a lot for taking the time to look at this, hope this could be resolved..
"/myAPI":{
"post":{
"summary":"mySummary",
"description":"myDescription",
"operationId":"myAPIId",
"x-display-name":"My API",
"tags":[
"My API"
],
"produces":[
"application/json"
],
"parameters":[
{
"name":"name",
"in":"query",
"description":"name field",
"required":true,
"type":"string"
},
{
"name":"file",
"in":"formData",
"description":"Upload file",
"required":false,
"type":"file"
}
],
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
Reproduce the issue in the Swagger Editor using the Petstore OAS 2.0 uploadImage steps, then inspect Swagger UI's OpenAPI 2.0 request generation for optional formData file parameters. Compare the generated request with and without an empty file field and verify that an optional empty formData request succeeds without the multipart boundary error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100