Skip to content

Commit

Permalink
Merge pull request #76 from gsson/optional-sequence
Browse files Browse the repository at this point in the history
Fix definition generation of optional arrays
  • Loading branch information
kailuowang committed May 9, 2016
2 parents feb744e + 7db17fb commit 0d2720a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Expand Up @@ -50,7 +50,7 @@ object SwaggerParameterMapper {
SwaggerParameter(parameter.name, referenceType = Some(referenceType))

def optionalParam(optionalTpe: String) = {
val param = if (isReference(optionalTpe)) referenceParam(optionalTpe) else mapParam(parameter.copy(typeName = optionalTpe))
val param = if (isReference(optionalTpe)) referenceParam(optionalTpe) else mapParam(parameter.copy(typeName = optionalTpe), modelQualifier = modelQualifier)
param.copy(required = false, default = defaultValueO)
}

Expand Down
Expand Up @@ -3,7 +3,7 @@ package com.iheart.playSwagger
import com.iheart.playSwagger.Domain.{Definition, SwaggerParameter}
import org.specs2.mutable.Specification

case class Foo(barStr: String, barInt: Int, barLong: Option[Long], reffedFoo: ReffedFoo)
case class Foo(barStr: String, barInt: Int, barLong: Option[Long], reffedFoo: ReffedFoo, seqReffedFoo: Seq[ReffedFoo], optionSeqReffedFoo: Option[Seq[ReffedFoo]])
case class ReffedFoo(name: String, refrefFoo: RefReffedFoo)
case class RefReffedFoo(bar: String)

Expand Down Expand Up @@ -44,7 +44,7 @@ class DefinitionGeneratorSpec extends Specification {

val result = DefinitionGenerator("com.iheart.playSwagger").definition[Foo].properties

result.length === 4
result.length === 6

"with correct string property" >> {
result.head === SwaggerParameter(name = "barStr", `type` = Some("string"))
Expand All @@ -62,6 +62,16 @@ class DefinitionGeneratorSpec extends Specification {
result(3) === SwaggerParameter(name = "reffedFoo", referenceType = Some("com.iheart.playSwagger.ReffedFoo"))
}

"with sequence of reference type" >> {
val itemsParam = SwaggerParameter(name = "seqReffedFoo", referenceType = Some("com.iheart.playSwagger.ReffedFoo"))
result(4) === SwaggerParameter(name = "seqReffedFoo", `type` = Some("array"), items = Some(itemsParam))
}

"with optional sequence of reference type" >> {
val itemsParam = SwaggerParameter(name = "optionSeqReffedFoo", referenceType = Some("com.iheart.playSwagger.ReffedFoo"))
result(5) === SwaggerParameter(name = "optionSeqReffedFoo", `type` = Some("array"), items = Some(itemsParam), required = false)
}

}

"read class in Object" >> {
Expand Down

0 comments on commit 0d2720a

Please sign in to comment.