Skip to content

Cannot generate MultipartForm server-side API #347

@mcruzdev

Description

@mcruzdev

This issue is related to quarkiverse/quarkus-openapi-generator#1154 issue.

For Quarkus , we need to following this tutorial here https://quarkus.io/guides/rest#multipart.

When the user uses by example:

{
  "openapi": "3.0.3",
  "info": {
    "title": "File Upload API",
    "version": "1.0.0"
  },
  "paths": {
    "/mypath": {
      "post": {
        "operationId": "mymethod",
        "summary": "Upload two files and receive a PDF response",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/FileUploadForm"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "FileUploadForm": {
        "type": "object",
        "properties": {
          "file1": {
            "type": "string",
            "format": "binary"
          },
          "file2": {
            "type": "string",
            "format": "binary"
          }
        },
        "required": ["file1", "file2"]
      }
    }
  }
}

The resource should have the following contract:

package org.example.api;

import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.example.api.beans.FileUploadForm;
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;

/**
 * A JAX-RS interface. An implementation of this interface must be provided.
 */
@Path("/mypath")
public interface MypathResource {
  @Operation(summary = "Upload two files and receive a PDF response", operationId = "mymethod")
  @POST
  @Produces("application/pdf")
  @Consumes("multipart/form-data")
  Response mymethod(@MultipartForm @NotNull FileUploadForm data);
}

And the bean, something like it:

import import org.jboss.resteasy.reactive.multipart.FileUpload;

public class FileUploadForm {
    private FileUpload file1;
    private FileUpload file2;
}

Another point: When the user uses a inline object with binary no bean are created and instead it a InputStream is added as body:

          multipart/form-data:
            schema:
              type: object
              properties:
                file1:
                  type: string
                  format: binary
                file2:
                  type: string
                  format: binary

cc: @EricWittmann @lpieprzyk @luca-vercelli @CodingLenni

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions