Repository: bkbnio/kompendium
Pull request #76 (2021-07-25 14:29:11)

Added support for BigInteger and BigDecimal in responses

rgbrizzlehizzle: LGTM 👍 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2ab557ee9..3d49e842d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
 # Changelog
 
+## [1.5.0] - July 25th, 2021
+
+### Changed
+
+- Added support for BigInteger and BigDecimal in response types
+
 ## [1.4.0] - July 22nd, 2021
 
 ### Changed
diff --git a/gradle.properties b/gradle.properties
index b7989bcd5..bd890282d 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,5 +1,5 @@
 # Kompendium
-project.version=1.4.0
+project.version=1.5.0
 # Kotlin
 kotlin.code.style=official
 # Gradle
diff --git a/kompendium-core/src/main/kotlin/io/bkbn/kompendium/Kontent.kt b/kompendium-core/src/main/kotlin/io/bkbn/kompendium/Kontent.kt
index 40d3528ec..7589f72ea 100644
--- a/kompendium-core/src/main/kotlin/io/bkbn/kompendium/Kontent.kt
+++ b/kompendium-core/src/main/kotlin/io/bkbn/kompendium/Kontent.kt
@@ -23,6 +23,8 @@ import kotlin.reflect.full.memberProperties
 import kotlin.reflect.jvm.javaField
 import kotlin.reflect.typeOf
 import org.slf4j.LoggerFactory
+import java.math.BigDecimal
+import java.math.BigInteger
 
 /**
  * Responsible for generating the schema map that is used to power all object references across the API Spec.
@@ -106,6 +108,8 @@ object Kontent {
       String::class -> cache.plus(clazz.simpleName!! to SimpleSchema("string"))
       Boolean::class -> cache.plus(clazz.simpleName!! to SimpleSchema("boolean"))
       UUID::class -> cache.plus(clazz.simpleName!! to FormatSchema("uuid", "string"))
+      BigDecimal::class -> cache.plus(clazz.simpleName!! to FormatSchema("double", "number"))
+      BigInteger::class -> cache.plus(clazz.simpleName!! to FormatSchema("int64", "integer"))
       else -> when {
         clazz.isSubclassOf(Collection::class) -> handleCollectionType(type, clazz, cache)
         clazz.isSubclassOf(Enum::class) -> handleEnumType(clazz, cache)


Test patch:
diff --git a/kompendium-core/src/test/kotlin/io/bkbn/kompendium/KontentTest.kt b/kompendium-core/src/test/kotlin/io/bkbn/kompendium/KontentTest.kt
index 14e8f5a73..2084110eb 100644
--- a/kompendium-core/src/test/kotlin/io/bkbn/kompendium/KontentTest.kt
+++ b/kompendium-core/src/test/kotlin/io/bkbn/kompendium/KontentTest.kt
@@ -13,15 +13,7 @@ import io.bkbn.kompendium.models.oas.DictionarySchema
 import io.bkbn.kompendium.models.oas.FormatSchema
 import io.bkbn.kompendium.models.oas.ObjectSchema
 import io.bkbn.kompendium.models.oas.ReferencedSchema
-import io.bkbn.kompendium.util.ComplexRequest
-import io.bkbn.kompendium.util.TestInvalidMap
-import io.bkbn.kompendium.util.TestNestedModel
-import io.bkbn.kompendium.util.TestSimpleModel
-import io.bkbn.kompendium.util.TestSimpleWithEnumList
-import io.bkbn.kompendium.util.TestSimpleWithEnums
-import io.bkbn.kompendium.util.TestSimpleWithList
-import io.bkbn.kompendium.util.TestSimpleWithMap
-import io.bkbn.kompendium.util.TestWithUUID
+import io.bkbn.kompendium.util.*
 
 @ExperimentalStdlibApi
 internal class KontentTest {
@@ -45,6 +37,18 @@ internal class KontentTest {
     assertEquals(FormatSchema("int64", "integer"), result["Long"])
   }
 
+  @Test
+  fun `Object with BigDecimal and BigInteger types`() {
+    // do
+    val result = generateKontent<TestBigNumberModel>()
+
+    // expect
+    assertEquals(3, result.count())
+    assertTrue { result.containsKey(TestBigNumberModel::class.simpleName) }
+    assertEquals(FormatSchema("double", "number"), result["BigDecimal"])
+    assertEquals(FormatSchema("int64", "integer"), result["BigInteger"])
+  }
+
   @Test
   fun `Objects reference their base types in the cache`() {
     // do
diff --git a/kompendium-core/src/test/kotlin/io/bkbn/kompendium/util/TestModels.kt b/kompendium-core/src/test/kotlin/io/bkbn/kompendium/util/TestModels.kt
index 58dd45641..7f14308db 100644
--- a/kompendium-core/src/test/kotlin/io/bkbn/kompendium/util/TestModels.kt
+++ b/kompendium-core/src/test/kotlin/io/bkbn/kompendium/util/TestModels.kt
@@ -4,9 +4,13 @@ import java.util.UUID
 import io.bkbn.kompendium.annotations.KompendiumField
 import io.bkbn.kompendium.annotations.KompendiumParam
 import io.bkbn.kompendium.annotations.ParamType
+import java.math.BigDecimal
+import java.math.BigInteger
 
 data class TestSimpleModel(val a: String, val b: Int)
 
+data class TestBigNumberModel(val a: BigDecimal, val b: BigInteger)
+
 data class TestNestedModel(val inner: TestSimpleModel)
 
 data class TestSimpleWithEnums(val a: String, val b: SimpleEnum)