fix: uuid schema (#296)
This commit is contained in:
@ -14,6 +14,7 @@ import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
import kotlin.reflect.typeOf
|
||||
import java.util.UUID
|
||||
|
||||
object SchemaGenerator {
|
||||
inline fun <reified T : Any?> fromTypeToSchema(cache: MutableMap<String, JsonSchema> = mutableMapOf()) =
|
||||
@ -37,6 +38,7 @@ object SchemaGenerator {
|
||||
Float::class -> checkForNull(type, TypeDefinition.FLOAT)
|
||||
String::class -> checkForNull(type, TypeDefinition.STRING)
|
||||
Boolean::class -> checkForNull(type, TypeDefinition.BOOLEAN)
|
||||
UUID::class -> checkForNull(type, TypeDefinition.UUID)
|
||||
else -> when {
|
||||
clazz.isSubclassOf(Enum::class) -> EnumHandler.handle(type, clazz)
|
||||
clazz.isSubclassOf(Collection::class) -> CollectionHandler.handle(type, cache)
|
||||
|
@ -40,6 +40,11 @@ data class TypeDefinition(
|
||||
type = "string"
|
||||
)
|
||||
|
||||
val UUID = TypeDefinition(
|
||||
type = "string",
|
||||
format = "uuid"
|
||||
)
|
||||
|
||||
val BOOLEAN = TypeDefinition(
|
||||
type = "boolean"
|
||||
)
|
||||
|
@ -12,6 +12,7 @@ import io.kotest.assertions.json.shouldEqualJson
|
||||
import io.kotest.assertions.throwables.shouldThrow
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.util.UUID
|
||||
|
||||
class SchemaGeneratorTest : DescribeSpec({
|
||||
describe("Scalars") {
|
||||
@ -24,6 +25,9 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
it("Can generate the schema for a String") {
|
||||
jsonSchemaTest<String>("T0003__scalar_string.json")
|
||||
}
|
||||
it("Can generate the schema for a UUID") {
|
||||
jsonSchemaTest<UUID>("T0017__scalar_uuid.json")
|
||||
}
|
||||
}
|
||||
describe("Objects") {
|
||||
it("Can generate the schema for a simple object") {
|
||||
|
4
json-schema/src/test/resources/T0017__scalar_uuid.json
Normal file
4
json-schema/src/test/resources/T0017__scalar_uuid.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
}
|
Reference in New Issue
Block a user