Reputation: 41
I am using openapi-generator-maven-plugin for multiple/form-data to upload file with additional data. If I use object (field metadata) in request object wouldn't be generated. For application/json content objects in request are generated. Problem exist only for multipart/form-data content type. Here is my plugin configuration:
<execution>
<id>generate rest api interfaces and dtos</id>
<phase>generate-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${openapi-generator-maven-plugin.inputSpec}</inputSpec>
<generatorName>spring</generatorName>
<generateSupportingFiles>false</generateSupportingFiles>
<modelPackage>${openapi-generator-maven-plugin.modelPackage}</modelPackage>
<apiPackage>com.application.api</apiPackage>
<library>spring-boot</library>
<configOptions>
<dateLibrary>java8</dateLibrary>
<skipDefaultInterface>true</skipDefaultInterface>
<useTags>true</useTags>
</configOptions>
</configuration>
</execution>
And my api yml config:
/api/document:
put:
tags:
- document
summary: upload
operationId: upload
requestBody:
content:
multipart/form-data:
schema:
required:
- file
- metadata
type: object
properties:
file:
type: string
format: binary
metadata:
type: object
properties:
claimNumber:
type: string
fileName:
type: string
contentType:
type: string
responses:
201:
description: OK
content:
text/plain:
schema:
type: string
When I use only simple types everything is ok:
/api/document:
put:
tags:
- document
summary: upload
operationId: upload
requestBody:
content:
multipart/form-data:
schema:
required:
- file
- metadata
type: object
properties:
file:
type: string
format: binary
claimNumber:
type: string
fileName:
type: string
contentType:
type: string
responses:
201:
description: OK
content:
text/plain:
schema:
type: string
Upvotes: 4
Views: 5782
Reputation: 188
You could try to be explicit about the content types of the fields (although the default for type: string format: binary should be application/octet-stream)
requestBody:
content:
multipart/form-data:
schema:
required:
- file
- metadata
type: object
properties:
file:
type: string
format: binary
claimNumber:
type: string
fileName:
type: string
contentType:
type: string
encoding:
file:
contentType: application/octet-stream
claimNumber:
contentType: text/plain
fileName:
contentType: text/plain
contentType:
contentType: text/plain
Upvotes: 0