Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix definition generation of optional arrays #76

Merged
merged 2 commits into from May 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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