OpenAPITools / OpenAPITools/openapi-generator

[BUG] Multiple file upload + metadata fails as multipart, works as json+base64

Open
#13,110 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue? --> https://github.com/sebpiller/openapi-bug
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists? --> No, only with 6.0.1 - master does not build at the moment (module java.base does not "opens java.util" to unnamed module xxx) !
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output? --> Generation error vs generation done: [WARNING] Could not compute datatypeWithEnum from UploadFileModel, null
Description

I'm trying to use openapi + spring boot to declare an endpoint where I can upload multiple files, each of them having metadatas (for example, an "urgent" flag that can be set for each file). I tried to use a multipart/form-data endpoint with a binary property but the generation of the beans&api is failing with a warning: [WARNING] Could not compute datatypeWithEnum from UploadFileModel, null

If I change the code to use a non-multipart request, eg. application/json+base64encoding for the upload file, then the issue disappear.

The code is available as a minimal reproducible example here: https://github.com/sebpiller/openapi-bug (toggle comment at demo.yaml, lines 11+12, 44+45 to have a working implem)

openapi-generator version

6.0.1, but fails similarly with all version I've tested

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Demo
  version: '1.0'
paths:
  '/demo/ok':
    post:
      operationId: ok
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/UploadFilesRequest'
      responses:
        '200':
          description: OK
          headers: { }
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UploadResponse'
components:
  schemas:
    UploadFilesRequest:
      title: Upload several files
      required:
        - files
      properties:
        files:
          type: array
          items:
            $ref: '#/components/schemas/UploadFile'

    UploadFile:
      title: A file upload with some metadata
      properties:
        urgent:
          type: boolean
        filename:
          type: string
        data:
          type: string
          format: binary

    UploadResponse:
      title: A stub response
      properties:
        accepted:
          type: boolean
Generation Details

Maven generator 6.0.1, see linked project's pom

Steps to reproduce

Run clean install on the demo project. It fails with a warning "[WARNING] Could not compute datatypeWithEnum from UploadFileModel, null"

Switching to application/json + base64 encoding of uploads works, but is suboptimal

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 linked minimal reproduction, especially demo.yaml and its Maven pom, then run clean install to reproduce the UploadFileModel warning. Trace how the generator handles multipart/form-data schemas containing arrays of binary-bearing objects. Done means the sample generates successfully without the warning while preserving the multipart upload and metadata structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring-boot
Domain
api, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.