forked from loafle/openapi-generator-original
Make recurseModel method tail-recursive, fix stack overflow error
This commit is contained in:
parent
025502efad
commit
1724c9328e
@ -5,7 +5,7 @@ organization := "com.wordnik"
|
|||||||
|
|
||||||
name := "swagger-codegen"
|
name := "swagger-codegen"
|
||||||
|
|
||||||
version := "2.0.2-SNAPSHOT"
|
version := "2.0.3-SNAPSHOT"
|
||||||
|
|
||||||
scalaVersion := "2.9.2"
|
scalaVersion := "2.9.2"
|
||||||
|
|
||||||
|
@ -3,9 +3,8 @@ package {{package}}
|
|||||||
{{#imports}}import {{import}}
|
{{#imports}}import {{import}}
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
import com.wordnik.swagger.client._
|
import com.wordnik.swagger.client._
|
||||||
import akka.dispatch.{ Future, Await }
|
import scala.concurrent.{ Future, Await }
|
||||||
import akka.util.duration._
|
import scala.concurrent.duration._
|
||||||
import akka.util.Duration
|
|
||||||
import collection.mutable
|
import collection.mutable
|
||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
|
@ -2,6 +2,8 @@ organization := "com.wordnik.samples"
|
|||||||
|
|
||||||
name := "{{projectName}}-client"
|
name := "{{projectName}}-client"
|
||||||
|
|
||||||
|
scalaVersion := "2.10.0"
|
||||||
|
|
||||||
libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.1.4"
|
libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.1.4"
|
||||||
|
|
||||||
libraryDependencies += "joda-time" % "joda-time" % "2.2"
|
libraryDependencies += "joda-time" % "joda-time" % "2.2"
|
||||||
|
@ -23,6 +23,8 @@ import scala.collection.JavaConversions._
|
|||||||
import com.wordnik.swagger.codegen.spec.SwaggerSpec._
|
import com.wordnik.swagger.codegen.spec.SwaggerSpec._
|
||||||
|
|
||||||
import scala.io.Source
|
import scala.io.Source
|
||||||
|
import scala.collection.mutable
|
||||||
|
import scala.annotation.tailrec
|
||||||
|
|
||||||
object CoreUtils {
|
object CoreUtils {
|
||||||
def extractAllModels(apis: List[ApiListing]): Map[String, Model] = {
|
def extractAllModels(apis: List[ApiListing]): Map[String, Model] = {
|
||||||
@ -87,40 +89,28 @@ object CoreUtils {
|
|||||||
allModels.filter(m => primitives.contains(m._1) == false).toMap
|
allModels.filter(m => primitives.contains(m._1) == false).toMap
|
||||||
}
|
}
|
||||||
|
|
||||||
def recurseModels(requiredModels: Map[String, Model], allModels: Map[String, Model], subNames: HashSet[String]) = {
|
def recurseModels(requiredModels: Map[String, Model], allModels: Map[String, Model], subNames: HashSet[String]) {
|
||||||
requiredModels.map(m => recurseModel(m._2, allModels, subNames))
|
requiredModels foreach (m => subNames ++ recurseModel(m._2.properties.toList, allModels, subNames.toSet))
|
||||||
}
|
}
|
||||||
|
|
||||||
def recurseModel(model: Model, allModels: Map[String, Model], subNames: HashSet[String]): Unit = {
|
@tailrec def recurseModel(properties: List[(String, ModelProperty)], allModels: Map[String, Model], subNames: Set[String]): Set[String] = {
|
||||||
model.properties.foreach(prop => {
|
properties match {
|
||||||
val subObject = prop._2
|
case Nil => subNames
|
||||||
val propertyName = containers.contains(subObject.`type`) match {
|
case (_, subObject) :: rest =>
|
||||||
case true => subObject.items match {
|
val propertyName = if (containers.contains(subObject.`type`)) {
|
||||||
case Some(subItem) => {
|
subObject.items flatMap { subItem =>
|
||||||
Option(subItem.ref.getOrElse(subItem.`type`)) match {
|
Option(subItem.ref.getOrElse(subItem.`type`))
|
||||||
case Some(sn) => Some(sn)
|
|
||||||
case _ => None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case _ => None
|
} else Option((subObject.`type`))
|
||||||
}
|
|
||||||
case false => Some(subObject.`type`)
|
if (propertyName.isDefined && !subNames.contains(propertyName.get)) {
|
||||||
}
|
val prop = propertyName.get
|
||||||
propertyName match {
|
if (allModels.contains(prop)) {
|
||||||
case Some(property) => subNames.contains(property) match {
|
recurseModel(allModels(prop).properties.toList, allModels, subNames + prop)
|
||||||
case false => {
|
} else {
|
||||||
allModels.containsKey(property) match {
|
recurseModel(rest, allModels, subNames + prop)
|
||||||
case true => {
|
|
||||||
recurseModel(allModels(property), allModels, subNames)
|
|
||||||
}
|
|
||||||
case false =>
|
|
||||||
}
|
|
||||||
subNames += property
|
|
||||||
}
|
}
|
||||||
case true =>
|
} else recurseModel(rest, allModels, subNames)
|
||||||
}
|
}
|
||||||
case None =>
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user