quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

Openapi Spec wrong for "FileUpload" #40058

Closed jackovsky8 closed 6 months ago

jackovsky8 commented 6 months ago

Describe the bug

If I use the class FileUpload in a Rest Service, it somehow overwrites the generated Openapi Specs.

I have a quarkus application where I defined a resource with two files in a multipart/form-data upload:

    @Path("v1")
    public interface IMultiPartResource {
    @POST
    @Path("/multipart")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.APPLICATION_JSON)
    Object multipart(
        @RequestBody(
            description = "The multipart data.",
            required = true,
            content = @Content(
                mediaType = MediaType.MULTIPART_FORM_DATA,
                schema = @Schema(
                    type = SchemaType.OBJECT,
                    properties = {
                        @SchemaProperty(name = "data1", type = SchemaType.STRING, format = "binary"),
                        @SchemaProperty(name = "data2", type = SchemaType.STRING, format = "binary"),
                    }
                )))
        @NotNull @RestForm("data1") FileUpload data1,
        @RestForm("data2") Optional<FileUpload> data2,
    }

My Problem is, that the generated openapi spec is not correct. It produces something like:

    ---
      ...
      /clv-api/v1/importer/gino-production-data:
        post:
          requestBody:
            description: "The multipart data."
            content:
              multipart/form-data:
                schema:
                  type: object
                  properties:
                    data1:
                      $ref: '#/components/schemas/FileUpload'
                    data2:
                      $ref: '#/components/schemas/FileUpload'
            required: true
      ...
    components:
      schemas:
        FileUpload:
          type: object

But I expect something like that:

    ---
      ...
      /clv-api/v1/importer/gino-production-data:
        post:
          requestBody:
            description: "The multipart data."
            content:
              multipart/form-data:
                schema:
                  type: object
                  properties:
                    data1:
                      type: string
                      format: binary
                    data2:
                      type: string
                      format: binary
            required: true
      ...
    components:
      schemas:
        FileUpload:
          type: object

It works correctly, if a use the class "File".

Expected behavior

For it to not overwrite the Openapi Specs, like how it is supposed to work.

Actual behavior

See above.

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

mvn --version Apache Maven 3.9.3 (21122926829f1ead511c958d89bd2f672198ae9f)

Additional information

No response

quarkus-bot[bot] commented 6 months ago

/cc @EricWittmann (openapi), @MikeEdgar (openapi), @phillip-kruger (openapi)

ramiswailem commented 6 months ago

https://github.com/quarkusio/quarkus/issues/39950

phillip-kruger commented 6 months ago

Closing here. Duplicate