Skip to content

Commit b1a468c

Browse files
committed
merged from develop scala 2.10
2 parents 684b906 + b247904 commit b1a468c

File tree

78 files changed

+858
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+858
-331
lines changed

modules/swagger-core/src/main/scala/com/wordnik/swagger/converter/ModelConverters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ trait ModelConverter {
155155
def toDescriptionOpt(cls: Class[_]): Option[String]
156156

157157
def ignoredPackages: Set[String] = Set("java.lang")
158-
def ignoredClasses: Set[String] = Set("java.util.Date")
158+
def ignoredClasses: Set[String] = Set("java.util.Date", "java.math.BigDecimal")
159159

160160
def typeMap = Map[String, String]()
161161

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.wordnik.swagger.core
22

33
object SwaggerSpec {
4-
val baseTypes = Set("byte", "boolean", "int", "long", "float", "double", "string", "date", "void", "Date")
4+
val baseTypes = Set("byte", "boolean", "int", "long", "float", "double", "string", "date", "void", "Date", "BigDecimal", "UUID")
55
val containerTypes = Set("Array", "List", "Set")
66
val version = "1.2"
77
}

modules/swagger-core/src/main/scala/com/wordnik/swagger/model/SwaggerSerializers.scala

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,20 @@ object SwaggerSerializers extends Serializers {
101101

102102
def toJsonSchema(name: String, `type`: String): JObject = {
103103
`type` match {
104-
case "int" => (name -> "integer") ~ ("format" -> "int32")
105-
case "long" => (name -> "integer") ~ ("format" -> "int64")
106-
case "float" => (name -> "number") ~ ("format" -> "float")
107-
case "double" => (name -> "number") ~ ("format" -> "double")
108-
case "string" => (name -> "string") ~ ("format" -> JNothing)
109-
case "byte" => (name -> "string") ~ ("format" -> "byte")
110-
case "boolean" => (name -> "boolean") ~ ("format" -> JNothing)
111-
case "Date" => (name -> "string") ~ ("format" -> "date-time")
112-
case "DateTime" => (name -> "string") ~ ("format" -> "date-time")
113-
case "date" => (name -> "string") ~ ("format" -> "date")
114-
case "date-time" => (name -> "string") ~ ("format" -> "date-time")
115-
case _ => {
104+
case "int" => (name -> "integer") ~ ("format" -> "int32")
105+
case "long" => (name -> "integer") ~ ("format" -> "int64")
106+
case "float" => (name -> "number") ~ ("format" -> "float")
107+
case "double" => (name -> "number") ~ ("format" -> "double")
108+
case "string" => (name -> "string") ~ ("format" -> JNothing)
109+
case "byte" => (name -> "string") ~ ("format" -> "byte")
110+
case "boolean" => (name -> "boolean") ~ ("format" -> JNothing)
111+
case "Date" => (name -> "string") ~ ("format" -> "date-time")
112+
case "DateTime" => (name -> "string") ~ ("format" -> "date-time")
113+
case "BigDecimal" => (name -> "number")
114+
case "UUID" => (name -> "string") ~ ("format" -> "uuid")
115+
case "date" => (name -> "string") ~ ("format" -> "date")
116+
case "date-time" => (name -> "string") ~ ("format" -> "date-time")
117+
case _ => {
116118
val ComplexTypeMatcher = "([a-zA-Z]*)\\[([a-zA-Z\\.\\-]*)\\].*".r
117119
`type` match {
118120
case ComplexTypeMatcher(container, value) =>
@@ -162,7 +164,9 @@ object SwaggerSerializers extends Serializers {
162164
case ("integer", "int64") => "long"
163165
case ("number", "float") => "float"
164166
case ("number", "double") => "double"
167+
case ("number", _) => "bigDecimal"
165168
case ("string", "byte") => "byte"
169+
case ("string", "uuid") => "uuid"
166170
case ("boolean", _) => "boolean"
167171
case ("string", "date") => "date"
168172
case ("string", "date-time") => "date-time"
@@ -236,19 +240,10 @@ object SwaggerSerializers extends Serializers {
236240
("authorizations" -> {
237241
x.authorizations match {
238242
case e: List[Authorization] if (e.size > 0) => {
239-
var open = false
240-
val o = ((for(at <- e) yield {
241-
if(at.`type` == "open") {
242-
open = true
243-
None
244-
}
245-
else if(at.`type` != "")
246-
Some(at.`type`, at)
247-
else
248-
None
243+
Extraction.decompose((for(at: Authorization <- e) yield {
244+
if(at.`type` != "") Some(at.`type`, at)
245+
else None
249246
}).flatten.toMap)
250-
if(o.size > 0 || open) Extraction.decompose(o)
251-
else JNothing
252247
}
253248
case _ => JNothing
254249
}
@@ -497,9 +492,9 @@ trait Serializers {
497492
}) ~
498493
("authorizations" -> {
499494
x.authorizations match {
500-
case e: List[AuthorizationType] if (e.size > 0) => {
501-
Extraction.decompose((for(at <- e) yield {
502-
if(at.`type` != "") Some(at.getName, at)
495+
case e: List[Authorization] if (e.size > 0) => {
496+
Extraction.decompose((for(at: Authorization <- e) yield {
497+
if(at.`type` != "") Some(at.`type`, at)
503498
else None
504499
}).flatten.toMap)
505500
}
@@ -557,8 +552,8 @@ trait Serializers {
557552
("authorizations" -> {
558553
x.authorizations match {
559554
case e: List[AuthorizationType] if (e.size > 0) => {
560-
Extraction.decompose((for(at <- e) yield {
561-
if(at.`type` != "") Some(at.getName, at)
555+
Extraction.decompose((for(at: AuthorizationType <- e) yield {
556+
if(at.`type` != "") Some(at.`type`, at)
562557
else None
563558
}).flatten.toMap)
564559
}
@@ -748,13 +743,14 @@ trait Serializers {
748743
}) ~
749744
("authorizations" -> {
750745
x.authorizations match {
751-
case e: List[AuthorizationType] if (e.size > 0) => {
752-
Extraction.decompose((for(at <- e) yield {
753-
if(at.getName != "") {
754-
Some(at.getName, at)
755-
}
756-
else None
757-
}).flatten.toMap)
746+
case e: List[Authorization] if (e.size > 0) => {
747+
val out = (for(at: Authorization <- e) yield {
748+
if(at.`type` != "") {
749+
Some(at.`type`, at)
750+
}
751+
else None
752+
}).flatten.toMap
753+
Extraction.decompose(out)
758754
}
759755
case _ => JNothing
760756
}
@@ -937,7 +933,7 @@ trait Serializers {
937933

938934
class AuthorizationTypeSerializer extends CustomSerializer[AuthorizationType](formats => ({
939935
case json =>
940-
implicit val fmts = formats
936+
implicit val fmts: Formats = formats
941937
json \ "type" match {
942938
case JString(x) if x.equalsIgnoreCase("oauth2") => {
943939
OAuth((json \ "scopes").extractOrElse(List()),
@@ -979,7 +975,7 @@ trait Serializers {
979975
}, {
980976
case x: Authorization =>
981977
implicit val fmts = formats
982-
Extraction.decompose(x.scopes.filter(_.scope != ""))
978+
Extraction.decompose(x.scopes)
983979
}
984980
))
985981

modules/swagger-core/src/test/scala/converter/ATMTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import scala.collection.mutable.LinkedHashMap
1212
import org.junit.runner.RunWith
1313
import org.scalatest.junit.JUnitRunner
1414
import org.scalatest.FlatSpec
15-
import org.scalatest.matchers.ShouldMatchers
15+
import org.scalatest.Matchers
1616
import javax.xml.bind.annotation._
1717
import converter.models.ATM
1818

1919
@RunWith(classOf[JUnitRunner])
20-
class ATMTest extends FlatSpec with ShouldMatchers {
20+
class ATMTest extends FlatSpec with Matchers {
2121
it should "read a model with enums" in {
2222
val a = ModelConverters.readAll(classOf[ATM])
2323
JsonSerializer.asJson(a) should be ("""[{"id":"ATM","properties":{"currency":{"$ref":"Currency","enum":["USA","CANADA"]}}}]""")

modules/swagger-core/src/test/scala/converter/CaseClassConverterTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import java.util.Date
99
import org.junit.runner.RunWith
1010
import org.scalatest.junit.JUnitRunner
1111
import org.scalatest.FlatSpec
12-
import org.scalatest.matchers.ShouldMatchers
12+
import org.scalatest.Matchers
1313

1414
@RunWith(classOf[JUnitRunner])
15-
class CaseClassConverterTest extends FlatSpec with ShouldMatchers {
15+
class CaseClassConverterTest extends FlatSpec with Matchers {
1616
it should "read a simple case class" in {
1717
val model = ModelConverters.read(classOf[SimpleCaseClass]).getOrElse(fail("no model found"))
1818
model.qualifiedType should be ("converter.SimpleCaseClass")

modules/swagger-core/src/test/scala/converter/CovariantGetterTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import com.wordnik.swagger.converter._
88
import org.junit.runner.RunWith
99
import org.scalatest.junit.JUnitRunner
1010
import org.scalatest.FlatSpec
11-
import org.scalatest.matchers.ShouldMatchers
11+
import org.scalatest.Matchers
1212
import converter.models.JCovariantGetter
1313

1414
@RunWith(classOf[JUnitRunner])
15-
class CovariantGetterTest extends FlatSpec with ShouldMatchers {
15+
class CovariantGetterTest extends FlatSpec with Matchers {
1616
implicit val formats = SwaggerSerializers.formats
1717

1818
it should "read a getter with covariant return type" in {

modules/swagger-core/src/test/scala/converter/CustomConverterTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ import com.wordnik.swagger.model._
1313
import org.joda.time.DateTime
1414

1515
import scala.collection.mutable.LinkedHashMap
16-
import scala.annotation.target.field
16+
import scala.annotation.meta.field
1717
import scala.beans.BeanProperty
1818

1919
import org.junit.runner.RunWith
2020
import org.scalatest.junit.JUnitRunner
2121
import org.scalatest.FlatSpec
22-
import org.scalatest.matchers.ShouldMatchers
22+
import org.scalatest.Matchers
2323

2424
@RunWith(classOf[JUnitRunner])
25-
class CustomConverterTest extends FlatSpec with ShouldMatchers {
25+
class CustomConverterTest extends FlatSpec with Matchers {
2626
it should "ignore properties with type Bar" in {
2727
// add the custom converter
2828
val customConverter = new CustomConverter

modules/swagger-core/src/test/scala/converter/EnumConversionTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import java.util.Date
1111
import org.junit.runner.RunWith
1212
import org.scalatest.junit.JUnitRunner
1313
import org.scalatest.FlatSpec
14-
import org.scalatest.matchers.ShouldMatchers
14+
import org.scalatest.Matchers
1515

1616
@RunWith(classOf[JUnitRunner])
17-
class EnumConversionTest extends FlatSpec with ShouldMatchers {
17+
class EnumConversionTest extends FlatSpec with Matchers {
1818
it should "read a model with an enum property" in {
1919
val model = ModelConverters.read(classOf[ModelWithEnumProperty]).getOrElse(fail("no model found"))
2020
model.id should be ("ModelWithEnumProperty")

modules/swagger-core/src/test/scala/converter/FormatTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import org.json4s.jackson.Serialization.write
99
import org.junit.runner.RunWith
1010
import org.scalatest.junit.JUnitRunner
1111
import org.scalatest.FlatSpec
12-
import org.scalatest.matchers.ShouldMatchers
12+
import org.scalatest.Matchers
1313

1414
import java.util.Date
1515

16-
import scala.annotation.target.field
16+
import scala.annotation.meta.field
1717

1818
@RunWith(classOf[JUnitRunner])
19-
class FormatTest extends FlatSpec with ShouldMatchers {
19+
class FormatTest extends FlatSpec with Matchers {
2020
implicit val formats = SwaggerSerializers.formats
2121

2222
it should "format a date" in {

modules/swagger-core/src/test/scala/converter/HiddenFieldTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import scala.beans.BeanProperty
1414
import org.junit.runner.RunWith
1515
import org.scalatest.junit.JUnitRunner
1616
import org.scalatest.FlatSpec
17-
import org.scalatest.matchers.ShouldMatchers
17+
import org.scalatest.Matchers
1818

1919
@RunWith(classOf[JUnitRunner])
20-
class HiddenFieldTest extends FlatSpec with ShouldMatchers {
20+
class HiddenFieldTest extends FlatSpec with Matchers {
2121
it should "ignore a hidden field" in {
2222
val model = ModelConverters.read(classOf[ModelWithHiddenFields]).getOrElse(fail("no model found"))
2323
model.id should be ("ModelWithHiddenFields")

0 commit comments

Comments
 (0)