forked from loafle/openapi-generator-original
removed unused code
This commit is contained in:
parent
31e65969b3
commit
d91da857a0
@ -43,7 +43,7 @@ object Codegen {
|
|||||||
|
|
||||||
class Codegen(config: CodegenConfig) {
|
class Codegen(config: CodegenConfig) {
|
||||||
implicit val formats = SwaggerSerializers.formats("1.2")
|
implicit val formats = SwaggerSerializers.formats("1.2")
|
||||||
|
/*
|
||||||
@deprecated
|
@deprecated
|
||||||
def generateSource(bundle: Map[String, AnyRef], templateFile: String): String = {
|
def generateSource(bundle: Map[String, AnyRef], templateFile: String): String = {
|
||||||
val allImports = new HashSet[String]
|
val allImports = new HashSet[String]
|
||||||
@ -170,7 +170,7 @@ class Codegen(config: CodegenConfig) {
|
|||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
def compileTemplate(templateFile: String, rootDir: Option[File] = None, engine: Option[TemplateEngine] = None): (String, (TemplateEngine, Template)) = {
|
def compileTemplate(templateFile: String, rootDir: Option[File] = None, engine: Option[TemplateEngine] = None): (String, (TemplateEngine, Template)) = {
|
||||||
val engine = new TemplateEngine(rootDir orElse Some(new File(".")))
|
val engine = new TemplateEngine(rootDir orElse Some(new File(".")))
|
||||||
val srcName = config.templateDir + "/" + templateFile
|
val srcName = config.templateDir + "/" + templateFile
|
||||||
@ -573,7 +573,6 @@ class Codegen(config: CodegenConfig) {
|
|||||||
"models" -> allModels,
|
"models" -> allModels,
|
||||||
"apiVersion" -> apiVersion) ++ config.additionalParams
|
"apiVersion" -> apiVersion) ++ config.additionalParams
|
||||||
|
|
||||||
println(pretty(render(parse(write(data)))))
|
|
||||||
val outputFiles = config.supportingFiles map { file =>
|
val outputFiles = config.supportingFiles map { file =>
|
||||||
val supportingFile = file._1
|
val supportingFile = file._1
|
||||||
val outputDir = file._2
|
val outputDir = file._2
|
||||||
@ -615,7 +614,7 @@ println(pretty(render(parse(write(data)))))
|
|||||||
engine.compiler.shutdown()
|
engine.compiler.shutdown()
|
||||||
outputFiles
|
outputFiles
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
final def writeSupportingClasses(
|
final def writeSupportingClasses(
|
||||||
apis: Map[(String, String), List[(String, Operation)]],
|
apis: Map[(String, String), List[(String, Operation)]],
|
||||||
models: Map[String, Model],
|
models: Map[String, Model],
|
||||||
@ -722,7 +721,7 @@ println(pretty(render(parse(write(data)))))
|
|||||||
|
|
||||||
writeSupportingClasses(apis, models, apiVersion, rootDir, dataF)
|
writeSupportingClasses(apis, models, apiVersion, rootDir, dataF)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
protected def isListType(dt: String) = isCollectionType(dt, "List") || isCollectionType(dt, "Array") || isCollectionType(dt, "Set")
|
protected def isListType(dt: String) = isCollectionType(dt, "List") || isCollectionType(dt, "Array") || isCollectionType(dt, "Set")
|
||||||
|
|
||||||
protected def isMapType(dt: String) = isCollectionType(dt, "Map")
|
protected def isMapType(dt: String) = isCollectionType(dt, "Map")
|
||||||
|
@ -114,7 +114,7 @@ object ScalaAsyncClientGenerator extends App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AsyncClientCodegen(clientName: String, config: CodegenConfig, rootDir: Option[File] = None) extends Codegen(config) {
|
class AsyncClientCodegen(clientName: String, config: CodegenConfig, rootDir: Option[File] = None) extends Codegen(config) {
|
||||||
|
/*
|
||||||
override def writeSupportingClasses(apis: Map[(String, String), List[(String, Operation)]],
|
override def writeSupportingClasses(apis: Map[(String, String), List[(String, Operation)]],
|
||||||
models: Map[String, Model], apiVersion: String): Seq[File] = {
|
models: Map[String, Model], apiVersion: String): Seq[File] = {
|
||||||
|
|
||||||
@ -177,6 +177,7 @@ class AsyncClientCodegen(clientName: String, config: CodegenConfig, rootDir: Opt
|
|||||||
val template = eng.compile(TemplateSource.fromText(resourceName,Source.fromInputStream(is).mkString))
|
val template = eng.compile(TemplateSource.fromText(resourceName,Source.fromInputStream(is).mkString))
|
||||||
(resourceName, eng -> template)
|
(resourceName, eng -> template)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
||||||
@ -308,30 +309,29 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
|||||||
val allModels = new mutable.HashMap[String, Model]
|
val allModels = new mutable.HashMap[String, Model]
|
||||||
val operations = extractApiOperations(apis, allModels)
|
val operations = extractApiOperations(apis, allModels)
|
||||||
val operationMap = groupOperationsToFiles(operations)
|
val operationMap = groupOperationsToFiles(operations)
|
||||||
val modelBundle = prepareModelMap(allModels.toMap)
|
|
||||||
val modelFiles = bundleToSource(modelBundle, modelTemplateFiles.toMap)
|
|
||||||
|
|
||||||
modelFiles.map(m => {
|
val modelMap = prepareModelMap(allModels.toMap)
|
||||||
val filename = m._1
|
|
||||||
|
|
||||||
|
val modelFileContents = writeFiles(modelMap, modelTemplateFiles.toMap)
|
||||||
|
val modelFiles = new ListBuffer[File]()
|
||||||
|
|
||||||
|
for((filename, contents) <- modelFileContents) {
|
||||||
val file = new java.io.File(filename)
|
val file = new java.io.File(filename)
|
||||||
|
modelFiles += file
|
||||||
file.getParentFile().mkdirs
|
file.getParentFile().mkdirs
|
||||||
|
|
||||||
val fw = new FileWriter(filename, false)
|
val fw = new FileWriter(filename, false)
|
||||||
fw.write(m._2 + "\n")
|
fw.write(contents + "\n")
|
||||||
fw.close()
|
fw.close()
|
||||||
println("wrote model " + filename)
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val apiBundle = prepareApiBundle(operationMap.toMap)
|
val apiBundle = prepareApiBundle(operationMap.toMap)
|
||||||
val apiFiles = bundleToSource(apiBundle, apiTemplateFiles.toMap)
|
val apiInfo = writeFiles(apiBundle, apiTemplateFiles.toMap)
|
||||||
|
val apiFiles = new ListBuffer[File]()
|
||||||
|
|
||||||
apiFiles.map(m => {
|
apiInfo.map(m => {
|
||||||
val filename = m._1
|
val filename = m._1
|
||||||
|
|
||||||
val file = new java.io.File(filename)
|
val file = new java.io.File(filename)
|
||||||
|
apiFiles += file
|
||||||
file.getParentFile().mkdirs
|
file.getParentFile().mkdirs
|
||||||
|
|
||||||
val fw = new FileWriter(filename, false)
|
val fw = new FileWriter(filename, false)
|
||||||
@ -340,7 +340,8 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
|||||||
println("wrote api " + filename)
|
println("wrote api " + filename)
|
||||||
})
|
})
|
||||||
|
|
||||||
codegen.writeSupportingClasses(operationMap, allModels.toMap, doc.apiVersion)
|
codegen.writeSupportingClasses2(apiBundle, allModels.toMap, doc.apiVersion) ++
|
||||||
|
modelFiles ++ apiFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -381,6 +382,7 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
|||||||
/**
|
/**
|
||||||
* creates a map of models and properties needed to write source
|
* creates a map of models and properties needed to write source
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
override def prepareModelMap(models: Map[String, Model]): List[Map[String, AnyRef]] = {
|
override def prepareModelMap(models: Map[String, Model]): List[Map[String, AnyRef]] = {
|
||||||
for {
|
for {
|
||||||
(name, schema) <- (models -- defaultIncludes).toList
|
(name, schema) <- (models -- defaultIncludes).toList
|
||||||
@ -439,7 +441,7 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
|||||||
fw.close()
|
fw.close()
|
||||||
println("wrote " + filename)
|
println("wrote " + filename)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
override def groupOperationsToFiles(operations: List[(String, String, Operation)]): Map[(String, String), List[(String, Operation)]] = {
|
override def groupOperationsToFiles(operations: List[(String, String, Operation)]): Map[(String, String), List[(String, Operation)]] = {
|
||||||
val opMap = new mutable.HashMap[(String, String), mutable.ListBuffer[(String, Operation)]]
|
val opMap = new mutable.HashMap[(String, String), mutable.ListBuffer[(String, Operation)]]
|
||||||
for ((basePath, apiPath, operation) <- operations) {
|
for ((basePath, apiPath, operation) <- operations) {
|
||||||
|
@ -265,7 +265,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
|||||||
queryParam("allowableValues") should be (Some("LIST[available,pending,sold]"))
|
queryParam("allowableValues") should be (Some("LIST[available,pending,sold]"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ignore should "create an api file" in {
|
it should "create an api file" in {
|
||||||
implicit val basePath = "http://localhost:8080/api"
|
implicit val basePath = "http://localhost:8080/api"
|
||||||
val codegen = new Codegen(config)
|
val codegen = new Codegen(config)
|
||||||
val resourceListing = ResourceExtractor.fetchListing("src/test/resources/petstore-1.1/resources.json", None)
|
val resourceListing = ResourceExtractor.fetchListing("src/test/resources/petstore-1.1/resources.json", None)
|
||||||
@ -281,8 +281,6 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
|||||||
val operations = config.extractApiOperations(List(petApi), allModels)
|
val operations = config.extractApiOperations(List(petApi), allModels)
|
||||||
|
|
||||||
val operationMap = config.groupOperationsToFiles(operations)
|
val operationMap = config.groupOperationsToFiles(operations)
|
||||||
// val bundle = config.prepareApiBundle(apiMap)
|
|
||||||
// val apiFiles = config.bundleToSource(bundle, config.apiTemplateFiles.toMap)
|
|
||||||
|
|
||||||
val apiBundle = config.prepareApiBundle(operationMap.toMap)
|
val apiBundle = config.prepareApiBundle(operationMap.toMap)
|
||||||
val apiInfo = config.writeFiles(apiBundle, config.apiTemplateFiles.toMap)
|
val apiInfo = config.writeFiles(apiBundle, config.apiTemplateFiles.toMap)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user