micronaut-projects / micronaut-openapi

Generates OpenAPI / Swagger Documentation for Micronaut projects
https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html
Apache License 2.0
80 stars 95 forks source link

There is no way to receive a file with Streaming using the OpenAPI generator #1721

Closed giovanabartholomeu closed 2 months ago

giovanabartholomeu commented 2 months ago

Issue description

Swagger-codegen version 3.0.1

Description When I generate a yaml to receive a file from the controller, by default it generates the CompletedFileUpload parameter:

requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary

Generated interface:

@Post("/products")
    @Consumes("multipart/form-data")
    @Secured(SecurityRule.IS_ANONYMOUS)
    HttpResponse<@Valid Product> productsPost(
        @Nullable(inherited = true) CompletedFileUpload file
    );

Controller implements:

@io.micronaut.http.annotation.Controller
public class Controller implements DefaultApi {

    @Override
    public HttpResponse<@Valid Product> productsPost(CompletedFileUpload file) {
        return HttpResponse.ok(null);
    }

But, I would like to upload files using StreamingFileUpload. How should I reference it in my yaml so that the generated parameter is a StreamingFileUpload and not a CompletedFileUpload?

altro3 commented 2 months ago

you are wrong, there is a way to do it. Just add type mapping via gradle plugin like this:

    openapi {
        server(file("swagger.yml")) {
            useReactive = false
            typeMapping = [
                    file : "StreamingFileUpload"
            ]
        }
    }
giovanabartholomeu commented 2 months ago

Well, I use Maven instead of Gradle, so it only worked for me when I did it this way:

multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: StreamingFileUpload
                  format: binary

I didn’t need to import anything :) thanks

altro3 commented 2 months ago

@giovanabartholomeu

Got it. Well, I've added support for all the generator's features to the maven plugin. Wait for the next release of the plugin, after that you'll be able to add mapping like in the gradle:

      <plugin>
        <groupId>io.micronaut.maven</groupId>
        <artifactId>micronaut-maven-plugin</artifactId>
        <version>${micronaut-maven-plugin.version}</version>
        <configuration>
          <lombok>true</lombok>
          <typeMapping>
            <file>StreamingFileUpload</file>
          </typeMapping>
        </configuration>
      </plugin>

https://github.com/micronaut-projects/micronaut-maven-plugin/pull/1185