[BUG] Multiple file upload + metadata fails as multipart, works as json+base64
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue? --> https://github.com/sebpiller/openapi-bug
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] 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) !
- [x] Have you searched for related issues/PRs?
- [x] 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