<@U0B8ZP13Q> What do you think about making the `K...
# klaxon
j
@cedric What do you think about making the
KlaxonJson
an interface? I have this huge object that I scope all my schema generation logic over
Copy code
class SchemaGenerator() {

    fun KlaxonJson.obj(fields: List<Pair<String, *>>) =
        obj(*fields.toTypedArray())

    fun KlaxonJson.arrayObj(type: String, description: String? = null) =
        objNullable(
            type("array"),
            description?.let { description(it) },
            "items" to obj(
                type(type)
            )
        )

    fun KlaxonJson.allOf(vararg schemas: JsonObject) =
        "allOf" to array(*schemas)

    fun KlaxonJson.oneOf(vararg schemas: JsonObject) =
        "oneOf" to array(*schemas)

   fun KlaxonJson.arrayObj(schema: JsonSchema, description: String? = null) =
        objNullable(
            type("array"),
            description?.let { description(it) },
            "items" to refObj(schema)
        )

    fun KlaxonJson.booleanObj() =
        obj(
            type("boolean")
        )

    fun KlaxonJson.shortObj() =
        obj(
            type("integer"),
            "minimum" to Short.MIN_VALUE.toInt(),
            "maximum" to Short.MAX_VALUE.toInt()
        )
.....
And in order to use it I have to do something like:
Copy code
fun SchemaGenerator.useIt() : JsonObject {
   // Here I can't use the KlaxonJson extensions.
    json {
        // Now I can use the KlaxonJson extensions on the SchemaGenerator
   }
}
It would allow me to do this:
Copy code
fun SchemaGenerator.useIt() : JsonObject {
   // I can use the KlaxonJson extensions on the SchemaGenerator
}
Thoughts?