OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][jaxrs-spec] Codegen creates invalid code for multipart/form-data for quarkus

Open
#7,994 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

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

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)

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 by generating the supplied openapi.yml with the jaxrs-spec generator using the quarkus library, then inspect the generated interface and model signatures. Compare the result with the multipart request shape and the suggested @MultipartForm approach; done means the generated Quarkus resource starts without the RESTEasy constructor error and preserves validation annotations.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.