[BUG][Java][jaxrs-spec] Codegen creates invalid code for multipart/form-data for quarkus
See original GitHub issueDescription
When creating Java code from a openapi.yml for quakus, the resulting code does not work:
RESTEASY003875: Unable to find a constructor that takes a String param or a valueOf() or fromString() method for javax.ws.rs.FormParam("file") on public abstract void org.openapitools.api.UploadApi.uploadPost(java.io.InputStream,java.lang.String) for basetype: java.io.InputStream
Quarkus cannot handle the geneated method signature of the Rest-resource-class:
@POST
@Consumes({ "multipart/form-data" })
@Produces({ "application/json" })
@ApiOperation(value = "", notes = "", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "", response = Void.class) })
void uploadPost( @FormParam(value = "file") InputStream fileInputStream,@FormParam(value = "name") String name);
(Additionally, no validation annotations are created!)
openapi-generator version
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: ''
description: ''
version: "1.0"
paths:
/upload:
post:
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/MultipartData'
responses:
200:
description: ''
content:
application/json: {}
components:
schemas:
MultipartData:
type: object
properties:
file:
format: binary
type: string
name:
pattern: .*
type: string
Command line used for generation
Quarkus-Version: 1.9.2.Final
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/META-INF/openapi.yml</inputSpec>
<generatorName>jaxrs-spec</generatorName>
<configOptions>
<library>quarkus</library>
<sourceFolder>src/gen/java/main</sourceFolder>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- clone https://github.com/M-Landwehr/poc/tree/quarkus-file-upload-multipart-form
- run
mvnw package quarkus:dev
- the error above is printed to the server log
- delete ExampleResource.java
- rerun
mvnw package quarkus:dev
- no error is logged; open http://localhost:8080/swagger-ui/#/default/post_upload
Alternatively simply generate java code from the openapi.yml above using the jaxrs-spec generator and the quarkus library
Related issues/PRs
Suggest a fix/enhancement
The model-class is created but is not used in this case. (althogh is has @JsonProperty
annotations insteadod the @FormParam
annotations
A possible fix would be to
- For a
multipart/form-data
request:- remove ‘@JsonProperty’ from the generated model class and add
@FormParam
- adjust the generated interface to have methods with a signure simmilar to
public void uploadPost(@MultipartForm @Valid MultipartData data) {}
(see https://quarkus.io/guides/rest-client-multipart)
- remove ‘@JsonProperty’ from the generated model class and add
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:7 (1 by maintainers)
Top GitHub Comments
Same for me. Tried to use a custom ParamConverter<InputStream> (see https://resteasy.dev/2021/04/05/blog-ParamConverter-with-Quarkus/), without success.
@fsiegrist thanks for suggesting custom converter, it worked for me below is the java code