apache / incubator-kie-kogito-runtimes

Kogito Runtimes - Kogito is a cloud-native business automation technology for building cloud-ready business applications.
http://kogito.kie.org
Apache License 2.0
543 stars 210 forks source link

Sonataflow OpenAPI UploadFile API #3767

Closed fjtirado closed 1 week ago

fjtirado commented 1 week ago

Description

An OpenAPI operation that is defined in the spec file as

 operationId: uploadJar
      requestBody:
        content:
          application/x-java-archive:
            schema:
              type: string
              format: binary

when processed by openapi quarkiverse extension is transformed to the following Java method


  @POST
    @Path("/jars/upload")
    @Consumes({"application/x-java-archive"})
    @Produces({"application/json"})
    @GeneratedMethod ("uploadJar")
    public JarUploadResponseBody uploadJar(
        File body

    );

Currently, SonataFlow implementation is not able to invoke that method, since the generated briged to perform the operation will never work (there is not way to convert a JsonObject to a File withtou aditional logic)

protected Object internalExecute(org.kie.kogito.openapi.flinkapi.api.DefaultApi openApiRef, java.util.Map<java.lang.String, java.lang.Object> parameters) {
        return openApiRef.uploadJar(buildBody(parameters, java.io.File.class));
    }

This issue has been opened to add the misisng logic to create a File object from the function call arguments. In particular, for an OpenAPI operation which has a File as argument, the argument of the function call in the workflow definition must be a string with the file location in disk

A YAML example:

 functionRef:
          refName: uploadJar
          arguments: /uploading/file/path/file.txt

After this change, it will be possible to upload files that are accessible in the local file system.

Implementation ideas

When the target class of the buildBody call is a File, assume that the paramters map contains one entry of type string and build the File object from that string.