Skip to content

Commit 3abc42e

Browse files
committed
Merge pull request #368 from amandaducrou/master
Adding first and hasRequiredParams parameters to Codegen
2 parents 2d193a0 + 2d81c71 commit 3abc42e

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/main/scala/com/wordnik/swagger/codegen/Codegen.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ class Codegen(config: CodegenConfig) {
202202

203203
queryParams.size match {
204204
case 0 =>
205-
case _ => queryParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
205+
case _ => {
206+
queryParams.head.asInstanceOf[HashMap[String, String]] += "first" -> "true"
207+
queryParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
208+
}
206209
}
207210

208211
pathParams.size match {
@@ -390,7 +393,10 @@ class Codegen(config: CodegenConfig) {
390393
"description" -> propertyDocSchema.description,
391394
"notes" -> propertyDocSchema.description,
392395
"allowableValues" -> rawAllowableValuesToString(propertyDocSchema.allowableValues),
393-
(if(propertyDocSchema.required) "required" else "isNotRequired") -> "true",
396+
(if(propertyDocSchema.required) {
397+
data += "hasRequiredParams" -> "true"
398+
"required"
399+
} else "isNotRequired") -> "true",
394400
"getter" -> config.toGetter(prop._1, config.toDeclaration(propertyDocSchema)._1),
395401
"setter" -> config.toSetter(prop._1, config.toDeclaration(propertyDocSchema)._1),
396402
"isList" -> isList,

src/test/scala/CodegenTest.scala

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.scalatest.FlatSpec
2424
import org.scalatest.Matchers
2525

2626
import scala.beans.BeanProperty
27+
import scala.collection.mutable.{ HashMap, LinkedHashMap }
2728

2829
@RunWith(classOf[JUnitRunner])
2930
class CodegenTest extends FlatSpec with Matchers {
@@ -40,8 +41,18 @@ class CodegenTest extends FlatSpec with Matchers {
4041
List.empty,
4142
List.empty,
4243
List.empty,
44+
//query param
45+
List(new Parameter("Name", Some("name"), Some("null"), false, false, "String", AnyAllowableValues, "query", None)),
4346
List.empty,
44-
List.empty,
47+
None)
48+
49+
val testModel = new Model("Contact",
50+
"Contact",
51+
"Contact",
52+
//required field
53+
LinkedHashMap("Name" -> new ModelProperty("String", "String", 0, true, None, AnyAllowableValues, None)),
54+
None,
55+
None,
4556
None)
4657

4758
behavior of "Codegen"
@@ -52,4 +63,21 @@ class CodegenTest extends FlatSpec with Matchers {
5263
val map = subject.apiToMap("/contacts", testOp)
5364
map("returnContainer") should be (Some("List"))
5465
}
66+
67+
/*
68+
* Field first on the query param should be true
69+
*/
70+
it should "have a first field on first query param and should be true" in {
71+
val map = subject.apiToMap("/contacts", testOp)
72+
map("queryParams").asInstanceOf[List[HashMap[String, String]]].head("first") should be ("true")
73+
}
74+
75+
/*
76+
* Field hasRequiredParams should be true
77+
*/
78+
it should "have a hasRequiredParams field and should be true" in {
79+
val map = subject.modelToMap("Contact", testModel)
80+
map("hasRequiredParams") should be ("true")
81+
}
5582
}
83+

0 commit comments

Comments
 (0)