SMILEY4 / ktor-swagger-ui

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

V3.0 Abillity to add discriminator property to anyOf body #109

Open MikeDirven opened 2 months ago

MikeDirven commented 2 months ago

I am missing the option to add a discriminator property to a body that can contain anyOf a specified sealed interface.

this is the body code i am using and cannot find any possibility to add the discriminator property as descript in the openApi spec: https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/#:~:text=or%20complexObject.-,Discriminator,-To%20help%20API

The sealed interface

@Serializable
sealed interface NewUser {
    val username: String
    val password: String
    /**
     * List of role id's to add to the user.
     */
    val roles: List<Long>?

    @Serializable
    data class NewUserDto(
        override val username: String,
        override val password: String,
        override val roles: List<Long>? = null,
        val relation: RelationDto,
    ) : NewUser

    @Serializable
    data class NewUserWithRelationDto(
        override val username: String,
        override val password: String,
        override val roles: List<Long>? = null,
        /**
         * The id of the existing relation to add to this user
         */
        val relation: Long
    ) : NewUser
}

The route documentation

val postUserDocumentation : RouteDocumentation
        get() = {
            tags = setOf(TAG)
            description = "Create new user"
            securitySchemeNames = setOf("Kargro_Identity")
            response {
                HttpStatusCode.OK to Unit
            }
            request {
                body<NewUser>()
            }
        }
SMILEY4 commented 1 month ago

Hi, sorry for the late response. I'll try to see what i can do :+1: