From 2d81c71b523be9300708c6496346effd7312e10d Mon Sep 17 00:00:00 2001 From: Amanda Ducrou Date: Fri, 9 Jan 2015 10:59:21 +1000 Subject: [PATCH] Adding first and hasRequiredParams parameters to Codegen --- .../com/wordnik/swagger/codegen/Codegen.scala | 10 +++++-- src/test/scala/CodegenTest.scala | 30 ++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala b/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala index 82581915c27..1c45e382c2f 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala @@ -202,7 +202,10 @@ class Codegen(config: CodegenConfig) { queryParams.size match { case 0 => - case _ => queryParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore" + case _ => { + queryParams.head.asInstanceOf[HashMap[String, String]] += "first" -> "true" + queryParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore" + } } pathParams.size match { @@ -390,7 +393,10 @@ class Codegen(config: CodegenConfig) { "description" -> propertyDocSchema.description, "notes" -> propertyDocSchema.description, "allowableValues" -> rawAllowableValuesToString(propertyDocSchema.allowableValues), - (if(propertyDocSchema.required) "required" else "isNotRequired") -> "true", + (if(propertyDocSchema.required) { + data += "hasRequiredParams" -> "true" + "required" + } else "isNotRequired") -> "true", "getter" -> config.toGetter(prop._1, config.toDeclaration(propertyDocSchema)._1), "setter" -> config.toSetter(prop._1, config.toDeclaration(propertyDocSchema)._1), "isList" -> isList, diff --git a/src/test/scala/CodegenTest.scala b/src/test/scala/CodegenTest.scala index 07d025ef6ce..b41ad4caa68 100644 --- a/src/test/scala/CodegenTest.scala +++ b/src/test/scala/CodegenTest.scala @@ -24,6 +24,7 @@ import org.scalatest.FlatSpec import org.scalatest.Matchers import scala.beans.BeanProperty +import scala.collection.mutable.{ HashMap, LinkedHashMap } @RunWith(classOf[JUnitRunner]) class CodegenTest extends FlatSpec with Matchers { @@ -40,8 +41,18 @@ class CodegenTest extends FlatSpec with Matchers { List.empty, List.empty, List.empty, + //query param + List(new Parameter("Name", Some("name"), Some("null"), false, false, "String", AnyAllowableValues, "query", None)), List.empty, - List.empty, + None) + + val testModel = new Model("Contact", + "Contact", + "Contact", + //required field + LinkedHashMap("Name" -> new ModelProperty("String", "String", 0, true, None, AnyAllowableValues, None)), + None, + None, None) behavior of "Codegen" @@ -52,4 +63,21 @@ class CodegenTest extends FlatSpec with Matchers { val map = subject.apiToMap("/contacts", testOp) map("returnContainer") should be (Some("List")) } + + /* + * Field first on the query param should be true + */ + it should "have a first field on first query param and should be true" in { + val map = subject.apiToMap("/contacts", testOp) + map("queryParams").asInstanceOf[List[HashMap[String, String]]].head("first") should be ("true") + } + + /* + * Field hasRequiredParams should be true + */ + it should "have a hasRequiredParams field and should be true" in { + val map = subject.modelToMap("Contact", testModel) + map("hasRequiredParams") should be ("true") + } } +