added support for swagger 1.2 spec

This commit is contained in:
Tony Tam 2013-06-30 21:36:52 -07:00
parent a31780e08f
commit 885cd36165
4 changed files with 42 additions and 30 deletions

View File

@ -5,9 +5,9 @@ organization := "com.wordnik"
name := "swagger-codegen" name := "swagger-codegen"
version := "2.0.5" version := "2.0.6"
scalaVersion := "2.9.2" scalaVersion := "2.9.1"
javacOptions ++= Seq("-target", "1.6", "-source", "1.6", "-Xlint:unchecked", "-Xlint:deprecation") javacOptions ++= Seq("-target", "1.6", "-source", "1.6", "-Xlint:unchecked", "-Xlint:deprecation")
@ -55,6 +55,9 @@ publishTo <<= (version) { version: String =>
Some("Sonatype Nexus Releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2") 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")))
publishMavenStyle := true publishMavenStyle := true
publishArtifact in Test := false publishArtifact in Test := false

View File

@ -60,7 +60,13 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil {
} }
} }
implicit val basePath = getBasePath(doc.basePath) implicit val basePath = getBasePath(doc.basePath) match {
case "" => {
// use host
host
}
case e: String => e
}
val apiReferences = doc.apis val apiReferences = doc.apis
if (apiReferences == null) if (apiReferences == null)

View File

@ -31,29 +31,30 @@ object ApiExtractor extends RemoteUrl {
implicit val formats = SwaggerSerializers.formats implicit val formats = SwaggerSerializers.formats
def fetchApiListings(basePath: String, apis: List[ApiListingReference], apiKey: Option[String] = None): List[ApiListing] = { def fetchApiListings(basePath: String, apis: List[ApiListingReference], apiKey: Option[String] = None): List[ApiListing] = {
println("looking at base path " + basePath)
(for (api <- apis) yield { (for (api <- apis) yield {
try{ try{
val json = basePath.startsWith("http") match { val json = (basePath.startsWith("http")) match {
case true => { case true => {
println("calling: " + ((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json"))) println("calling: " + ((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json")))
urlToString((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json")) urlToString((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json"))
}
case false => Source.fromFile((basePath + api.path).replaceAll(".\\{format\\}", ".json")).mkString
}
Some(parse(json).extract[ApiListing])
} }
catch { case false => Source.fromFile((basePath + api.path).replaceAll(".\\{format\\}", ".json")).mkString
case e: java.io.FileNotFoundException => { }
println("WARNING! Unable to read API " + basePath + api.path) Some(parse(json).extract[ApiListing])
None }
} catch {
case e: Throwable => { case e: java.io.FileNotFoundException => {
println("WARNING! Unable to read API " + basePath + api.path) println("WARNING! Unable to read API " + basePath + api.path)
e.printStackTrace() None
None }
} case e: Throwable => {
} println("WARNING! Unable to read API " + basePath + api.path)
}).flatten.toList e.printStackTrace()
None
}
}
}).flatten.toList
} }
def extractApiOperations(basePath: String, references: List[ApiListingReference], apiKey: Option[String] = None) = { def extractApiOperations(basePath: String, references: List[ApiListingReference], apiKey: Option[String] = None) = {

View File

@ -89,7 +89,7 @@ object SwaggerSerializers {
"" ""
}), }),
(json \ "basePath").extractOrElse({ (json \ "basePath").extractOrElse({
!!(json, RESOURCE_LISTING, "basePath", "missing required field", ERROR) !!(json, RESOURCE_LISTING, "basePath", "missing deprecated field", WARNING)
"" ""
}), }),
(json \ "apis").extract[List[ApiListingReference]] (json \ "apis").extract[List[ApiListingReference]]
@ -177,10 +177,12 @@ object SwaggerSerializers {
case json => case json =>
implicit val fmts: Formats = formats implicit val fmts: Formats = formats
Operation( Operation(
(json \ "httpMethod").extractOrElse({ (json \ "httpMethod").extractOrElse(
!!(json, OPERATION, "httpMethod", "missing required field", ERROR) (json \ "method").extractOrElse({
"" !!(json, OPERATION, "method", "missing required field", ERROR)
}), ""
})
),
(json \ "summary").extract[String], (json \ "summary").extract[String],
(json \ "notes").extractOrElse(""), (json \ "notes").extractOrElse(""),
(json \ "responseClass").extractOrElse({ (json \ "responseClass").extractOrElse({
@ -198,7 +200,7 @@ object SwaggerSerializers {
}, { }, {
case x: Operation => case x: Operation =>
implicit val fmts = formats implicit val fmts = formats
("httpMethod" -> x.httpMethod) ~ ("method" -> x.httpMethod) ~
("summary" -> x.summary) ~ ("summary" -> x.summary) ~
("notes" -> x.notes) ~ ("notes" -> x.notes) ~
("responseClass" -> x.responseClass) ~ ("responseClass" -> x.responseClass) ~