Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin nullable File/FileUpload missing upload button #2187

Open
BrianSetz opened this issue Jan 31, 2025 · 4 comments
Open

Kotlin nullable File/FileUpload missing upload button #2187

BrianSetz opened this issue Jan 31, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@BrianSetz
Copy link
Contributor

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
Copy link
Contributor Author

The workaround comes from a previous issue of mine: quarkusio/quarkus#39950

@MikeEdgar MikeEdgar added the bug Something isn't working label Feb 8, 2025
@MikeEdgar
Copy link
Member

@BrianSetz I suspect this may be a bug with Swagger UI not handling the type: [ string, "null" ] in OAS 3.1.0. Can you try it with an OAS 3.0.x output? It can be generated by setting the following property.

mp.openapi.extensions.smallrye.openapi=3.0.3

@BrianSetz
Copy link
Contributor Author

@MikeEdgar I can confirm that 3.0.3 produces the correct output!

@MikeEdgar
Copy link
Member

As far as I can tell, this is because Swagger UI is only supporting a string value [1] for type (not an array as is the result in OAS 3.1 for a nullable file). It may be worth opening an issue (or commenting on an existing issue if there is one) to improve support for this scenario when OpenAPI 3.1 is being used. The link below is for the oas3 request body component. I do not see a separate oas31 component, which would probably be the place to start.

[1] https://github.com/swagger-api/swagger-ui/blob/96b0d361b206d34d82543a9d05fb2140fe03d881/src/core/plugins/oas3/components/request-body.jsx#L189

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants