diff --git a/modules/swagger-codegen/src/main/resources/scalatra/Bootstrap.mustache b/modules/swagger-codegen/src/main/resources/scalatra/Bootstrap.mustache
index 08cc829bd80..5121079424f 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/Bootstrap.mustache
+++ b/modules/swagger-codegen/src/main/resources/scalatra/Bootstrap.mustache
@@ -5,16 +5,16 @@ import javax.servlet.ServletContext
import org.scalatra.LifeCycle
class ScalatraBootstrap extends LifeCycle {
-implicit val swagger = new SwaggerApp
+ implicit val swagger = new SwaggerApp
-override def init(context: ServletContext) {
-implicit val system = ActorSystem("appActorSystem")
-try {
-{{#apiInfo}}{{#apis}}context mount (new {{classname}}, "/{{baseName}}/*")
-{{/apis}}{{/apiInfo}}
-context mount (new ResourcesApp, "/api-docs/*")
-} catch {
-case e: Throwable => e.printStackTrace()
-}
-}
+ override def init(context: ServletContext) {
+ implicit val system = ActorSystem("appActorSystem")
+ try {
+ {{#apiInfo}}{{#apis}}context mount (new {{classname}}, "/{{baseName}}/*")
+ {{/apis}}{{/apiInfo}}
+ context mount (new ResourcesApp, "/api-docs/*")
+ } catch {
+ case e: Throwable => e.printStackTrace()
+ }
+ }
}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/scalatra/JettyMain.scala b/modules/swagger-codegen/src/main/resources/scalatra/JettyMain.scala
index 69ca43c0e1f..e25f16ba392 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/JettyMain.scala
+++ b/modules/swagger-codegen/src/main/resources/scalatra/JettyMain.scala
@@ -1,7 +1,17 @@
-
+import org.eclipse.jetty.server._
+import org.eclipse.jetty.webapp.WebAppContext
+import org.scalatra.servlet.ScalatraListener
object JettyMain {
+ object conf {
+ val port = sys.env.get("PORT") map (_.toInt) getOrElse (8080)
+ val stopTimeout = sys.env.get("STOP_TIMEOUT") map (_.toInt) getOrElse (5000)
+ val connectorIdleTimeout = sys.env.get("CONNECTOR_IDLE_TIMEOUT") map (_.toInt) getOrElse (90000)
+ val webapp = sys.env.get("PUBLIC") getOrElse "webapp"
+ val contextPath = sys.env.get("CONTEXT_PATH") getOrElse "/"
+ }
+
def main(args: Array[String]) = {
val server: Server = new Server
println("starting jetty")
@@ -30,12 +40,4 @@ object JettyMain {
server.start()
}
-
- object conf {
- val port = sys.env.get("PORT") map (_.toInt) getOrElse (8080)
- val stopTimeout = sys.env.get("STOP_TIMEOUT") map (_.toInt) getOrElse (5000)
- val connectorIdleTimeout = sys.env.get("CONNECTOR_IDLE_TIMEOUT") map (_.toInt) getOrElse (90000)
- val webapp = sys.env.get("PUBLIC") getOrElse "webapp"
- val contextPath = sys.env.get("CONTEXT_PATH") getOrElse "/"
- }
}
diff --git a/modules/swagger-codegen/src/main/resources/scalatra/JsonUtil.scala b/modules/swagger-codegen/src/main/resources/scalatra/JsonUtil.scala
index 1502e1092be..691a82f563b 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/JsonUtil.scala
+++ b/modules/swagger-codegen/src/main/resources/scalatra/JsonUtil.scala
@@ -1,5 +1,7 @@
package json
+import com.fasterxml.jackson.module.scala.DefaultScalaModule
+import com.fasterxml.jackson.core.JsonGenerator.Feature
import com.fasterxml.jackson.databind._
object JsonUtil {
diff --git a/modules/swagger-codegen/src/main/resources/scalatra/README.mustache b/modules/swagger-codegen/src/main/resources/scalatra/README.mustache
index 4a80e8480a7..3ffa01fb257 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/README.mustache
+++ b/modules/swagger-codegen/src/main/resources/scalatra/README.mustache
@@ -1,7 +1,7 @@
# Swagger generated server
## Overview
-This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
+This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
[swagger-spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
is an example of building a swagger-enabled scalatra server.
diff --git a/modules/swagger-codegen/src/main/resources/scalatra/ServletApp.mustache b/modules/swagger-codegen/src/main/resources/scalatra/ServletApp.mustache
index bae9c83a77f..423b8644712 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/ServletApp.mustache
+++ b/modules/swagger-codegen/src/main/resources/scalatra/ServletApp.mustache
@@ -8,32 +8,32 @@ import org.scalatra.ScalatraServlet
import org.json4s.{DefaultFormats, Formats}
class ResourcesApp(implicit protected val system: ActorSystem, val swagger: SwaggerApp)
-extends ScalatraServlet with JacksonSwaggerBase {
-before() {
-response.headers += ("Access-Control-Allow-Origin" -> "*")
-}
+ extends ScalatraServlet with JacksonSwaggerBase {
+ before() {
+ response.headers += ("Access-Control-Allow-Origin" -> "*")
+ }
-protected def buildFullUrl(path: String) = if (path.startsWith("http")) path else {
-val port = request.getServerPort
-val h = request.getServerName
-val prot = if (port == 443) "https" else "http"
-val (proto, host) = if (port != 80 && port != 443) ("http", h+":"+port.toString) else (prot, h)
-"%s://%s%s%s".format(
-proto,
-host,
-request.getContextPath,
-path)
-}
+ protected def buildFullUrl(path: String) = if (path.startsWith("http")) path else {
+ val port = request.getServerPort
+ val h = request.getServerName
+ val prot = if (port == 443) "https" else "http"
+ val (proto, host) = if (port != 80 && port != 443) ("http", h+":"+port.toString) else (prot, h)
+ "%s://%s%s%s".format(
+ proto,
+ host,
+ request.getContextPath,
+ path)
+ }
}
class SwaggerApp extends Swagger(apiInfo = ApiSwagger.apiInfo, apiVersion = "1.0", swaggerVersion = "1.2")
object ApiSwagger {
-val apiInfo = ApiInfo(
-"""{{{appName}}}""",
-"""{{{appDescription}}}""",
-"""{{{infoUrl}}}""",
-"""{{{infoEmail}}}""",
-"""{{{licenseInfo}}}""",
-"""{{{licenseUrl}}}""")
+ val apiInfo = ApiInfo(
+ """{{{appName}}}""",
+ """{{{appDescription}}}""",
+ """{{{infoUrl}}}""",
+ """{{{infoEmail}}}""",
+ """{{{licenseInfo}}}""",
+ """{{{licenseUrl}}}""")
}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/scalatra/api.mustache b/modules/swagger-codegen/src/main/resources/scalatra/api.mustache
index bb559a6b1b3..54710361fe9 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/api.mustache
+++ b/modules/swagger-codegen/src/main/resources/scalatra/api.mustache
@@ -14,26 +14,26 @@ import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintE
import scala.collection.JavaConverters._
-class {{classname}} (implicit val swagger: Swagger) extends ScalatraServlet
-with FileUploadSupport
-with JacksonJsonSupport
-with SwaggerSupport {
-protected implicit val jsonFormats: Formats = DefaultFormats
+class {{classname}} (implicit val swagger: Swagger) extends ScalatraServlet
+ with FileUploadSupport
+ with JacksonJsonSupport
+ with SwaggerSupport {
+ protected implicit val jsonFormats: Formats = DefaultFormats
-protected val applicationDescription: String = "{{classname}}"
-override protected val applicationName: Option[String] = Some("{{baseName}}")
+ protected val applicationDescription: String = "{{classname}}"
+ override protected val applicationName: Option[String] = Some("{{baseName}}")
-before() {
-contentType = formats("json")
-response.headers += ("Access-Control-Allow-Origin" -> "*")
-}
+ before() {
+ contentType = formats("json")
+ response.headers += ("Access-Control-Allow-Origin" -> "*")
+ }
{{#operations}}
- {{#operation}}
- {{newline}}
+{{#operation}}
+ {{newline}}
- val {{nickname}}Operation = (apiOperation[{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]("{{nickname}}")
- summary "{{{summary}}}"
- parameters(
+ val {{nickname}}Operation = (apiOperation[{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]("{{nickname}}")
+ summary "{{{summary}}}"
+ parameters(
{{#allParams}}{{#isQueryParam}}queryParam[{{dataType}}]("{{paramName}}").description(""){{^required}}.optional{{/required}}{{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}}
{{/isQueryParam}}
{{#isPathParam}}pathParam[{{dataType}}]("{{paramName}}").description(""){{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}}
@@ -46,49 +46,49 @@ response.headers += ("Access-Control-Allow-Origin" -> "*")
{{/isFormParam}}
{{#hasMore}},{{/hasMore}}
{{/allParams}})
- )
+ )
- {{httpMethod}}("{{path}}",operation({{nickname}}Operation)) {
- {{#allParams}}
- {{#isFile}}
- val {{paramName}} = fileParams("{{paramName}}")
- {{/isFile}}
- {{^isFile}}
- {{#isPathParam}}
- val {{paramName}} = params.getOrElse("{{paramName}}", halt(400))
- {{/isPathParam}}
+ {{httpMethod}}("{{path}}",operation({{nickname}}Operation)) {
+ {{#allParams}}
+ {{#isFile}}
+ val {{paramName}} = fileParams("{{paramName}}")
+ {{/isFile}}
+ {{^isFile}}
+ {{#isPathParam}}
+ val {{paramName}} = params.getOrElse("{{paramName}}", halt(400))
+ {{/isPathParam}}
- {{#isQueryParam}}
- {{#collectionFormat}}val {{paramName}}String = params.getAs[String]("{{paramName}}")
- val {{paramName}} = if("{{collectionFormat}}".equals("default")) {
- {{paramName}}String match {
- case Some(str) => str.split(",")
- case None => List()
- }
- }
- else
- List()
- {{/collectionFormat}}
- {{^collectionFormat}}val {{paramName}} = params.getAs[{{dataType}}]("{{paramName}}"){{/collectionFormat}}
-
- {{/isQueryParam}}
-
- {{#isHeaderParam}}
- val {{paramName}} = request.getHeader("{{paramName}}")
- {{/isHeaderParam}}
-
- {{#isFormParam}}
- val {{paramName}} = params.getAs[{{dataType}}]("{{paramName}}")
- {{/isFormParam}}
-
- {{#isBodyParam}}
- val {{paramName}} = parsedBody.extract[{{dataType}}]
- {{/isBodyParam}}
- {{/isFile}}
- println("{{paramName}}: " + {{paramName}})
- {{/allParams}}
+ {{#isQueryParam}}
+ {{#collectionFormat}}val {{paramName}}String = params.getAs[String]("{{paramName}}")
+ val {{paramName}} = if("{{collectionFormat}}".equals("default")) {
+ {{paramName}}String match {
+ case Some(str) => str.split(",")
+ case None => List()
}
+ }
+ else
+ List()
+ {{/collectionFormat}}
+ {{^collectionFormat}}val {{paramName}} = params.getAs[{{dataType}}]("{{paramName}}"){{/collectionFormat}}
+
+ {{/isQueryParam}}
- {{/operation}}
+ {{#isHeaderParam}}
+ val {{paramName}} = request.getHeader("{{paramName}}")
+ {{/isHeaderParam}}
+
+ {{#isFormParam}}
+ val {{paramName}} = params.getAs[{{dataType}}]("{{paramName}}")
+ {{/isFormParam}}
+
+ {{#isBodyParam}}
+ val {{paramName}} = parsedBody.extract[{{dataType}}]
+ {{/isBodyParam}}
+ {{/isFile}}
+ println("{{paramName}}: " + {{paramName}})
+ {{/allParams}}
+ }
+
+{{/operation}}
{{/operations}}
}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/scalatra/build.sbt b/modules/swagger-codegen/src/main/resources/scalatra/build.sbt
index 23af47dada0..00575312d85 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/build.sbt
+++ b/modules/swagger-codegen/src/main/resources/scalatra/build.sbt
@@ -1,6 +1,4 @@
-
-
-// put this at the top of the file
+import AssemblyKeys._ // put this at the top of the file
import NativePackagerKeys._
@@ -12,7 +10,7 @@ scalariformSettings
organization := "io.swagger"
-seq(webSettings: _*)
+seq(webSettings :_*)
mainClass in assembly := Some("JettyMain")
@@ -25,40 +23,40 @@ scalaVersion := "2.11.2"
scalacOptions += "-language:postfixOps"
libraryDependencies ++= Seq(
- "org.scalatest" %% "scalatest" % "2.2.1" % "test",
- "org.scalatra" %% "scalatra" % "2.3.0.RC3",
- "org.scalatra" %% "scalatra-scalate" % "2.3.0.RC3",
- "org.scalatra" %% "scalatra-json" % "2.3.0.RC3",
- "org.scalatra" %% "scalatra-swagger" % "2.3.0.RC3",
- "org.scalatra" %% "scalatra-swagger-ext" % "2.3.0.RC3",
- "org.scalatra" %% "scalatra-slf4j" % "2.3.0.RC3",
- "org.json4s" %% "json4s-jackson" % "3.2.10",
- "org.json4s" %% "json4s-ext" % "3.2.10",
- "commons-codec" % "commons-codec" % "1.7",
- "net.databinder.dispatch" %% "dispatch-core" % "0.11.2",
+ "org.scalatest" %% "scalatest" % "2.2.1" % "test",
+ "org.scalatra" %% "scalatra" % "2.3.0.RC3",
+ "org.scalatra" %% "scalatra-scalate" % "2.3.0.RC3",
+ "org.scalatra" %% "scalatra-json" % "2.3.0.RC3",
+ "org.scalatra" %% "scalatra-swagger" % "2.3.0.RC3",
+ "org.scalatra" %% "scalatra-swagger-ext" % "2.3.0.RC3",
+ "org.scalatra" %% "scalatra-slf4j" % "2.3.0.RC3",
+ "org.json4s" %% "json4s-jackson" % "3.2.10",
+ "org.json4s" %% "json4s-ext" % "3.2.10",
+ "commons-codec" % "commons-codec" % "1.7",
+ "net.databinder.dispatch" %% "dispatch-core" % "0.11.2",
//"net.databinder.dispatch" %% "json4s-jackson" % "0.11.2",
- "net.databinder.dispatch" %% "dispatch-json4s-jackson" % "0.11.2",
- "com.typesafe.akka" %% "akka-actor" % "2.3.6",
- "org.eclipse.jetty" % "jetty-server" % "9.2.3.v20140905" % "container;compile;test",
- "org.eclipse.jetty" % "jetty-webapp" % "9.2.3.v20140905" % "container;compile;test",
- "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;compile;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))
+ "net.databinder.dispatch" %% "dispatch-json4s-jackson" % "0.11.2",
+ "com.typesafe.akka" %% "akka-actor" % "2.3.6",
+ "org.eclipse.jetty" % "jetty-server" % "9.2.3.v20140905" % "container;compile;test",
+ "org.eclipse.jetty" % "jetty-webapp" % "9.2.3.v20140905" % "container;compile;test",
+ "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;compile;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))
)
-resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository"
+resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "Sonatype OSS Releases" at "http://oss.sonatype.org/content/repositories/releases/"
ivyXML :=
-
-
-
-
+
+
+
+
mergeStrategy in assembly <<= (mergeStrategy in assembly) {
(old) => {
- case "about.html" => MergeStrategy.discard
+ case "about.html" => MergeStrategy.discard
case x => old(x)
}
}
diff --git a/modules/swagger-codegen/src/main/resources/scalatra/model.mustache b/modules/swagger-codegen/src/main/resources/scalatra/model.mustache
index f740d40bc07..8c5d1954662 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/model.mustache
+++ b/modules/swagger-codegen/src/main/resources/scalatra/model.mustache
@@ -5,11 +5,11 @@ package {{package}}
{{#models}}
- {{#model}}
- case class {{classname}} (
- {{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}] {{#description}} // {{description}}{{/description}}
- {{/isNotRequired}}{{#hasMore}},
- {{/hasMore}}{{/vars}}
- )
- {{/model}}
+{{#model}}
+case class {{classname}} (
+ {{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}] {{#description}} // {{description}}{{/description}}
+ {{/isNotRequired}}{{#hasMore}},
+ {{/hasMore}}{{/vars}}
+)
+{{/model}}
{{/models}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/scalatra/web.xml b/modules/swagger-codegen/src/main/resources/scalatra/web.xml
index a6e529e4aec..2a08440458e 100644
--- a/modules/swagger-codegen/src/main/resources/scalatra/web.xml
+++ b/modules/swagger-codegen/src/main/resources/scalatra/web.xml
@@ -1,17 +1,17 @@
-
-
- org.scalatra.servlet.ScalatraListener
-
+
+
+ org.scalatra.servlet.ScalatraListener
+
-
- default
- /*.html
- /css/*
- /js/*.js
- /images/*
-
+
+ default
+ /*.html
+ /css/*
+ /js/*.js
+ /images/*
+