forked from loafle/openapi-generator-original
Merge pull request #215 from JDiPierro/fix_java_generator_lists
Use config.processResponseClass to determine type of returnContainer
This commit is contained in:
commit
87083034ee
@ -309,7 +309,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 {
|
||||
|
@ -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[_]]
|
||||
|
55
src/test/scala/CodegenTest.scala
Normal file
55
src/test/scala/CodegenTest.scala
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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 return specified as "Array" should map to "List"
|
||||
*/
|
||||
it should "recognize the returnContainer as a List" in {
|
||||
val map = subject.apiToMap("/contacts", testOp)
|
||||
map("returnContainer") should be (Some("List"))
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user