jlleitschuh
09/20/2018, 12:02 AMKlaxonJson
an interface?
I have this huge object that I scope all my schema generation logic over
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:
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:
fun SchemaGenerator.useIt() : JsonObject {
// I can use the KlaxonJson extensions on the SchemaGenerator
}
Thoughts?