more refactoring to support 1.2 spec

This commit is contained in:
Tony Tam
2013-08-08 15:32:37 -07:00
parent 558a9cbf64
commit 17b63b2be8
33 changed files with 77 additions and 43 deletions

View File

@@ -5,7 +5,7 @@
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<logger name="com.wordnik" level="ERROR"/>
<logger name="com.wordnik" level="DEBUG"/>
<root level="error">
<appender-ref ref="STDOUT" />
</root>

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,6 +61,7 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil {
}
implicit val basePath = getBasePath(host, doc.basePath)
println("base path is " + basePath)
val apiReferences = doc.apis
if (apiReferences == null)

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,8 @@ class BasicJavaGenerator extends BasicGenerator {
"float" -> "Float",
"long" -> "Long",
"double" -> "Double",
"object" -> "Object")
"object" -> "Object",
"integer" -> "Integer")
// location of templates
override def templateDir = "Java"

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,9 @@ trait PathUtil {
}
def toModelName(name: String) = {
name(0).toUpper + name.substring(1)
if(name.length > 0)
name(0).toUpper + name.substring(1)
else "MISSING MODEL NAME"
}
def toApiName(name: String) = {

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,13 +31,14 @@ 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"))
val path = if(api.path.startsWith("http")) api.path
else basePath + api.path
println("calling: " + ((path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json")))
urlToString((path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json"))
}
case false => Source.fromFile((basePath + api.path).replaceAll(".\\{format\\}", ".json")).mkString
}

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -12,6 +12,20 @@ import scala.collection.mutable.{ListBuffer, LinkedHashMap}
object SwaggerSerializers {
import ValidationMessage._
val swaggerTypeMap = Map(
// simple types
("integer", "int32") -> "int",
("integer", "int64") -> "long",
("number", "float") -> "float",
("number", "double") -> "double",
("string", "byte") -> "byte",
("string", "date") -> "Date",
("string", "date-time") -> "Date",
// containers
("array", "") -> "Array"
)
implicit val formats = DefaultFormats +
new ModelSerializer +
new ModelPropertySerializer +
@@ -326,9 +340,20 @@ object SwaggerSerializers {
class ModelPropertySerializer extends CustomSerializer[ModelProperty] (formats => ({
case json =>
implicit val fmts: Formats = formats
val `type` = (json \ "$ref") match {
case e: JString => e.s
case _ => {
// convert the jsonschema types into swagger types. Note, this logic will move elsewhere soon
SwaggerSerializers.swaggerTypeMap.getOrElse(
((json \ "type").extractOrElse(""), (json \ "format").extractOrElse(""))
, (json \ "type").extractOrElse(""))
}
}
ModelProperty(
`type` = (json \ "type").extractOrElse(""),
`qualifiedType` = (json \ "type").extractOrElse(""),
`type` = `type`,
`qualifiedType` = `type`,
required = (json \ "required") match {
case e:JString => e.s.toBoolean
case e:JBool => e.value

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
import com.wordnik.swagger.codegen.BasicScalaGenerator
import com.wordnik.swagger.codegen.PathUtil
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@@ -45,7 +46,10 @@ class PathUtilTest extends FlatSpec with ShouldMatchers {
* since swagger-spec 1.2 doesn't support `basePath` in the Resource Listing,
* ensure the base path is extracted from the input host
**/
it should "get determine the basePath implicitly" in {
config.getBasePath("http://foo.com/api-docs", "") should be ("http://foo.com/api-docs")
}
}
it should "get determine the basePath implicitly" in {
sys.props -= "fileMap"
new PathUtilImpl().getBasePath("http://foo.com/api-docs", "") should be ("http://foo.com/api-docs")
}
}
class PathUtilImpl extends PathUtil

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2012 Wordnik, Inc.
* Copyright 2013 Wordnik, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.