OpenAPITools / OpenAPITools/openapi-generator

[BUG] Multipart/form-data encoding object requires contentType

Open
#5,902 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Bug
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)
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.