SMILEY4 / ktor-swagger-ui

Kotlin Ktor plugin to generate OpenAPI and provide Swagger UI
Apache License 2.0
182 stars 33 forks source link

Incorrect display of UUIDs in Swagger between versions 2.10.0 and 3.0.0 #102

Closed Ziedelth closed 5 months ago

Ziedelth commented 5 months ago

Hi there,

I noticed a problem with the UUID display in Swagger between versions 2.10.0 and 3.0.0. Before, the display indicated that it was a UUID string, but now it indicates that it is an object.

Is this normal behavior?

Thanks for your help.

Version 2.10.0 image

Version 3.0.0 image

SMILEY4 commented 5 months ago

Hi, i switched to my own library for generating schemas for objects. It seems like the previous generator automatically encoded UUIDs as strings which is not a default behavior with the new one. You can configure this manually by customizing the schema generator and overwriting or redirecting UUIDs to strings

I tested it by simply "redirecting" and it produced the desired result:

install(SwaggerUI) {
    schemas {
        generator = { type ->
            type
                .collectSubTypes()
                .processReflection {
                    redirect<UUID, String>() // redirect UUID to string, i.e treat is as a string for schema generation
                }
                .connectSubTypes()
                .handleNameAnnotation()
                .generateSwaggerSchema()
                .handleCoreAnnotations()
                .withAutoTitle(TitleType.SIMPLE)
                .compileReferencingRoot()
        }
    }
}