Skip to content

Commit

Permalink
#54 Support for Timestamp, BigDecimal, and BigInt (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakipatryk committed Apr 18, 2024
1 parent 9344a0c commit 76f9c4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import scala.collection.JavaConverters._
import scala.reflect.runtime.universe._
import OpenAPIModelRegistration._

import java.sql.Timestamp

class OpenAPIModelRegistration(
components: Components,
extraTypesHandler: ExtraTypesHandling.ExtraTypesHandler = ExtraTypesHandling.noExtraHandling,
Expand Down Expand Up @@ -243,6 +245,9 @@ class OpenAPIModelRegistration(
case t if t =:= typeOf[LocalDateTime] => OpenAPISimpleType("string", Some("date-time"))
case t if t =:= typeOf[LocalDate] => OpenAPISimpleType("string", Some("date"))
case t if t =:= typeOf[LocalTime] => OpenAPISimpleType("string", Some("time"))
case t if t =:= typeOf[Timestamp] => OpenAPISimpleType("string", Some("date-time"))
case t if t =:= typeOf[BigDecimal] => OpenAPISimpleType("number")
case t if t =:= typeOf[BigInt] => OpenAPISimpleType("integer")
}

private def registerAsReference(name: String, schema: Schema[_]): Schema[_] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ package za.co.absa.springdocopenapiscala

import io.swagger.v3.oas.models.Components
import io.swagger.v3.oas.models.media.Schema

import org.scalatest
import org.scalatest.flatspec.AnyFlatSpec

import java.time.{Instant, LocalDate, LocalDateTime, LocalTime, ZonedDateTime}
import java.util.UUID
import scala.collection.JavaConverters._
import scala.reflect.runtime.universe._

import za.co.absa.springdocopenapiscala.OpenAPIModelRegistration.ExtraTypesHandling

import java.sql.Timestamp

class OpenAPIModelRegistrationSpec extends AnyFlatSpec {

private case class OnlySimpleTypes(
Expand All @@ -47,7 +47,10 @@ class OpenAPIModelRegistrationSpec extends AnyFlatSpec {
o: Instant,
p: LocalDateTime,
r: LocalDate,
s: LocalTime
s: LocalTime,
t: BigDecimal,
w: BigInt,
z: Timestamp
)

private case class SimpleTypesMaybeInOption(
Expand Down Expand Up @@ -194,6 +197,9 @@ class OpenAPIModelRegistrationSpec extends AnyFlatSpec {
assertTypeAndFormatAreAsExpected(actualSchemas, "OnlySimpleTypes.p", "string", Some("date-time"))
assertTypeAndFormatAreAsExpected(actualSchemas, "OnlySimpleTypes.r", "string", Some("date"))
assertTypeAndFormatAreAsExpected(actualSchemas, "OnlySimpleTypes.s", "string", Some("time"))
assertTypeAndFormatAreAsExpected(actualSchemas, "OnlySimpleTypes.t", "number")
assertTypeAndFormatAreAsExpected(actualSchemas, "OnlySimpleTypes.w", "integer")
assertTypeAndFormatAreAsExpected(actualSchemas, "OnlySimpleTypes.z", "string", Some("date-time"))
}

it should "mark all non-Option fields of case class as required" in {
Expand Down

0 comments on commit 76f9c4d

Please sign in to comment.