added special case to support UUID field (#19)
This commit is contained in:
@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## [0.1.1] - April 16th, 2021
|
||||
|
||||
### Added
|
||||
|
||||
- Explicit UUID support to prevent incorrect interpretation as complex object
|
||||
|
||||
## [0.1.0] - April 16th, 2021
|
||||
|
||||
### Changed
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Kompendium
|
||||
project.version=0.1.0
|
||||
project.version=0.1.1
|
||||
# Kotlin
|
||||
kotlin.code.style=official
|
||||
# Gradle
|
||||
|
@ -1,11 +1,13 @@
|
||||
package org.leafygreens.kompendium
|
||||
|
||||
import java.lang.reflect.ParameterizedType
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
import kotlin.reflect.full.memberProperties
|
||||
import kotlin.reflect.jvm.javaField
|
||||
import org.leafygreens.kompendium.models.meta.SchemaMap
|
||||
import org.leafygreens.kompendium.models.oas.ArraySchema
|
||||
import org.leafygreens.kompendium.models.oas.DictionarySchema
|
||||
import org.leafygreens.kompendium.models.oas.EnumSchema
|
||||
@ -20,8 +22,6 @@ import org.leafygreens.kompendium.util.Helpers.logged
|
||||
import org.leafygreens.kompendium.util.Helpers.toPair
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
typealias SchemaMap = Map<String, OpenApiSpecComponentSchema>
|
||||
|
||||
object Kontent {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
@ -38,6 +38,7 @@ object Kontent {
|
||||
clazz == Float::class -> cache.plus(clazz.simpleName!! to FormatSchema("float", "number"))
|
||||
clazz == String::class -> cache.plus(clazz.simpleName!! to SimpleSchema("string"))
|
||||
clazz == Boolean::class -> cache.plus(clazz.simpleName!! to SimpleSchema("boolean"))
|
||||
clazz == UUID::class -> cache.plus(clazz.simpleName!! to FormatSchema("uuid", "string"))
|
||||
clazz.isSubclassOf(Enum::class) -> error("Top level enums are currently not supported by Kompendium")
|
||||
clazz.typeParameters.isNotEmpty() -> error("Top level generics are not supported by Kompendium")
|
||||
else -> handleComplexType(clazz, cache)
|
||||
|
@ -0,0 +1,5 @@
|
||||
package org.leafygreens.kompendium.models.meta
|
||||
|
||||
import org.leafygreens.kompendium.models.oas.OpenApiSpecComponentSchema
|
||||
|
||||
typealias SchemaMap = Map<String, OpenApiSpecComponentSchema>
|
@ -1,5 +1,6 @@
|
||||
package org.leafygreens.kompendium
|
||||
|
||||
import java.util.UUID
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
@ -16,6 +17,7 @@ import org.leafygreens.kompendium.util.TestSimpleWithEnumList
|
||||
import org.leafygreens.kompendium.util.TestSimpleWithEnums
|
||||
import org.leafygreens.kompendium.util.TestSimpleWithList
|
||||
import org.leafygreens.kompendium.util.TestSimpleWithMap
|
||||
import org.leafygreens.kompendium.util.TestWithUUID
|
||||
|
||||
internal class KontentTest {
|
||||
|
||||
@ -166,4 +168,21 @@ internal class KontentTest {
|
||||
assertFailsWith<java.lang.IllegalStateException> { generateKontent(clazz) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `UUID schema support`() {
|
||||
// when
|
||||
val clazz = TestWithUUID::class
|
||||
|
||||
// do
|
||||
val result = generateKontent(clazz)
|
||||
|
||||
// expect
|
||||
assertNotNull(result)
|
||||
assertEquals(2, result.count())
|
||||
assertTrue { result.containsKey(UUID::class.simpleName) }
|
||||
assertTrue { result.containsKey(clazz.simpleName) }
|
||||
val expectedSchema = result[UUID::class.simpleName] as FormatSchema
|
||||
assertEquals(FormatSchema("uuid", "string"), expectedSchema)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.leafygreens.kompendium.util
|
||||
|
||||
import java.util.UUID
|
||||
import org.leafygreens.kompendium.annotations.KompendiumField
|
||||
import org.leafygreens.kompendium.annotations.KompendiumRequest
|
||||
import org.leafygreens.kompendium.annotations.KompendiumResponse
|
||||
@ -22,6 +23,8 @@ data class TestParams(val a: String, val aa: Int)
|
||||
|
||||
data class TestNested(val nesty: String)
|
||||
|
||||
data class TestWithUUID(val id: UUID)
|
||||
|
||||
@KompendiumRequest("Example Request")
|
||||
data class TestRequest(
|
||||
@KompendiumField(name = "field_name")
|
||||
|
Reference in New Issue
Block a user