question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
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:

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
fsiegristcommented, Mar 22, 2022

Same for me. Tried to use a custom ParamConverter<InputStream> (see https://resteasy.dev/2021/04/05/blog-ParamConverter-with-Quarkus/), without success.

0reactions
vikalpsareencommented, Oct 4, 2022

@fsiegrist thanks for suggesting custom converter, it worked for me below is the java code


@Provider
public class InstantParamConverter implements ParamConverter<InputStream> {

   public InputStream fromString(String value){
      try {
         return  IOUtils.toInputStream(value);
      } catch (Exception e) {

      }
      return null;
   }

   public String toString(InputStream value){
      return value.toString();
   }
}

@Provider
public class InstantParamConverterProvider implements ParamConverterProvider
{


   @Override
   public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations)
   {
      if (rawType.isAssignableFrom(InputStream.class)) {
         return (ParamConverter<T>) new InstantParamConverter();
      }
      return null;
   }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the REST Client with Multipart - Quarkus
Our first order of business is to set up the model we will be using to define the multipart/form-data payload, in the form...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found