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"
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")
@ -55,6 +55,9 @@ 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")))
publishMavenStyle := true
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
if (apiReferences == null)

View File

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

View File

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