quarkusio / quarkus

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

UUID as a key map is not generated correctly in OpenAPI #42222

Closed moalshak closed 1 month ago

moalshak commented 2 months ago

Describe the bug

When using a UUID as the key for a map (in a request body), the swagger UI does not generate the example body correctly

Expected behavior

An example UUID is generated just like when used in value

Actual behavior

A random "additionalPropX" is generated

How to Reproduce?

  1. Make a project
  2. Make a resource
  3. Add a data class that takes a map (Map<UUID,..>)

import jakarta.ws.rs.POST
import jakarta.ws.rs.Path
import java.util.UUID

@Path("/example")
class ExampleResource {
    @Path("/map")
    @POST
    fun takeMap(
        myMap: MyMap
    ) : MyMap = myMap
}

data class MyMap(
    val map: Map<UUID, UUID>
)
  1. Start the app
  2. Visit DevUI swagger
image

Output of uname -a or ver

Ubuntu

Output of java -version

17

Quarkus version or git rev

3.12.3

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

8.9

Additional information

No response

quarkus-bot[bot] commented 2 months ago

/cc @MikeEdgar (swagger-ui), @geoand (kotlin), @phillip-kruger (swagger-ui)

phillip-kruger commented 2 months ago

This is an OpenAPI issue (not a swagger ui one). Changing the title to reflect that.

phillip-kruger commented 2 months ago

@MikeEdgar this might need to be reported in SmallRye ?

MikeEdgar commented 2 months ago

@MikeEdgar this might need to be reported in SmallRye ?

Yeah, possibly. Let me check how this is rendered in the OpenAPI to be sure. The OpenAPI won't have an example value by default, so the example map object shown in the screenshot may actually be generated by Swagger UI.

MikeEdgar commented 2 months ago

@moalshak , OpenAPI 3.0.x does not allow for a schema for object keys, so you will need to provide an example in the Kotlin code for this. OpenAPI 3.1.0 (which is currently under development in smallrye-open-api) will have a propertyNames attribute [1] for schemas which could possibly allow this to work automatically if Swagger UI supports it.

data class MyMap(
    @Schema(example = "... example object here...")
    val map: Map<UUID, UUID>
)

[1] https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.3.2.4

phillip-kruger commented 1 month ago

Closing here.