Skip to content

Commit 8708303

Browse files
committed
Merge pull request #215 from JDiPierro/fix_java_generator_lists
Use config.processResponseClass to determine type of returnContainer
2 parents d9de57d + e2a2044 commit 8708303

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class Codegen(config: CodegenConfig) {
309309
val ComplexTypeMatcher(basePart) = operation.responseClass
310310

311311
properties += "returnType" -> config.processResponseDeclaration(operation.responseClass.replaceAll(basePart, config.processResponseClass(basePart).get))
312-
properties += "returnContainer" -> (operation.responseClass.substring(0, n))
312+
properties += "returnContainer" -> config.processResponseClass(operation.responseClass.substring(0, n))
313313
properties += "returnBaseType" -> config.processResponseClass(basePart)
314314
properties += "returnTypeIsPrimitive" -> {
315315
(config.languageSpecificPrimitives.contains(basePart) || primitives.contains(basePart)) match {

src/test/scala/BasicScalaGeneratorTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
211211
m("returnType") should be (Some("List[Pet]"))
212212
m("returnTypeIsPrimitive") should be (None)
213213
m("pathParams").asInstanceOf[List[_]].size should be (0)
214-
m("returnContainer") should be ("List")
214+
m("returnContainer") should be (Some("List"))
215215
m("requiredParamCount") should be ("1")
216216

217217
val queryParams = m("queryParams").asInstanceOf[List[_]]
@@ -248,7 +248,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
248248
m("returnType") should be (Some("List[Pet]"))
249249
m("returnTypeIsPrimitive") should be (None)
250250
m("pathParams").asInstanceOf[List[_]].size should be (0)
251-
m("returnContainer") should be ("List")
251+
m("returnContainer") should be (Some("List"))
252252
m("requiredParamCount") should be ("1")
253253

254254
val queryParams = m("queryParams").asInstanceOf[List[_]]

src/test/scala/CodegenTest.scala

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright 2014 Wordnik, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import com.wordnik.swagger.codegen.Codegen
18+
import com.wordnik.swagger.codegen.BasicJavaGenerator
19+
import com.wordnik.swagger.codegen.model._
20+
21+
import org.junit.runner.RunWith
22+
import org.scalatest.junit.JUnitRunner
23+
import org.scalatest.FlatSpec
24+
import org.scalatest.matchers.ShouldMatchers
25+
26+
import scala.reflect.BeanProperty
27+
28+
@RunWith(classOf[JUnitRunner])
29+
class CodegenTest extends FlatSpec with ShouldMatchers {
30+
31+
val subject = new Codegen(new BasicJavaGenerator)
32+
33+
val testOp = new Operation("GET",
34+
"List All Contacts",
35+
"",
36+
"Array[ContactData]",
37+
"listContacts",
38+
0,
39+
List.empty,
40+
List.empty,
41+
List.empty,
42+
List.empty,
43+
List.empty,
44+
List.empty,
45+
None)
46+
47+
behavior of "Codegen"
48+
/*
49+
* A return specified as "Array" should map to "List"
50+
*/
51+
it should "recognize the returnContainer as a List" in {
52+
val map = subject.apiToMap("/contacts", testOp)
53+
map("returnContainer") should be (Some("List"))
54+
}
55+
}

0 commit comments

Comments
 (0)