Skip to content

Instantly share code, notes, and snippets.

@takezoe
Last active November 23, 2018 01:27
Show Gist options
  • Save takezoe/61f6fb79f1b27dbae6bfcd8a91a63dd4 to your computer and use it in GitHub Desktop.
Save takezoe/61f6fb79f1b27dbae6bfcd8a91a63dd4 to your computer and use it in GitHub Desktop.
diff --git a/swagger/src/main/scala/org/scalatra/swagger/Swagger.scala b/swagger/src/main/scala/org/scalatra/swagger/Swagger.scala
index 97e00e46..f5525ca2 100644
--- a/swagger/src/main/scala/org/scalatra/swagger/Swagger.scala
+++ b/swagger/src/main/scala/org/scalatra/swagger/Swagger.scala
@@ -45,16 +45,6 @@ trait SwaggerEngine[T <: SwaggerApi[_]] {
object Swagger {
- val excludes: Set[java.lang.reflect.Type] = Set(
- classOf[java.util.TimeZone],
- classOf[java.util.Date],
- classOf[java.time.OffsetDateTime],
- classOf[java.time.ZonedDateTime],
- classOf[java.time.LocalDateTime],
- classOf[java.time.LocalDate],
- classOf[java.time.Instant],
- classOf[java.time.chrono.Chronology],
- classOf[java.time.ZoneOffset])
val SpecVersion = "2.0"
def collectModels[T: Manifest](alreadyKnown: Set[Model]): Set[Model] = collectModels(Reflector.scalaTypeOf[T], alreadyKnown)
@@ -111,7 +101,8 @@ object Swagger {
prop.name -> mp
}
def modelToSwagger(klass: ScalaType): Option[Model] = {
- if (Reflector.isPrimitive(klass.erasure) || Reflector.isExcluded(klass.erasure, excludes.toSeq)) None
+
+ if (Reflector.isPrimitive(klass.erasure)) None
else {
val name = klass.simpleName
diff --git a/swagger/src/main/scala/org/scalatra/swagger/reflect/descriptors.scala b/swagger/src/main/scala/org/scalatra/swagger/reflect/descriptors.scala
index 51e8c7cf..4cc68509 100644
--- a/swagger/src/main/scala/org/scalatra/swagger/reflect/descriptors.scala
+++ b/swagger/src/main/scala/org/scalatra/swagger/reflect/descriptors.scala
@@ -19,6 +19,10 @@ object ManifestScalaType {
else if (mf.runtimeClass == classOf[Boolean] || mf.runtimeClass == classOf[java.lang.Boolean]) ManifestScalaType.BooleanType
else if (mf.runtimeClass == classOf[String] || mf.runtimeClass == classOf[java.lang.String]) ManifestScalaType.StringType
else if (mf.runtimeClass == classOf[java.util.Date]) ManifestScalaType.DateType
+ else if (mf.runtimeClass == classOf[java.time.OffsetDateTime]) ManifestScalaType.OffsetDateTimeType
+ else if (mf.runtimeClass == classOf[java.time.ZonedDateTime]) ManifestScalaType.ZonedDateTimeType
+ else if (mf.runtimeClass == classOf[java.time.LocalDateTime]) ManifestScalaType.LocalDateTimeType
+ else if (mf.runtimeClass == classOf[java.time.LocalDate]) ManifestScalaType.LocalDateType
else if (mf.runtimeClass == classOf[java.sql.Timestamp]) ManifestScalaType.TimestampType
else if (mf.runtimeClass == classOf[Symbol]) ManifestScalaType.SymbolType
else if (mf.runtimeClass == classOf[Number]) ManifestScalaType.NumberType
@@ -53,6 +57,10 @@ object ManifestScalaType {
private val BigDecimalType: ScalaType = new PrimitiveManifestScalaType(manifest[BigDecimal])
private val BigIntType: ScalaType = new PrimitiveManifestScalaType(manifest[BigInt])
private val DateType: ScalaType = new PrimitiveManifestScalaType(manifest[java.util.Date])
+ private val OffsetDateTimeType: ScalaType = new PrimitiveManifestScalaType(manifest[java.time.OffsetDateTime])
+ private val ZonedDateTimeType: ScalaType = new PrimitiveManifestScalaType(manifest[java.time.ZonedDateTime])
+ private val LocalDateTimeType: ScalaType = new PrimitiveManifestScalaType(manifest[java.time.LocalDateTime])
+ private val LocalDateType: ScalaType = new PrimitiveManifestScalaType(manifest[java.time.LocalDate])
private val TimestampType: ScalaType = new PrimitiveManifestScalaType(manifest[java.sql.Timestamp])
private class PrimitiveManifestScalaType(mf: Manifest[_]) extends ManifestScalaType(mf) {
@@ -175,6 +183,10 @@ class ManifestScalaType(val manifest: Manifest[_]) extends ScalaType {
else if (erasure == classOf[Boolean] || erasure == classOf[java.lang.Boolean]) ManifestScalaType.BooleanType
else if (erasure == classOf[String] || erasure == classOf[java.lang.String]) ManifestScalaType.StringType
else if (erasure == classOf[java.util.Date]) ManifestScalaType.DateType
+ else if (erasure == classOf[java.time.OffsetDateTime]) ManifestScalaType.OffsetDateTimeType
+ else if (erasure == classOf[java.time.ZonedDateTime]) ManifestScalaType.ZonedDateTimeType
+ else if (erasure == classOf[java.time.LocalDateTime]) ManifestScalaType.LocalDateTimeType
+ else if (erasure == classOf[java.time.LocalDate]) ManifestScalaType.LocalDateType
else if (erasure == classOf[java.sql.Timestamp]) ManifestScalaType.TimestampType
else if (erasure == classOf[Symbol]) ManifestScalaType.SymbolType
else if (erasure == classOf[Number]) ManifestScalaType.NumberType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment