From aa1b4fc0fb5771522bfc86234594c28476c0b392 Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Thu, 3 Jul 2014 11:19:53 -0400 Subject: [PATCH 1/4] Wrote failing test for Codegen --- src/test/scala/CodegenTest.scala | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/test/scala/CodegenTest.scala diff --git a/src/test/scala/CodegenTest.scala b/src/test/scala/CodegenTest.scala new file mode 100644 index 00000000000..c81dacf22b0 --- /dev/null +++ b/src/test/scala/CodegenTest.scala @@ -0,0 +1,56 @@ +/** + * Copyright 2014 Wordnik, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.wordnik.swagger.codegen.Codegen +import com.wordnik.swagger.codegen.BasicJavaGenerator +import com.wordnik.swagger.codegen.model._ + +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner +import org.scalatest.FlatSpec +import org.scalatest.matchers.ShouldMatchers + +import scala.reflect.BeanProperty + +@RunWith(classOf[JUnitRunner]) +class CodegenTest extends FlatSpec with ShouldMatchers { + + val subject = new Codegen(new BasicJavaGenerator) + + val testOp = new Operation("GET", + "List All Contacts", + "", + "Array[ContactData]", + "listContacts", + 0, + List.empty, + List.empty, + List.empty, + List.empty, + List.empty, + List.empty, + None) + + behavior of "Codegen" + /* + * A response of type "void" will turn into a declaration of None + * for the template generator + */ + it should "recognize the returnContainer as a List" in { + val map = subject.apiToMap("/contacts", testOp) + map("returnContainer") should be (Some("List")) + } +} From 550fade9e00620260ce236b68ab931868ac9d3e5 Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Thu, 3 Jul 2014 11:24:05 -0400 Subject: [PATCH 2/4] Codegen.apiToMap should use config.processResponseClass when setting the returnContainer property. Test passes now --- src/main/scala/com/wordnik/swagger/codegen/Codegen.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala b/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala index ec0d0116b8a..988a2b7c6cc 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala @@ -436,7 +436,7 @@ class Codegen(config: CodegenConfig) { val ComplexTypeMatcher(basePart) = operation.responseClass properties += "returnType" -> config.processResponseDeclaration(operation.responseClass.replaceAll(basePart, config.processResponseClass(basePart).get)) - properties += "returnContainer" -> (operation.responseClass.substring(0, n)) + properties += "returnContainer" -> config.processResponseClass(operation.responseClass.substring(0, n)) properties += "returnBaseType" -> config.processResponseClass(basePart) properties += "returnTypeIsPrimitive" -> { (config.languageSpecificPrimitives.contains(basePart) || primitives.contains(basePart)) match { From 9834059786df77f16e82e2f945764ec272db168b Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Thu, 3 Jul 2014 11:32:37 -0400 Subject: [PATCH 3/4] Fixed BasicScalaGeneratorTest to expect Some(List) --- src/test/scala/BasicScalaGeneratorTest.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/scala/BasicScalaGeneratorTest.scala b/src/test/scala/BasicScalaGeneratorTest.scala index d2147f78cb4..9bcea0af9d0 100644 --- a/src/test/scala/BasicScalaGeneratorTest.scala +++ b/src/test/scala/BasicScalaGeneratorTest.scala @@ -211,7 +211,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers { m("returnType") should be (Some("List[Pet]")) m("returnTypeIsPrimitive") should be (None) m("pathParams").asInstanceOf[List[_]].size should be (0) - m("returnContainer") should be ("List") + m("returnContainer") should be (Some("List")) m("requiredParamCount") should be ("1") val queryParams = m("queryParams").asInstanceOf[List[_]] @@ -248,7 +248,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers { m("returnType") should be (Some("List[Pet]")) m("returnTypeIsPrimitive") should be (None) m("pathParams").asInstanceOf[List[_]].size should be (0) - m("returnContainer") should be ("List") + m("returnContainer") should be (Some("List")) m("requiredParamCount") should be ("1") val queryParams = m("queryParams").asInstanceOf[List[_]] From e2a20447dfab2cdb5e3424643bf363834f25a1b4 Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Thu, 10 Jul 2014 10:02:18 -0400 Subject: [PATCH 4/4] Fixed comment in test --- src/test/scala/CodegenTest.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/scala/CodegenTest.scala b/src/test/scala/CodegenTest.scala index c81dacf22b0..26156bb8eb5 100644 --- a/src/test/scala/CodegenTest.scala +++ b/src/test/scala/CodegenTest.scala @@ -46,8 +46,7 @@ class CodegenTest extends FlatSpec with ShouldMatchers { behavior of "Codegen" /* - * A response of type "void" will turn into a declaration of None - * for the template generator + * A return specified as "Array" should map to "List" */ it should "recognize the returnContainer as a List" in { val map = subject.apiToMap("/contacts", testOp)