moved to petstore

This commit is contained in:
Tony Tam 2014-07-04 10:19:48 -07:00
parent 256485ec5b
commit 5d42c8cc5f
5 changed files with 34 additions and 152 deletions

View File

@ -22,8 +22,8 @@ cd $APP_DIR
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files/resources.json"
ags="$@ SwaggerDocGenerator https://api.wordnik.com/v4/resources.json"
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties "
ags="$@ com.wordnik.swagger.codegen.SwaggerDocGenerator http://petstore.swagger.wordnik.com/api/api-docs"
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar ]; then
scala -cp target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar $ags

View File

@ -7,8 +7,6 @@ name := "swagger-codegen"
version := "2.0.17-SNAPSHOT"
scalaVersion := "2.10.0"
crossVersion := CrossVersion.full
javacOptions ++= Seq("-target", "1.6", "-source", "1.6", "-Xlint:unchecked", "-Xlint:deprecation")
@ -17,6 +15,8 @@ scalacOptions ++= Seq("-optimize", "-unchecked", "-deprecation", "-Xcheckinit",
crossScalaVersions := Seq("2.9.0", "2.9.0-1", "2.9.1", "2.9.1-1", "2.9.2", "2.9.3", "2.10.0", "2.10.1", "2.10.2", "2.10.3", "2.10.4", "2.11.0", "2.11.1")
scalaVersion := "2.10.0"
libraryDependencies ++= Seq(
"org.json4s" %% "json4s-jackson" % "3.2.10",
"io.backchat.inflector" %% "scala-inflector" % "1.3.5",
@ -66,7 +66,7 @@ publishTo <<= (version) { version: String =>
Some("Sonatype Nexus Releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
}
//publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
artifact in (Compile, assembly) ~= { art =>
art.copy(`classifier` = Some("assembly"))

View File

@ -43,134 +43,7 @@ object Codegen {
class Codegen(config: CodegenConfig) {
implicit val formats = SwaggerSerializers.formats("1.2")
/*
@deprecated
def generateSource(bundle: Map[String, AnyRef], templateFile: String): String = {
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)]]]
models match {
case e: List[Tuple2[String, Model]] => {
e.foreach(m => {
includedModels += m._1
val modelMap = modelToMap(m._1, m._2)
modelMap.getOrElse("imports", None) match {
case im: Set[Map[String, String]] => im.foreach(m => m.map(e => allImports += e._2))
case None =>
}
modelList += modelMap
})
}
case _ =>
}
val modelData = Map[String, AnyRef]("model" -> modelList.toList)
val operationList = new ListBuffer[Map[String, AnyRef]]
val classNameToOperationList = new HashMap[String, ListBuffer[AnyRef]]
val apis = bundle("apis")
apis match {
case a: Map[String, List[(String, Operation)]] => {
a.map(op => {
val classname = op._1
val ops = op._2
for ((apiPath, operation) <- ops) {
val opList = classNameToOperationList.getOrElse(classname, {
val lb = new ListBuffer[AnyRef]
classNameToOperationList += classname -> lb
lb
})
opList += apiToMap(apiPath, operation)
CoreUtils.extractModelNames(operation).foreach(i => allImports += i)
}
})
}
case None =>
}
val f = new ListBuffer[AnyRef]
classNameToOperationList.map(m => f += Map("classname" -> m._1, "operation" -> m._2))
val imports = new ListBuffer[Map[String, String]]
val importScope = config.modelPackage match {
case Some(s) => s + "."
case None => ""
}
// do the mapping before removing primitives!
allImports.foreach(i => {
val model = config.toModelName(i)
includedModels.contains(model) match {
case false => {
config.importMapping.containsKey(model) match {
case true => {
if(!imports.flatten.map(m => m._2).toSet.contains(config.importMapping(model))) {
imports += Map("import" -> config.importMapping(model))
}
}
case false =>
}
}
case true =>
}
})
allImports --= config.defaultIncludes
allImports --= primitives
allImports --= containers
allImports.foreach(i => {
val model = config.toModelName(i)
includedModels.contains(model) match {
case false => {
config.importMapping.containsKey(model) match {
case true =>
case false => {
if(!imports.flatten.map(m => m._2).toSet.contains(importScope + model)){
imports += Map("import" -> (importScope + model))
}
}
}
}
case true => // no need to add the model
}
})
val rootDir = new java.io.File(".")
val (resourcePath, (engine, template)) = Codegen.templates.getOrElseUpdate(templateFile, compileTemplate(templateFile, Some(rootDir)))
val requiredModels = {
for(i <- allImports) yield {
HashMap("name" -> i, "hasMore" -> "true")
}
}.toList
requiredModels.size match {
case i if (i > 0) => requiredModels.last += "hasMore" -> "false"
case _ =>
}
var data = Map[String, AnyRef](
"name" -> bundle("name"),
"modelPackage" -> bundle.getOrElse("modelPackage", None),
"package" -> bundle("package"),
"baseName" -> bundle.getOrElse("baseName", None),
"className" -> bundle("className"),
"invokerPackage" -> bundle("invokerPackage"),
"imports" -> imports,
"requiredModels" -> requiredModels,
"operations" -> f,
"models" -> modelData,
"basePath" -> bundle.getOrElse("basePath", ""))
var output = engine.layout(resourcePath, template, data.toMap)
// a shutdown method will be added to scalate in an upcoming release
engine.compiler.shutdown
output
}
*/
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 srcName = config.templateDir + "/" + templateFile

View File

@ -285,10 +285,8 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
modelTemplateFiles ++= cfg.api.modelTemplates
apiTemplateFiles ++= cfg.api.apiTemplates
codegen = new AsyncClientCodegen(cfg.api.clientName, this, Some(cfg.projectRoot))
override def getBasePath(host: String, basePath: String, fileMap: Option[String]): String =
cfg.api.baseUrl.getOrElse(super.getBasePath(host, basePath, fileMap))
/*

View File

@ -16,9 +16,9 @@ object SwaggerValidator {
val errors = new ListBuffer[ValidationError]
if(resource.apiVersion == "")
errors += ValidationError("resourceListing", "apiVersion", ERROR)
errors += ValidationError("resourceListing", "apiVersion is required", ERROR)
if(resource.swaggerVersion == "")
errors += ValidationError("resourceListing", "apiVersion", ERROR)
errors += ValidationError("resourceListing", "apiVersion is required", ERROR)
for(api <- resource.apis)
validate(api, errors, "resourceListing")
errors.toList
@ -26,26 +26,30 @@ object SwaggerValidator {
def validate(ref: ApiListingReference, errors: ListBuffer[ValidationError], parent: String): Unit = {
if(ref.path == "")
errors += ValidationError(parent + ":api", "path", ERROR)
errors += ValidationError(parent + ":[api]", "path is required", ERROR)
}
def validate(api: ApiListing, errors: ListBuffer[ValidationError]): Unit = {
if(api.swaggerVersion == "")
errors += ValidationError("apiDeclaration", "swaggerVersion", ERROR)
errors += ValidationError("apiDeclaration", "swaggerVersion is required", ERROR)
if(api.apiVersion == "")
errors += ValidationError("apiDeclaration", "apiVersion", ERROR)
errors += ValidationError("apiDeclaration", "apiVersion is required", ERROR)
if(api.basePath == "")
errors += ValidationError("apiDeclaration", "basePath", ERROR)
errors += ValidationError("apiDeclaration", "basePath is required", ERROR)
if(api.resourcePath == "")
errors += ValidationError("apiDeclaration", "resourcePath", ERROR)
errors += ValidationError("apiDeclaration", "resourcePath is required", ERROR)
val name = {
if(api.resourcePath == "") "[unknown]"
else api.resourcePath
}
for(a <- api.apis) {
validate(a, errors, api.resourcePath)
validate(a, errors, name)
}
api.models match {
case Some(m) => for((name, model) <- m) {
validate(model, errors, api.resourcePath)
validate(model, errors, name)
}
case None =>
}
@ -53,23 +57,23 @@ object SwaggerValidator {
def validate(model: Model, errors: ListBuffer[ValidationError], parent: String): Unit = {
if(model.id == "")
errors += ValidationError(parent + ":model", "id", ERROR)
errors += ValidationError(parent + ":[model]", "id is required", ERROR)
}
def validate(desc: ApiDescription, errors: ListBuffer[ValidationError], parent: String): Unit = {
if(desc.path == "")
errors += ValidationError(parent + ":api", "path", ERROR)
errors += ValidationError(parent + ":[api]", "path is required", ERROR)
for(op <- desc.operations)
validate(op, errors, parent + ":" + desc.path)
}
def validate(op: Operation, errors: ListBuffer[ValidationError], parent: String): Unit = {
if(op.method == "")
errors += ValidationError(parent + ":operation", "method", ERROR)
errors += ValidationError(parent + ":[operation]", "method is required", ERROR)
if(op.nickname == "")
errors += ValidationError(parent + ":" + op.method, "nickname", WARNING)
errors += ValidationError(parent + ":" + op.method, "nickname is recommended", WARNING)
if(op.responseClass == "")
errors += ValidationError(parent + ":" + op.method, "responseClass", ERROR)
errors += ValidationError(parent + ":" + op.method, "responseClass is required", ERROR)
for(resp <- op.responseMessages)
validate(resp, errors, parent)
for(param <- op.parameters)
@ -77,16 +81,23 @@ object SwaggerValidator {
}
def validate(param: Parameter, errors: ListBuffer[ValidationError], parent: String): Unit = {
val name = if(param.name == "")
"[unknown]"
else
param.name
if(param.name == "")
errors += ValidationError("Parameter", "name", ERROR)
errors += ValidationError(parent + ":[parameter]", "name is required", ERROR)
if(param.paramType == "")
errors += ValidationError("Parameter", "paramType", ERROR)
errors += ValidationError(parent + name, "paramType is required", ERROR)
if(param.dataType == "")
errors += ValidationError(parent + name, "type is required", ERROR)
}
def validate(resp: ResponseMessage, errors: ListBuffer[ValidationError], parent: String): Unit = {
if(resp.code == 0)
errors += ValidationError("ResponseMessage", "code", ERROR)
errors += ValidationError(parent + ":[responseMessage]", "code is required", ERROR)
if(resp.message == 0)
errors += ValidationError("ResponseMessage", "message", ERROR)
errors += ValidationError(parent + ":[responseMessage]", "message is required", ERROR)
}
}