removed printlns, cruft

This commit is contained in:
Tony Tam 2014-05-30 07:53:27 -07:00
parent df250bc056
commit 31e65969b3
4 changed files with 15 additions and 47 deletions

View File

@ -109,7 +109,6 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil {
new SwaggerSpecValidator(doc, apis).validate()
println("prepare model bundle")
val allModels = new HashMap[String, Model]
val operations = extractApiOperations(apis, allModels)
val operationMap: Map[(String, String), List[(String, Operation)]] =
@ -130,16 +129,7 @@ println("prepare model bundle")
fw.close()
}
println("prepare api bundle")
val apiBundle = prepareApiBundle(operationMap.toMap)
// println(apiBundle)
// println(pretty(render(parse(write(apiBundle)))))
// for(i <- apiBundle; (a, b) <- i) println(i)
// println(pretty(render(parse(write(apiBundle)))))
println("made api bundle")
val apiInfo = writeFiles(apiBundle, apiTemplateFiles.toMap)
val apiFiles = new ListBuffer[File]()
@ -152,10 +142,9 @@ println("made api bundle")
val fw = new FileWriter(filename, false)
fw.write(m._2 + "\n")
fw.close()
// println("wrote api " + filename)
println("wrote api " + filename)
})
println("supporting classes")
codegen.writeSupportingClasses2(apiBundle, allModels.toMap, doc.apiVersion) ++
modelFiles ++ apiFiles
}
@ -338,29 +327,6 @@ println("supporting classes")
}).flatten.toList
}
def bundleToSource(bundle:List[Map[String, AnyRef]], templates: Map[String, String]): List[(String, String)] = {
val output = new ListBuffer[(String, String)]
bundle.foreach(m => {
for ((file, suffix) <- templates) {
val filename = m("outputDirectory").toString + File.separator + m("filename").toString + suffix
output += Tuple2(filename, codegen.generateSource(m, file))
}
})
output.toList
}
def generateAndWrite(bundle: Map[String, AnyRef], templateFile: String) = {
val output = codegen.generateSource(bundle, templateFile)
val outputDir = new File(bundle("outputDirectory").asInstanceOf[String])
outputDir.mkdirs
val filename = outputDir + File.separator + bundle("filename")
val fw = new FileWriter(filename, false)
fw.write(output + "\n")
fw.close()
println("wrote " + filename)
}
def groupOperationsToFiles(operations: List[(String, String, Operation)]): Map[(String, String), List[(String, Operation)]] = {
val opMap = new HashMap[(String, String), ListBuffer[(String, Operation)]]
for ((basePath, apiPath, operation) <- operations) {

View File

@ -44,15 +44,14 @@ object Codegen {
class Codegen(config: CodegenConfig) {
implicit val formats = SwaggerSerializers.formats("1.2")
@deprecated
def generateSource(bundle: Map[String, AnyRef], templateFile: String): String = {
println("~~~~~~~ Generate Source ~~~~~~~~")
val allImports = new HashSet[String]
val includedModels = new HashSet[String]
val modelList = new ListBuffer[Map[String, AnyRef]]
// val models = bundle("models").asInstanceOf[Tuple2[String, List[(String, AnyRef)]]]
val models = bundle("models").asInstanceOf[Tuple2[String, List[(String, AnyRef)]]]
// println(models)
/* models match {
models match {
case e: List[Tuple2[String, Model]] => {
e.foreach(m => {
includedModels += m._1
@ -66,7 +65,7 @@ class Codegen(config: CodegenConfig) {
}
case _ =>
}
*/
val modelData = Map[String, AnyRef]("model" -> modelList.toList)
val operationList = new ListBuffer[Map[String, AnyRef]]
val classNameToOperationList = new HashMap[String, ListBuffer[AnyRef]]

View File

@ -419,7 +419,7 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
}
}
override def bundleToSource(bundle:List[Map[String, AnyRef]], templates: Map[String, String]): List[(String, String)] = {
def bundleToSource(bundle:List[Map[String, AnyRef]], templates: Map[String, String]): List[(String, String)] = {
bundle.foldLeft(List.empty[(String, String)]) { (acc, m) =>
templates.foldLeft(acc) { (out, tem) =>
val (file, suffix) = tem
@ -428,7 +428,7 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
}
}
override def generateAndWrite(bundle: Map[String, AnyRef], templateFile: String) = {
def generateAndWrite(bundle: Map[String, AnyRef], templateFile: String) = {
val output = codegen.generateSource(bundle, templateFile)
val outputDir = new File(bundle("outputDirectory").asInstanceOf[String])
outputDir.mkdirs

View File

@ -280,12 +280,15 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
val allModels = new HashMap[String, Model]
val operations = config.extractApiOperations(List(petApi), allModels)
val apiMap = config.groupOperationsToFiles(operations)
val bundle = config.prepareApiBundle(apiMap)
val apiFiles = config.bundleToSource(bundle, config.apiTemplateFiles.toMap)
val operationMap = config.groupOperationsToFiles(operations)
// val bundle = config.prepareApiBundle(apiMap)
// val apiFiles = config.bundleToSource(bundle, config.apiTemplateFiles.toMap)
apiFiles.size should be (1)
val file = apiFiles.head
val apiBundle = config.prepareApiBundle(operationMap.toMap)
val apiInfo = config.writeFiles(apiBundle, config.apiTemplateFiles.toMap)
apiInfo.size should be (1)
val file = apiInfo.head
// verify the filename is set
file._1.indexOf("""PetApi.scala""") should not be (-1)