Skip to content

Commit 1ca5c5b

Browse files
committed
updated tests to 1.3.10 core
1 parent 316a4de commit 1ca5c5b

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

modules/swagger-play2/app/play/modules/swagger/PlayApiReader.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,14 @@ class PlayApiReader(val routes: Option[Routes]) extends JaxrsApiReader {
252252
case e: String if e.trim != "" => e.split(",").map(_.trim).toList
253253
case _ => List()
254254
}
255-
val authorizations:List[com.wordnik.swagger.model.Authorization] = Option(apiOperation.authorizations) match {
255+
val authorizations: List[com.wordnik.swagger.model.Authorization] = Option(apiOperation.authorizations) match {
256256
case Some(e) => (for(a <- e) yield {
257257
val scopes = (for(s <- a.scopes) yield com.wordnik.swagger.model.AuthorizationScope(s.scope, s.description)).toArray
258-
new com.wordnik.swagger.model.Authorization(a.value, scopes)
259-
}).toList
258+
if(a.value != null && !"".equals(a.value))
259+
Some(new com.wordnik.swagger.model.Authorization(a.value, scopes))
260+
else
261+
None
262+
}).flatten.toList
260263
case _ => List()
261264
}
262265
val responseClass = apiOperation.responseContainer match {

modules/swagger-play2/test/PlayApiReaderSpec.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import org.mockito.Mockito._
1515

1616

1717
class PlayApiReaderSpec extends Specification with Mockito {
18-
1918
"PlayApiReader.SwaggerUtils" should {
2019
"convert a simple play route comment" in {
2120
val path = "/pet.json/$id<[^/]+>/test/$nothing<[^/]+>"
@@ -84,7 +83,6 @@ class PlayApiReaderSpec extends Specification with Mockito {
8483

8584

8685
"with Object as Controller" should {
87-
8886
"get full name for method" in {
8987
reader.getFullMethodName(dogControllerClass, dogMethod("add1").get) must beEqualTo("test.testdata.DogController$.add1")
9088
}
@@ -119,7 +117,6 @@ class PlayApiReaderSpec extends Specification with Mockito {
119117
"get request path for a method that has path params" in {
120118
reader.getPath(catControllerClass, catControllerClass.getMethod("get1", classOf[Long])).getOrElse("") must beEqualTo("/api/cat/:id")
121119
}
122-
123120
}
124121

125122

@@ -157,7 +154,6 @@ class PlayApiReaderSpec extends Specification with Mockito {
157154
}
158155

159156
"readMethod with Object as controller" should {
160-
161157
"create Operation for annotated method" in {
162158
val maybeOperation: Option[Operation] = reader.readMethod(dogMethod("list").get)
163159
maybeOperation.nonEmpty must beTrue
@@ -188,20 +184,22 @@ class PlayApiReaderSpec extends Specification with Mockito {
188184

189185
"adds empty 'authorizations' when not defined" in {
190186
val operation: Operation = reader.readMethod(dogMethod("add1").get).get
187+
println(operation.authorizations)
191188
operation.authorizations must beEqualTo(List.empty)
192189
}
193190

194191
"adds 'authorizations' when defined" in {
195192
val operation: Operation = reader.readMethod(dogMethod("add2").get).get
196193
operation.authorizations.length must beEqualTo(1)
197-
operation.authorizations.head must beEqualTo("vet")
194+
operation.authorizations.head.`type` must beEqualTo("oauth2")
198195
}
199196

200-
"adds mulitple 'authorizations' when defined" in {
197+
"adds multiple 'authorizations' when defined" in {
201198
val operation: Operation = reader.readMethod(dogMethod("add3").get).get
202199
operation.authorizations.length must beEqualTo(2)
203-
operation.authorizations.contains("vet") must beTrue
204-
operation.authorizations.contains("owner") must beTrue
200+
val authNames = (for(auth <- operation.authorizations) yield auth.`type`).toSet
201+
authNames.contains("oauth2") must beTrue
202+
authNames.contains("api_key") must beTrue
205203
}
206204

207205
"adds empty 'produces' when not defined" in {

modules/swagger-play2/test/testdata/CatController.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class CatController extends Controller {
1717

1818
@ApiOperation(value = "addCat1",
1919
httpMethod = "PUT",
20-
authorizations = "",
2120
consumes = "",
2221
protocols = "")
2322
@ApiImplicitParams(Array(
@@ -60,13 +59,9 @@ class CatController extends Controller {
6059
request => Ok("test case")
6160
}
6261

63-
6462
def no_route = Action {
6563
request => Ok("test case")
6664
}
67-
68-
69-
7065
}
7166

7267
case class Cat(id: Long, name: String)

modules/swagger-play2/test/testdata/DogController.scala

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ import scala.concurrent.Future
2222
produces = "application/json, application/xml",
2323
consumes = "application/json, application/xml",
2424
protocols = "http, https",
25-
authorizations = "vet, owner"
25+
authorizations = Array(new Authorization(value="oauth2",
26+
scopes = Array(
27+
new AuthorizationScope(scope = "vet", description = "vet access"),
28+
new AuthorizationScope(scope = "owner", description = "owner access")
29+
))
30+
)
2631
)
2732
object DogController extends Controller {
28-
2933
@ApiOperation(value = "addDog1",
30-
httpMethod = "PUT",
31-
authorizations = "",
32-
consumes = "",
33-
protocols = "")
34+
httpMethod = "PUT")
3435
@ApiImplicitParams(Array(
3536
new ApiImplicitParam(name = "dog", value = "Dog object to add", required = true, dataType = "Dog", paramType = "body")))
3637
def add1 = Action {
@@ -41,7 +42,12 @@ object DogController extends Controller {
4142
notes = "Adds a dogs better",
4243
httpMethod = "PUT",
4344
nickname = "addDog2_nickname",
44-
authorizations = "vet",
45+
authorizations = Array(new Authorization(value="oauth2",
46+
scopes = Array(
47+
new AuthorizationScope(scope = "vet", description = "vet access"),
48+
new AuthorizationScope(scope = "owner", description = "owner access")
49+
))
50+
),
4551
consumes = " application/json ",
4652
protocols = "http",
4753
position = 2)
@@ -55,7 +61,13 @@ object DogController extends Controller {
5561
@ApiOperation(value = "Add a new Dog",
5662
notes = "Adds a dogs nicely",
5763
httpMethod = "PUT",
58-
authorizations = "vet, owner",
64+
authorizations = Array(new Authorization(value="oauth2",
65+
scopes = Array(
66+
new AuthorizationScope(scope = "vet", description = "vet access"),
67+
new AuthorizationScope(scope = "owner", description = "owner access")
68+
)),
69+
new Authorization(value="api_key")
70+
),
5971
consumes = " application/json, text/yaml ",
6072
protocols = "http, https"
6173
)
@@ -177,7 +189,6 @@ object DogController extends Controller {
177189
def undefined_method() = Action {
178190
request => Ok("test case")
179191
}
180-
181192
}
182193

183194
case class Dog(id: Long, name: String)

0 commit comments

Comments
 (0)