Skip to content

Commit 4849ebf

Browse files
committed
t push origin masterMerge branch 'develop_scala-2.10'
2 parents 9fc507c + 7200fcb commit 4849ebf

File tree

53 files changed

+15172
-7382
lines changed

Some content is hidden

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

53 files changed

+15172
-7382
lines changed

modules/swagger-annotations/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<parent>
44
<groupId>com.wordnik</groupId>
55
<artifactId>swagger-project_2.10</artifactId>
6-
<version>1.3.10</version>
6+
<version>1.3.11-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<groupId>com.wordnik</groupId>
1111
<artifactId>swagger-annotations</artifactId>
12-
<version>1.3.10</version>
12+
<version>1.3.11-SNAPSHOT</version>
1313
<packaging>bundle</packaging>
1414
<name>swagger-annotations</name>
1515

modules/swagger-core/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<parent>
33
<groupId>com.wordnik</groupId>
44
<artifactId>swagger-project_2.10</artifactId>
5-
<version>1.3.10</version>
5+
<version>1.3.11-SNAPSHOT</version>
66
<relativePath>../..</relativePath>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<groupId>com.wordnik</groupId>
1010
<artifactId>swagger-core_2.10</artifactId>
1111
<packaging>jar</packaging>
1212
<name>swagger-core</name>
13-
<version>1.3.10</version>
13+
<version>1.3.11-SNAPSHOT</version>
1414
<build>
1515
<sourceDirectory>src/main/java</sourceDirectory>
1616
<defaultGoal>install</defaultGoal>
@@ -103,13 +103,13 @@
103103
<groupId>ch.qos.logback</groupId>
104104
<artifactId>logback-classic</artifactId>
105105
<version>${logback-version}</version>
106-
<scope>test</scope>
106+
<scope>provided</scope>
107107
</dependency>
108108
<dependency>
109109
<groupId>ch.qos.logback</groupId>
110110
<artifactId>logback-core</artifactId>
111111
<version>${logback-version}</version>
112-
<scope>test</scope>
112+
<scope>provided</scope>
113113
</dependency>
114114
</dependencies>
115115
</project>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
206206
else simpleTypeRef
207207
}
208208
simpleName = containerType
209-
if(isComplex(simpleTypeRef)) {
210-
Some(ModelRef(null, Some(simpleTypeRef), Some(basePart)))
209+
if(isComplex(typeRef)) {
210+
Some(ModelRef(null, Some(typeRef), Some(basePart)))
211211
}
212-
else Some(ModelRef(simpleTypeRef, None, Some(basePart)))
212+
else Some(ModelRef(typeRef, None, Some(basePart)))
213213
}
214214
case _ => None
215215
}

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ object SwaggerSerializers extends Serializers {
175175
}
176176
}
177177

