From 31e65969b33c43ae37e99844437716cbf626abb0 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 30 May 2014 07:53:27 -0700 Subject: [PATCH] removed printlns, cruft --- .../swagger/codegen/BasicGenerator.scala | 36 +------------------ .../com/wordnik/swagger/codegen/Codegen.scala | 9 +++-- .../codegen/ScalaAsyncClientGenerator.scala | 4 +-- src/test/scala/BasicScalaGeneratorTest.scala | 13 ++++--- 4 files changed, 15 insertions(+), 47 deletions(-) diff --git a/src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala b/src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala index cd3a7268191..7c6a6d4729f 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala @@ -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) { diff --git a/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala b/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala index 67df7e344b3..f2b5815a00f 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala @@ -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]] diff --git a/src/main/scala/com/wordnik/swagger/codegen/ScalaAsyncClientGenerator.scala b/src/main/scala/com/wordnik/swagger/codegen/ScalaAsyncClientGenerator.scala index 9d7bfff592b..0cb0bbd904a 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/ScalaAsyncClientGenerator.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/ScalaAsyncClientGenerator.scala @@ -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 diff --git a/src/test/scala/BasicScalaGeneratorTest.scala b/src/test/scala/BasicScalaGeneratorTest.scala index d3e23b7e6a5..d58af081834 100644 --- a/src/test/scala/BasicScalaGeneratorTest.scala +++ b/src/test/scala/BasicScalaGeneratorTest.scala @@ -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)