chore: clean up some bad habits
This commit is contained in:
@ -14,7 +14,8 @@ import kotlin.reflect.KType
|
||||
object CollectionHandler {
|
||||
|
||||
fun handle(type: KType, cache: MutableMap<String, JsonSchema>): JsonSchema {
|
||||
val collectionType = type.arguments.first().type!!
|
||||
val collectionType = type.arguments.first().type
|
||||
?: error("This indicates a bug in Kompendium, please open a GitHub issue!")
|
||||
val typeSchema = SchemaGenerator.fromTypeToSchema(collectionType, cache).let {
|
||||
if (it is TypeDefinition && it.type == "object") {
|
||||
cache[collectionType.getSimpleSlug()] = it
|
||||
|
@ -15,10 +15,10 @@ import kotlin.reflect.KType
|
||||
object MapHandler {
|
||||
|
||||
fun handle(type: KType, cache: MutableMap<String, JsonSchema>): JsonSchema {
|
||||
require(type.arguments.first().type!!.classifier as KClass<*> == String::class) {
|
||||
require(type.arguments.first().type?.classifier as KClass<*> == String::class) {
|
||||
"JSON requires that map keys MUST be Strings. You provided ${type.arguments.first().type}"
|
||||
}
|
||||
val valueType = type.arguments[1].type!!
|
||||
val valueType = type.arguments[1].type ?: error("this indicates a bug in Kompendium, please open a GitHub issue")
|
||||
val valueSchema = SchemaGenerator.fromTypeToSchema(valueType, cache).let {
|
||||
if (it is TypeDefinition && it.type == "object") {
|
||||
cache[valueType.getSimpleSlug()] = it
|
||||
|
@ -92,7 +92,8 @@ object SimpleObjectHandler {
|
||||
typeMap: Map<KTypeParameter, KTypeProjection>,
|
||||
cache: MutableMap<String, JsonSchema>
|
||||
): JsonSchema {
|
||||
val type = typeMap[prop.returnType.classifier]?.type!!
|
||||
val type = typeMap[prop.returnType.classifier]?.type
|
||||
?: error("This indicates a bug in Kompendium, please open a GitHub issue")
|
||||
return SchemaGenerator.fromTypeToSchema(type, cache).let {
|
||||
if (it.isOrContainsObjectDef()) {
|
||||
cache[type.getSimpleSlug()] = it
|
||||
@ -119,5 +120,5 @@ object SimpleObjectHandler {
|
||||
return isTypeDef || isTypeDefOneOf
|
||||
}
|
||||
|
||||
private fun JsonSchema.isNullable(): Boolean = this is OneOfDefinition && this.oneOf.any{ it is NullableDefinition }
|
||||
private fun JsonSchema.isNullable(): Boolean = this is OneOfDefinition && this.oneOf.any { it is NullableDefinition }
|
||||
}
|
||||
|
Reference in New Issue
Block a user