OpenAPITools / OpenAPITools/openapi-generator
[BUG] Multipart/form-data encoding object requires contentType
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Validation fails when multipart request description contains encoding without contentType.
Using openapi-generator-cli@1.0.12-4.3.0
OpenAPI declaration file content or url
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary",
"nullable": true
}
}
},
"encoding": {
"file": {
"style": "form"
}
}
}
}
},
Command line used for generation
openapi-generator generate -i swagger.json -g typescript-redux-query -o src/openapi-client
Steps to reproduce
- Swashbuckle.AspNetCore generates encoding object with style: "form" when using IFormFile to accept file uploads.
[HttpPost("{id}/files")]
public Task<ActionResult<EntityWithNameDto>> PostFiles(int id, IFormFile file, CancellationToken ct)
- While specifying content type for multipart requests is allowed, it is not required: https://swagger.io/specification/#encodingObject
- Validation fails with the following error: "...requestBody.content.encoding.contentType is missing"
Suggest a fix
After removing the encoding element entirely, validation passes. It should be possible to specify encoding without content type in this context.
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 with the openapi-generator generate -i swagger.json -g typescript-redux-query entry point and reproduce the validation failure using the multipart/form-data declaration shown in the issue. Trace the validation of the request body's encoding object; done means an encoding containing style: "form" without contentType validates successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, typescript
- Domain
- api, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100