178+
def toJsonSchemaTypeFromRef(ref: ModelRef): JObject = {
179+
// see if primitive
180+
if(SwaggerSpec.baseTypes.contains(ref.`type`)) {
181+
toJsonSchema("type", ref.`type`)
182+
} else {
183+
("type" -> ref.`type`)
184+
}
185+
}
186+
178187
class JsonSchemaOperationSerializer extends CustomSerializer[Operation](formats => ({
179188
case json =>
180189
implicit val fmts: Formats = formats
@@ -337,23 +346,22 @@ object SwaggerSerializers extends Serializers {
337346
))
338347

339348
class JsonSchemaModelRefSerializer extends CustomSerializer[ModelRef](formats => ({
340-
case json =>
349+
case json => {
341350
implicit val fmts: Formats = formats
342351
ModelRef(
343352
(json \ "type").extractOrElse(null: String),
344353
(json \ "$ref").extractOpt[String]
345354
)
346-
}, {
347-
case x: ModelRef =>
355+
}}, {
356+
case x: ModelRef => {
348357
implicit val fmts = formats
349-
("type" -> {
350-
x.`type` match {
351-
case e:String => Some(e)
352-
case _ => None
353-
}
354-
}) ~
355-
("$ref" -> x.ref)
358+
val output: JObject = x.`type` match {
359+
case e: String => toJsonSchemaTypeFromRef(x)
360+
case _ => ("type" -> None)
361+
}
362+
output ~ ("$ref" -> x.ref)
356363
}
364+
}
357365
))
358366

359367
class JsonSchemaParameterSerializer extends CustomSerializer[Parameter](formats => ({
@@ -383,8 +391,8 @@ object SwaggerSerializers extends Serializers {
383391
""
384392
}),
385393
(json \ "allowableValues").extract[AllowableValues],
386-
(json \ "type").extractOrElse({
387-
!!(json, OPERATION_PARAM, "type", "missing required field", ERROR)
394+
(json \ "paramType").extractOrElse({
395+
!!(json, OPERATION_PARAM, "paramType", "missing required field", ERROR)
388396
""
389397
}),
390398
(json \ "paramAccess").extractOpt[String]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package converter
2+
3+
import com.wordnik.swagger.core.SwaggerSpec
4+
import com.wordnik.swagger.core.util.ModelUtil
5+
import converter.models._
6+
import com.wordnik.swagger.model._
7+
import com.wordnik.swagger.converter._
8+
import org.json4s._
9+
import org.json4s.jackson.Serialization.write
10+
import org.json4s.jackson._
11+
12+
import org.junit.runner.RunWith
13+
import org.scalatest.junit.JUnitRunner
14+
import org.scalatest.FlatSpec
15+
import org.scalatest.Matchers
16+
17+
@RunWith(classOf[JUnitRunner])
18+
class BoxedTypesTest extends FlatSpec with Matchers {
19+
implicit val formats = SwaggerSerializers.formats
20+
21+
"ModelConverters" should "format a BoxedType" in {
22+
val model = ModelConverters.read(classOf[BoxedTypesIssue31]).getOrElse(fail("no model found"))
23+
model.properties.size should be(5)
24+
write(model) should be( """{"id":"BoxedTypesIssue31","description":"Options of boxed types produces an Object ref instead of correct type","properties":{"stringSeq":{"type":"array","items":{"type":"string"}},"stringOpt":{"type":"string"},"intSeq":{"type":"array","description":"Integers in a Sequence Box","items":{"$ref":"Object"}},"intOpt":{"$ref":"Object","description":"Integer in an Option Box"},"justInt":{"type":"integer","format":"int32"}}}""")
25+
}
26+
27+
it should "format a BoxedTypeWithDataType provided in the annotation for the boxed object types" in {
28+
val model = ModelConverters.read(classOf[BoxedTypesIssue31WithDataType]).getOrElse(fail("no model found"))
29+
model.properties.size should be(5)
30+
write(model) should be( """{"id":"BoxedTypesIssue31WithDataType","description":"Options of boxed types produces an Object ref instead of correct type, but can be overcome with dataType","properties":{"stringSeq":{"type":"array","items":{"type":"string"}},"stringOpt":{"type":"string"},"intSeq":{"type":"array","description":"Integers in a Sequence Box","items":{"type":"integer","format":"int32"}},"intOpt":{"type":"integer","format":"int32","description":"Integer in an Option Box"},"justInt":{"type":"integer","format":"int32"}}}""")
31+
}
32+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class FormatTest extends FlatSpec with Matchers {
3030
val model = ModelConverters.read(classOf[SetModel]).getOrElse(fail("no model found"))
3131
model.properties.size should be (1)
3232

33-
write(model) should be ("""{"id":"SetModel","properties":{"longs":{"type":"array","uniqueItems":true,"items":{"type":"long"}}}}""")
33+
// gbolt; 11/9/2014 - Unclear why the type is expected to be "long"? As far as I understand, long is not one of the
34+
// 7 primitive types defined in JSON Schema. It should be integer with format of int64.
35+
// write(model) should be ("""{"id":"SetModel","properties":{"longs":{"type":"array","uniqueItems":true,"items":{"type":"long"}}}}""")
36+
write(model) should be ("""{"id":"SetModel","properties":{"longs":{"type":"array","uniqueItems":true,"items":{"type":"integer","format":"int64"}}}}""")
37+
3438
}
3539
}
3640

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package converter
2+
3+
import org.junit.runner.RunWith
4+
import org.scalatest.junit.JUnitRunner
5+
import org.scalatest.FlatSpec
6+
import org.scalatest.Matchers
7+
8+
@RunWith(classOf[JUnitRunner])
9+
class ModelUtilTest extends FlatSpec with Matchers {
10+
import com.wordnik.swagger.core.util.ModelUtil._
11+
12+
"ModelUtil cleanDataType" should "convert a fully-qualified primitive type to a SwaggerTypes primitive" in {
13+
val primitiveName = "java.lang.Integer"
14+
val cleanName = cleanDataType(primitiveName)
15+
cleanName should equal ("int")
16+
}
17+
18+
it should "convert a primitive type simple name to a SwaggerTypes primitive" in {
19+
val primitiveName = "Integer"
20+
val cleanName = cleanDataType(primitiveName)
21+
cleanName should equal ("int")
22+
}
23+
24+
it should "convert the inner class of a container to a SwaggerTypes primitive" in {
25+
val origName = "List[java.lang.Integer]"
26+
val cleanName = cleanDataType(origName)
27+
cleanName should equal ("List[int]")
28+
}
29+
30+
it should "return a fully-qualified class name unchanged" in {
31+
val fqcn = "com.wordnik.swagger.core.ModelUtil"
32+
val cleanName = cleanDataType(fqcn)
33+
cleanName should equal (fqcn)
34+
}
35+
36+
it should "return a container with a fully-qualified inner class name unchanged" in {
37+
val fqcn = "List[com.wordnik.swagger.core.ModelUtil]"
38+
val cleanName = cleanDataType(fqcn)
39+
cleanName should equal (fqcn)
40+
}
41+
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package converter
22

3+
import com.wordnik.swagger.core.SwaggerSpec
34
import com.wordnik.swagger.model._
45

56
import org.json4s._
@@ -32,10 +33,29 @@ class SwaggerSerializersTest extends FlatSpec with Matchers {
3233
}""")*/
3334
}
3435

36+
it should "serialize an api listing with authorizations" in {
37+
val auth = new Authorization("oauth2", Array(AuthorizationScope("scope1", "description 1"),
38+
AuthorizationScope("scope2", "description 2")))
39+
val emptyList = List()
40+
val apiListing = ApiListing(
41+
"1.0",
42+
SwaggerSpec.version,
43+
"",
44+
"/relative-path-to-endpoint",
45+
emptyList,
46+
emptyList,
47+
emptyList,
48+
List(auth),
49+
emptyList,
50+
None,
51+
None,
52+
1)
53+
println(pretty(render(parse(write(apiListing)))))
54+
}
55+
3556
it should "deserialize an ApiDeclaration" in {
3657
parse(apiDeclaration).extract[ApiListing] should not be (null)
3758
}
3859

39-
4060
val apiDeclaration = """{"apiVersion":"1.0.0","swaggerVersion":"1.2","basePath":"http://localhost:9095/resteasy","resourcePath":"/library","apis":[{"path":"/library/books/badger","operations":[{"method":"GET","summary":"gets books with Badger","notes":"gets books with @Badgerfish","type":"listing","nickname":"getBooksBadger","produces":["application/json"],"authorizations":{},"parameters":[],"responseMessages":[{"code":400,"message":"Not sure"},{"code":404,"message":"bad"}]}]},{"path":"/library/books/mapped","operations":[{"method":"GET","summary":"gets books with mapped","notes":"gets books with @Mapped","type":"listing","nickname":"getBooksMapped","produces":["application/json"],"authorizations":{},"parameters":[],"responseMessages":[{"code":400,"message":"Not sure"},{"code":404,"message":"bad"}]}]}],"models":{"book":{"id":"book","properties":{"author":{"type":"string"},"title":{"type":"string"},"iSBN":{"type":"string"}}},"listing":{"id":"listing","properties":{"books":{"type":"array","items":{"$ref":"book"}}}}}}"""
4161
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package converter.models
2+
3+
import com.wordnik.swagger.annotations.{ ApiModel, ApiModelProperty }
4+
5+
import scala.annotation.meta.field
6+
7+
// Issue #31: https://github.com/gettyimages/spray-swagger/issues/31
8+
// It would be nice if the Seq[Int] and Option[Int] could create the proper spec, but due
9+
// to erasure the parameterized types are only identified as Object
10+
@ApiModel(description = "Options of boxed types produces an Object ref instead of correct type")
11+
case class BoxedTypesIssue31(stringSeq: Seq[String], stringOpt: Option[String],
12+
@(ApiModelProperty @field)(value = "Integers in a Sequence Box") intSeq: Seq[Int],
13+
@(ApiModelProperty @field)(value = "Integer in an Option Box") intOpt: Option[Int],
14+
justInt: Int)
15+
16+
// Get around the erasure by providing the dataType explicitly using the dataType common names.
17+
@ApiModel(description = "Options of boxed types produces an Object ref instead of correct type, but can be overcome with dataType")
18+
case class BoxedTypesIssue31WithDataType(stringSeq: Seq[String], stringOpt: Option[String],
19+
@(ApiModelProperty @field)(value = "Integers in a Sequence Box", dataType = "List[int]") intSeq: Seq[Int],
20+
@(ApiModelProperty @field)(value = "Integer in an Option Box", dataType = "int") intOpt: Option[Int],
21+
justInt: Int)

modules/swagger-jaxrs-utils/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<parent>
44
<groupId>com.wordnik</groupId>
55
<artifactId>swagger-project_2.10</artifactId>
6-
<version>1.3.10</version>
6+
<version>1.3.11-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<groupId>com.wordnik</groupId>
1111
<artifactId>swagger-jaxrs-utils_2.10</artifactId>
1212
<packaging>jar</packaging>
13-
<version>1.3.10</version>
13+
<version>1.3.11-SNAPSHOT</version>
1414
<name>swagger-jaxrs-utils</name>
1515
<build>
1616
<defaultGoal>install</defaultGoal>

0 commit comments

Comments
 (0)