smallrye-open-api icon indicating copy to clipboard operation
smallrye-open-api copied to clipboard

Kotlin nullable File/FileUpload missing upload button

Open BrianSetz opened this issue 11 months ago • 4 comments

I am observing some unexpected behaviour for nullable (meaning optional) File and Fileuploads.

package org.example

import jakarta.ws.rs.POST
import jakarta.ws.rs.Path
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType
import org.eclipse.microprofile.openapi.annotations.media.Schema
import org.jboss.resteasy.reactive.RestForm
import org.jboss.resteasy.reactive.multipart.FileUpload
import java.io.File

@Path("/hello")
class ExampleResource {
    @POST
    @Path("/int")
    fun postInt(@RestForm int: Int): String {
        // Do nothing
        return "Int"
    }

    @POST
    @Path("/intNullable")
    fun postNullableInt(@RestForm int: Int?): String {
        // Do nothing
        return "Int?"
    }

    @POST
    @Path("/string")
    fun postString(@RestForm string: String): String {
        // Do nothing
        return "String"
    }

    @POST
    @Path("/stringNullable")
    fun postNullableString(@RestForm string: String?): String {
        // Do nothing
        return "String?"
    }

    @POST
    @Path("/file")
    fun postFile(@RestForm file: File): String {
        // Do nothing
        return "File"
    }

    @POST
    @Path("/fileNullable")
    fun postNullableFile(@RestForm file: File?): String {
        // Do nothing
        return "File?"
    }

    @POST
    @Path("/fileNullableFix")
    fun postNullableFileWithFix(@RestForm @Schema(implementation = BinaryStringSchema::class) file: File?): String {
        // Do nothing
        return "File?"
    }

    @POST
    @Path("/fileupload")
    fun postFileUpload(@RestForm fileUpload: FileUpload): String {
        // Do nothing
        return "FileUpload"
    }

    @POST
    @Path("/fileuploadNullable")
    fun postNullableFileUpload(@RestForm fileUpload: FileUpload?): String {
        // Do nothing
        return "FileUpload?"
    }

    @POST
    @Path("/fileuploadNullableFix")
    fun postNullableFileUploadWithFix(@RestForm @Schema(implementation = BinaryStringSchema::class) fileUpload: FileUpload?): String {
        // Do nothing
        return "FileUpload?"
    }
}

@Schema(type = SchemaType.STRING, format = "binary")
interface BinaryStringSchema

File (upload button):

Image

File? (without upload button):

Image

File? (with schema workaround):

Image

The behaviour works as expected for nullable Ints and Strings, but it breaks for nullable Files and FileUploads (potentially others too?).

I would expect a nullable File(Upload) to have upload buttons just like non-nullable File(Upload).

BrianSetz avatar Jan 31 '25 12:01 BrianSetz