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.x missing feature - configuring the schema encoder #117

Closed Sterta closed 1 month ago

Sterta commented 1 month ago

Before 3.x it was possible for example to do something like this:

typealias SchemaEncoder = (type: SchemaType) -> String?
    encoding {
        schemaEncoder { type ->
            when (type.javaType) {
                ByteArrayWrapper::class.java -> jssJson.encodeToSchema(
                    serializer = ByteArrayWrapperSerializer
                )

                UUID::class.java -> jssJson.encodeToSchema(
                  serializer = UUIDSerializer
                )
                OffsetDateTime::class.java -> jssJson.encodeToSchema(
                    serializer = OffsetDateTimeSerializer
                )

                else -> {
                    jssJson.encodeToSchema(
                        serializer = serializer(type)
                    )
                }
            }
        }
        schemaDefinitionsField = "definitions"
    }

For the example encoder it is possible with 3.x.

I couldn't find a way to implement the schema encoder example with 3.x.

Is this not possible anymore, or is their a way?

If not, is it possible to add this functionality again?

SMILEY4 commented 1 month ago

The "old" schema generator was replaced with a completely new one which works a quite bit different now. You can customize this new schema generator, some information here.

You can then for example:

there is currently also an open issue about custom schema for LocalDateTime that might be relevant.

I hope these links are helpful enough. I'm still working on the new schema generator and the wiki, so if you encounter any questions or issues, please let me know.