From 539496d73572a50be8d51e07697fde3b582a237d Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 20 Oct 2015 07:10:05 -0700 Subject: [PATCH] rebuilt --- .../src/main/resources/scalatra/api.mustache | 53 +-- .../resources/scalatra/bodyParam.mustache | 1 + .../scalatra/bodyParamOperation.mustache | 3 + .../resources/scalatra/formParam.mustache | 1 + .../scalatra/formParamMustache.mustache | 3 + .../resources/scalatra/headerParam.mustache | 1 + .../scalatra/headerParamOperation.mustache | 3 + .../resources/scalatra/pathParam.mustache | 1 + .../resources/scalatra/queryParam.mustache | 1 + .../scalatra/queryParamOperation.mustache | 13 + samples/server/petstore/scalatra/README.md | 6 +- samples/server/petstore/scalatra/build.sbt | 52 ++- samples/server/petstore/scalatra/sbt | 0 .../scalatra/src/main/scala/JettyMain.scala | 20 +- .../src/main/scala/ScalatraBootstrap.scala | 16 +- .../scalatra/src/main/scala/ServletApp.scala | 32 +- .../scala/com/wordnik/client/api/PetApi.scala | 397 ++++++++---------- .../com/wordnik/client/api/StoreApi.scala | 135 +++--- .../com/wordnik/client/api/UserApi.scala | 311 ++++++-------- .../com/wordnik/client/model/Category.scala | 9 +- .../com/wordnik/client/model/Order.scala | 16 +- .../scala/com/wordnik/client/model/Pet.scala | 19 +- .../scala/com/wordnik/client/model/Tag.scala | 9 +- .../scala/com/wordnik/client/model/User.scala | 21 +- .../scalatra/src/main/webapp/WEB-INF/web.xml | 28 +- 25 files changed, 531 insertions(+), 620 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/bodyParam.mustache create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/bodyParamOperation.mustache create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/formParam.mustache create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/formParamMustache.mustache create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/headerParam.mustache create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/headerParamOperation.mustache create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/pathParam.mustache create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/queryParam.mustache create mode 100644 modules/swagger-codegen/src/main/resources/scalatra/queryParamOperation.mustache mode change 100644 => 100755 samples/server/petstore/scalatra/sbt diff --git a/modules/swagger-codegen/src/main/resources/scalatra/api.mustache b/modules/swagger-codegen/src/main/resources/scalatra/api.mustache index 54710361fe..b6749641e5 100644 --- a/modules/swagger-codegen/src/main/resources/scalatra/api.mustache +++ b/modules/swagger-codegen/src/main/resources/scalatra/api.mustache @@ -33,57 +33,16 @@ class {{classname}} (implicit val swagger: Swagger) extends ScalatraServlet 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}} - {{/isPathParam}} - {{#isHeaderParam}}headerParam[{{dataType}}]("{{paramName}}").description(""){{^required}}.optional{{/required}}{{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}} - {{/isHeaderParam}} - {{#isBodyParam}}bodyParam[{{dataType}}]("{{paramName}}").description(""){{^required}}.optional{{/required}}{{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}} - {{/isBodyParam}} - {{#isFormParam}}formParam[{{dataType}}]("{{paramName}}").description(""){{^required}}.optional{{/required}}{{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}} - {{/isFormParam}} - {{#hasMore}},{{/hasMore}} - {{/allParams}}) + parameters({{#allParams}}{{>queryParam}}{{>pathParam}}{{>bodyParam}}{{>formParam}}{{#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}} - - {{#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}}val {{paramName}} = fileParams("{{paramName}}"){{/isFile}} + {{^isFile}}{{#isPathParam}} + val {{paramName}} = params.getOrElse("{{paramName}}", halt(400)){{/isPathParam}} + {{>queryParamOperation}}{{>headerParamOperation}}{{>formParamMustache}}{{>bodyParam}} {{/isFile}} println("{{paramName}}: " + {{paramName}}) {{/allParams}} diff --git a/modules/swagger-codegen/src/main/resources/scalatra/bodyParam.mustache b/modules/swagger-codegen/src/main/resources/scalatra/bodyParam.mustache new file mode 100644 index 0000000000..07a90aa23c --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/bodyParam.mustache @@ -0,0 +1 @@ +{{#isBodyParam}}bodyParam[{{dataType}}]("{{paramName}}").description(""){{^required}}.optional{{/required}}{{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/scalatra/bodyParamOperation.mustache b/modules/swagger-codegen/src/main/resources/scalatra/bodyParamOperation.mustache new file mode 100644 index 0000000000..cfb2bf49d2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/bodyParamOperation.mustache @@ -0,0 +1,3 @@ + {{#isBodyParam}} + val {{paramName}} = parsedBody.extract[{{dataType}}] + {{/isBodyParam}} diff --git a/modules/swagger-codegen/src/main/resources/scalatra/formParam.mustache b/modules/swagger-codegen/src/main/resources/scalatra/formParam.mustache new file mode 100644 index 0000000000..1afcf12ccc --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/formParam.mustache @@ -0,0 +1 @@ +{{#isFormParam}}formParam[{{dataType}}]("{{paramName}}").description(""){{^required}}.optional{{/required}}{{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}}{{/isFormParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/scalatra/formParamMustache.mustache b/modules/swagger-codegen/src/main/resources/scalatra/formParamMustache.mustache new file mode 100644 index 0000000000..29c571ee2e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/formParamMustache.mustache @@ -0,0 +1,3 @@ + {{#isFormParam}} + val {{paramName}} = params.getAs[{{dataType}}]("{{paramName}}") + {{/isFormParam}} diff --git a/modules/swagger-codegen/src/main/resources/scalatra/headerParam.mustache b/modules/swagger-codegen/src/main/resources/scalatra/headerParam.mustache new file mode 100644 index 0000000000..798bb0fe6d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/headerParam.mustache @@ -0,0 +1 @@ +{{#isHeaderParam}}headerParam[{{dataType}}]("{{paramName}}").description(""){{^required}}.optional{{/required}}{{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}}{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/scalatra/headerParamOperation.mustache b/modules/swagger-codegen/src/main/resources/scalatra/headerParamOperation.mustache new file mode 100644 index 0000000000..7f8f528639 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/headerParamOperation.mustache @@ -0,0 +1,3 @@ + {{#isHeaderParam}} + val {{paramName}} = request.getHeader("{{paramName}}") + {{/isHeaderParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/scalatra/pathParam.mustache b/modules/swagger-codegen/src/main/resources/scalatra/pathParam.mustache new file mode 100644 index 0000000000..ae72aa8ec7 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/pathParam.mustache @@ -0,0 +1 @@ +{{#isPathParam}}pathParam[{{dataType}}]("{{paramName}}").description(""){{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/scalatra/queryParam.mustache b/modules/swagger-codegen/src/main/resources/scalatra/queryParam.mustache new file mode 100644 index 0000000000..79af702d0f --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/queryParam.mustache @@ -0,0 +1 @@ +{{#isQueryParam}}queryParam[{{dataType}}]("{{paramName}}").description(""){{^required}}.optional{{/required}}{{#defaultValue}}.defaultValue({{{defaultValue}}}){{/defaultValue}}{{/isQueryParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/scalatra/queryParamOperation.mustache b/modules/swagger-codegen/src/main/resources/scalatra/queryParamOperation.mustache new file mode 100644 index 0000000000..832bbed203 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/scalatra/queryParamOperation.mustache @@ -0,0 +1,13 @@ + {{#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}} \ No newline at end of file diff --git a/samples/server/petstore/scalatra/README.md b/samples/server/petstore/scalatra/README.md index f8a560b776..3ffa01fb25 100644 --- a/samples/server/petstore/scalatra/README.md +++ b/samples/server/petstore/scalatra/README.md @@ -1,10 +1,10 @@ # Swagger generated server ## Overview -This server was generated by the [swagger-codegen](https://github.com/wordnik/swagger-codegen) project. By using the -[swagger-spec](https://github.com/wordnik/swagger-core/wiki) from a remote server, you can easily generate a server stub. This +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. This example uses the [scalatra](http://scalatra.org/) framework. To see how to make this your own, look here: -[README](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/scalatra) \ No newline at end of file +[README](https://github.com/swagger-api/swagger-codegen/tree/master/samples/server-generator/scalatra) \ No newline at end of file diff --git a/samples/server/petstore/scalatra/build.sbt b/samples/server/petstore/scalatra/build.sbt index eaa098f07f..00575312d8 100644 --- a/samples/server/petstore/scalatra/build.sbt +++ b/samples/server/petstore/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._ @@ -10,9 +8,9 @@ assemblySettings scalariformSettings -organization := "com.wordnik" +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/samples/server/petstore/scalatra/sbt b/samples/server/petstore/scalatra/sbt old mode 100644 new mode 100755 diff --git a/samples/server/petstore/scalatra/src/main/scala/JettyMain.scala b/samples/server/petstore/scalatra/src/main/scala/JettyMain.scala index 69ca43c0e1..e25f16ba39 100644 --- a/samples/server/petstore/scalatra/src/main/scala/JettyMain.scala +++ b/samples/server/petstore/scalatra/src/main/scala/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/samples/server/petstore/scalatra/src/main/scala/ScalatraBootstrap.scala b/samples/server/petstore/scalatra/src/main/scala/ScalatraBootstrap.scala index a8a16d0b1f..1129a77d3c 100644 --- a/samples/server/petstore/scalatra/src/main/scala/ScalatraBootstrap.scala +++ b/samples/server/petstore/scalatra/src/main/scala/ScalatraBootstrap.scala @@ -1,4 +1,8 @@ - +import com.wordnik.client.api._ +import akka.actor.ActorSystem +import io.swagger.app.{ResourcesApp, SwaggerApp} +import javax.servlet.ServletContext +import org.scalatra.LifeCycle class ScalatraBootstrap extends LifeCycle { implicit val swagger = new SwaggerApp @@ -6,11 +10,11 @@ class ScalatraBootstrap extends LifeCycle { override def init(context: ServletContext) { implicit val system = ActorSystem("appActorSystem") try { - context mount(new UserApi, "/User/*") - context mount(new PetApi, "/Pet/*") - context mount(new StoreApi, "/Store/*") - - context mount(new ResourcesApp, "/api-docs/*") + context mount (new UserApi, "/User/*") + context mount (new PetApi, "/Pet/*") + context mount (new StoreApi, "/Store/*") + + context mount (new ResourcesApp, "/api-docs/*") } catch { case e: Throwable => e.printStackTrace() } diff --git a/samples/server/petstore/scalatra/src/main/scala/ServletApp.scala b/samples/server/petstore/scalatra/src/main/scala/ServletApp.scala index 212fbbb94b..6631eb98cc 100644 --- a/samples/server/petstore/scalatra/src/main/scala/ServletApp.scala +++ b/samples/server/petstore/scalatra/src/main/scala/ServletApp.scala @@ -1,4 +1,11 @@ -package com.wordnik.swagger.app +package io.swagger.app + +import _root_.akka.actor.ActorSystem + +import org.scalatra.swagger.{ ApiInfo, SwaggerWithAuth, Swagger } +import org.scalatra.swagger.{JacksonSwaggerBase, Swagger} +import org.scalatra.ScalatraServlet +import org.json4s.{DefaultFormats, Formats} class ResourcesApp(implicit protected val system: ActorSystem, val swagger: SwaggerApp) extends ScalatraServlet with JacksonSwaggerBase { @@ -6,17 +13,16 @@ class ResourcesApp(implicit protected val system: ActorSystem, val swagger: Swag 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) } } @@ -25,7 +31,7 @@ class SwaggerApp extends Swagger(apiInfo = ApiSwagger.apiInfo, apiVersion = "1.0 object ApiSwagger { val apiInfo = ApiInfo( """Swagger Petstore""", - """This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://webchat.freenode.net/?channels=swagger). For this sample, you can use the api key `special-key` to test the authorization filters""", + """This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters""", """""", """apiteam@swagger.io""", """Apache 2.0""", diff --git a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/PetApi.scala b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/PetApi.scala index b9c9b5bb23..7e0a438db1 100644 --- a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/PetApi.scala +++ b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/PetApi.scala @@ -1,7 +1,23 @@ -package com.wordnik.client.apiass PetApi(implicit val swagger: Swagger) extends ScalatraServlet -with FileUploadSupport -with JacksonJsonSupport -with SwaggerSupport { +package com.wordnik.client.api + +import com.wordnik.client.model.Pet +import java.io.File + +import java.io.File + +import org.scalatra.{ TypedParamSupport, ScalatraServlet } +import org.scalatra.swagger._ +import org.json4s._ +import org.json4s.JsonDSL._ +import org.scalatra.json.{ JValueResult, JacksonJsonSupport } +import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintExceededException} + +import scala.collection.JavaConverters._ + +class PetApi (implicit val swagger: Swagger) extends ScalatraServlet + with FileUploadSupport + with JacksonJsonSupport + with SwaggerSupport { protected implicit val jsonFormats: Formats = DefaultFormats protected val applicationDescription: String = "PetApi" @@ -11,268 +27,221 @@ with SwaggerSupport { contentType = formats("json") response.headers += ("Access-Control-Allow-Origin" -> "*") } - + val updatePetOperation = (apiOperation[Unit]("updatePet") - summary "Update an existing pet" - parameters ( - - - bodyParam[Pet]("body").description("").optional - - - ) - ) - - put("/pet", operation(updatePetOperation)) { - - - val body = parsedBody.extract[Pet] - + summary "Update an existing pet" + parameters(bodyParam[Pet]("body").description("").optional) + ) + put("/pet",operation(updatePetOperation)) { + + + + +bodyParam[Pet]("body").description("").optional + println("body: " + body) - + } + val addPetOperation = (apiOperation[Unit]("addPet") - summary "Add a new pet to the store" - parameters ( - - - bodyParam[Pet]("body").description("").optional - - - ) - ) - - post("/pet", operation(addPetOperation)) { - - - val body = parsedBody.extract[Pet] - + summary "Add a new pet to the store" + parameters(bodyParam[Pet]("body").description("").optional) + ) + post("/pet",operation(addPetOperation)) { + + + + +bodyParam[Pet]("body").description("").optional + println("body: " + body) - + } + val findPetsByStatusOperation = (apiOperation[List[Pet]]("findPetsByStatus") - summary "Finds Pets by status" - parameters ( - queryParam[List[String]]("status").description("").optional + summary "Finds Pets by status" + parameters(queryParam[List[String]]("status").description("").optional.defaultValue(available)) + ) - - ) - ) - - get("/pet/findByStatus", operation(findPetsByStatusOperation)) { - - - val statusString = params.getAs[String]("status") - val status = if ("multi".equals("default")) { - statusString match { - case Some(str) => str.split(",") - case None => List() + get("/pet/findByStatus",operation(findPetsByStatusOperation)) { + + + + + val statusString = params.getAs[String]("status") + val status = if("multi".equals("default")) { + statusString match { + case Some(str) => str.split(",") + case None => List() + } } - } - else - List() - - - - - - - - - - + else + List() + + + + println("status: " + status) - + } + val findPetsByTagsOperation = (apiOperation[List[Pet]]("findPetsByTags") - summary "Finds Pets by tags" - parameters ( - queryParam[List[String]]("tags").description("").optional + summary "Finds Pets by tags" + parameters(queryParam[List[String]]("tags").description("").optional) + ) - - ) - ) - - get("/pet/findByTags", operation(findPetsByTagsOperation)) { - - - val tagsString = params.getAs[String]("tags") - val tags = if ("multi".equals("default")) { - tagsString match { - case Some(str) => str.split(",") - case None => List() + get("/pet/findByTags",operation(findPetsByTagsOperation)) { + + + + + val tagsString = params.getAs[String]("tags") + val tags = if("multi".equals("default")) { + tagsString match { + case Some(str) => str.split(",") + case None => List() + } } - } - else - List() - - - - - - - - - - + else + List() + + + + println("tags: " + tags) - + } + val getPetByIdOperation = (apiOperation[Pet]("getPetById") - summary "Find pet by ID" - parameters ( - - pathParam[Long]("petId").description("") - - - ) - ) - - get("/pet/{petId}", operation(getPetByIdOperation)) { - - - val petId = params.getOrElse("petId", halt(400)) - - - - - - - - + summary "Find pet by ID" + parameters(pathParam[Long]("petId").description("")) + ) + get("/pet/{petId}",operation(getPetByIdOperation)) { + + + + val petId = params.getOrElse("petId", halt(400)) + + println("petId: " + petId) - + } + val updatePetWithFormOperation = (apiOperation[Unit]("updatePetWithForm") - summary "Updates a pet in the store with form data" - parameters( - - pathParam[String]("petId").description("") - - - , - - - formParam[String]("name").description("").optional - - , - - - formParam[String]("status").description("").optional - - ) - ) - - post("/pet/{petId}", operation(updatePetWithFormOperation)) { - - - val petId = params.getOrElse("petId", halt(400)) - - - - - - - - + summary "Updates a pet in the store with form data" + parameters(pathParam[String]("petId").description(""), + formParam[String]("name").description("").optional, + formParam[String]("status").description("").optional) + ) + post("/pet/{petId}",operation(updatePetWithFormOperation)) { + + + + val petId = params.getOrElse("petId", halt(400)) + + println("petId: " + petId) + + + + + val name = params.getAs[String]("name") + - - - - - - - - - - val name = params.getAs[String]("name") - - - - + println("name: " + name) + + + + + val status = params.getAs[String]("status") + - - - - - - - - - - val status = params.getAs[String]("status") - - - - + println("status: " + status) - + } + val deletePetOperation = (apiOperation[Unit]("deletePet") - summary "Deletes a pet" - parameters( - - headerParam[String]("api_key").description("").optional - - - , - - pathParam[Long]("petId").description("") - - ) - ) - - delete("/pet/{petId}", operation(deletePetOperation)) { - - - val api_key = request.getHeader("api_key") - - - - - - - println("api_key: " + api_key) - - - - - val petId = params.getOrElse("petId", halt(400)) - - - - - - - - + summary "Deletes a pet" + parameters(pathParam[Long]("petId").description(""), + ) + ) + delete("/pet/{petId}",operation(deletePetOperation)) { + + + + val petId = params.getOrElse("petId", halt(400)) + + println("petId: " + petId) + + + + + val apiKey = request.getHeader("apiKey") + + + println("apiKey: " + apiKey) + + } + + + + val uploadFileOperation = (apiOperation[Unit]("uploadFile") + summary "uploads an image" + parameters(pathParam[Long]("petId").description(""), + formParam[String]("additionalMetadata").description("").optional, + formParam[File]("file").description("").optional) + ) + + post("/pet/{petId}/uploadImage",operation(uploadFileOperation)) { + + + + val petId = params.getOrElse("petId", halt(400)) + + + + println("petId: " + petId) + + + + + val additionalMetadata = params.getAs[String]("additionalMetadata") + + + + println("additionalMetadata: " + additionalMetadata) + + val file = fileParams("file") + + println("file: " + file) + } } \ No newline at end of file diff --git a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/StoreApi.scala b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/StoreApi.scala index 3e31c93743..27fbc08e2c 100644 --- a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/StoreApi.scala +++ b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/StoreApi.scala @@ -1,99 +1,96 @@ package com.wordnik.client.api -class StoreApi(implicit val swagger: Swagger) extends ScalatraServlet -with FileUploadSupport -with JacksonJsonSupport -with SwaggerSupport { +import com.wordnik.client.model.Order + +import java.io.File + +import org.scalatra.{ TypedParamSupport, ScalatraServlet } +import org.scalatra.swagger._ +import org.json4s._ +import org.json4s.JsonDSL._ +import org.scalatra.json.{ JValueResult, JacksonJsonSupport } +import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintExceededException} + +import scala.collection.JavaConverters._ + +class StoreApi (implicit val swagger: Swagger) extends ScalatraServlet + with FileUploadSupport + with JacksonJsonSupport + with SwaggerSupport { + protected implicit val jsonFormats: Formats = DefaultFormats + + protected val applicationDescription: String = "StoreApi" override protected val applicationName: Option[String] = Some("Store") - val getInventoryOperation = (apiOperation[Map[String, Int]]("getInventory") - summary "Returns pet inventories by status" - parameters( - ) - ) - val placeOrderOperation = (apiOperation[Order]("placeOrder") - summary "Place an order for a pet" - parameters ( - - - bodyParam[Order]("body").description("").optional - - - ) - ) before() { contentType = formats("json") response.headers += ("Access-Control-Allow-Origin" -> "*") } - val getOrderByIdOperation = (apiOperation[Order]("getOrderById") - summary "Find purchase order by ID" - parameters ( + - pathParam[String]("orderId").description("") - - - ) - ) - - get("/store/inventory", operation(getInventoryOperation)) { + val getInventoryOperation = (apiOperation[Map[String, Int]]("getInventory") + summary "Returns pet inventories by status" + parameters() + ) + get("/store/inventory",operation(getInventoryOperation)) { + } - val deleteOrderOperation = (apiOperation[Unit]("deleteOrder") - summary "Delete purchase order by ID" - parameters ( - pathParam[String]("orderId").description("") - - - ) - ) - - post("/store/order", operation(placeOrderOperation)) { - - - val body = parsedBody.extract[Order] + + val placeOrderOperation = (apiOperation[Order]("placeOrder") + summary "Place an order for a pet" + parameters(bodyParam[Order]("body").description("").optional) + ) + post("/store/order",operation(placeOrderOperation)) { + + + + +bodyParam[Order]("body").description("").optional + println("body: " + body) - + } - protected implicit val jsonFormats: Formats = DefaultFormats - - get("/store/order/{orderId}", operation(getOrderByIdOperation)) { - - - val orderId = params.getOrElse("orderId", halt(400)) - - - - - - + + val getOrderByIdOperation = (apiOperation[Order]("getOrderById") + summary "Find purchase order by ID" + parameters(pathParam[String]("orderId").description("")) + ) + get("/store/order/{orderId}",operation(getOrderByIdOperation)) { + + + + val orderId = params.getOrElse("orderId", halt(400)) + + println("orderId: " + orderId) - + } - protected val applicationDescription: String = "StoreApi" - - delete("/store/order/{orderId}", operation(deleteOrderOperation)) { - - - val orderId = params.getOrElse("orderId", halt(400)) - - - - - - + + val deleteOrderOperation = (apiOperation[Unit]("deleteOrder") + summary "Delete purchase order by ID" + parameters(pathParam[String]("orderId").description("")) + ) + delete("/store/order/{orderId}",operation(deleteOrderOperation)) { + + + + val orderId = params.getOrElse("orderId", halt(400)) + + println("orderId: " + orderId) - + } } \ No newline at end of file diff --git a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/UserApi.scala b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/UserApi.scala index ab493b4bfa..c63151a8d3 100644 --- a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/UserApi.scala +++ b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/api/UserApi.scala @@ -1,7 +1,22 @@ -package com.wordnik.client.apiass UserApi(implicit val swagger: Swagger) extends ScalatraServlet -with FileUploadSupport -with JacksonJsonSupport -with SwaggerSupport { +package com.wordnik.client.api + +import com.wordnik.client.model.User + +import java.io.File + +import org.scalatra.{ TypedParamSupport, ScalatraServlet } +import org.scalatra.swagger._ +import org.json4s._ +import org.json4s.JsonDSL._ +import org.scalatra.json.{ JValueResult, JacksonJsonSupport } +import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintExceededException} + +import scala.collection.JavaConverters._ + +class UserApi (implicit val swagger: Swagger) extends ScalatraServlet + with FileUploadSupport + with JacksonJsonSupport + with SwaggerSupport { protected implicit val jsonFormats: Formats = DefaultFormats protected val applicationDescription: String = "UserApi" @@ -11,238 +26,166 @@ with SwaggerSupport { contentType = formats("json") response.headers += ("Access-Control-Allow-Origin" -> "*") } - + val createUserOperation = (apiOperation[Unit]("createUser") - summary "Create user" - parameters ( - - - bodyParam[User]("body").description("").optional - - - ) - ) - - post("/user", operation(createUserOperation)) { - - - val body = parsedBody.extract[User] - + summary "Create user" + parameters(bodyParam[User]("body").description("").optional) + ) + post("/user",operation(createUserOperation)) { + + + + +bodyParam[User]("body").description("").optional + println("body: " + body) - + } + val createUsersWithArrayInputOperation = (apiOperation[Unit]("createUsersWithArrayInput") - summary "Creates list of users with given input array" - parameters ( - - - bodyParam[List[User]]("body").description("").optional - - - ) - ) - - post("/user/createWithArray", operation(createUsersWithArrayInputOperation)) { - - - val body = parsedBody.extract[List[User]] - + summary "Creates list of users with given input array" + parameters(bodyParam[List[User]]("body").description("").optional) + ) + post("/user/createWithArray",operation(createUsersWithArrayInputOperation)) { + + + + +bodyParam[List[User]]("body").description("").optional + println("body: " + body) - + } + val createUsersWithListInputOperation = (apiOperation[Unit]("createUsersWithListInput") - summary "Creates list of users with given input array" - parameters ( - - - bodyParam[List[User]]("body").description("").optional - - - ) - ) - - post("/user/createWithList", operation(createUsersWithListInputOperation)) { - - - val body = parsedBody.extract[List[User]] - + summary "Creates list of users with given input array" + parameters(bodyParam[List[User]]("body").description("").optional) + ) + post("/user/createWithList",operation(createUsersWithListInputOperation)) { + + + + +bodyParam[List[User]]("body").description("").optional + println("body: " + body) - + } + val loginUserOperation = (apiOperation[String]("loginUser") - summary "Logs user into the system" - parameters( - queryParam[String]("username").description("").optional - - - , - queryParam[String]("password").description("").optional - - ) - ) - - get("/user/login", operation(loginUserOperation)) { - - - val username = params.getAs[String]("username") - - - - - - - + summary "Logs user into the system" + parameters(queryParam[String]("username").description("").optional, + queryParam[String]("password").description("").optional) + ) + get("/user/login",operation(loginUserOperation)) { + + + + + + val username = params.getAs[String]("username") + + println("username: " + username) + + + + + + val password = params.getAs[String]("password") + - - - - - - - val password = params.getAs[String]("password") - - - - - - - - - + println("password: " + password) - + } + val logoutUserOperation = (apiOperation[Unit]("logoutUser") - summary "Logs out current logged in user session" - parameters( - ) - ) - - get("/user/logout", operation(logoutUserOperation)) { + summary "Logs out current logged in user session" + parameters() + ) + get("/user/logout",operation(logoutUserOperation)) { + } + val getUserByNameOperation = (apiOperation[User]("getUserByName") - summary "Get user by user name" - parameters ( - - pathParam[String]("username").description("") - - - ) - ) - - get("/user/{username}", operation(getUserByNameOperation)) { - - - val username = params.getOrElse("username", halt(400)) - - - - - - - - + summary "Get user by user name" + parameters(pathParam[String]("username").description("")) + ) + get("/user/{username}",operation(getUserByNameOperation)) { + + + + val username = params.getOrElse("username", halt(400)) + + println("username: " + username) - + } + val updateUserOperation = (apiOperation[Unit]("updateUser") - summary "Updated user" - parameters( - - pathParam[String]("username").description("") - - - , - - - bodyParam[User]("body").description("").optional - - ) - ) - - put("/user/{username}", operation(updateUserOperation)) { - - - val username = params.getOrElse("username", halt(400)) - - - - - - - - + summary "Updated user" + parameters(pathParam[String]("username").description(""), + bodyParam[User]("body").description("").optional) + ) + put("/user/{username}",operation(updateUserOperation)) { + + + + val username = params.getOrElse("username", halt(400)) + + println("username: " + username) - - - - - - - - - - - - - val body = parsedBody.extract[User] - - + + + + +bodyParam[User]("body").description("").optional + println("body: " + body) - + } + val deleteUserOperation = (apiOperation[Unit]("deleteUser") - summary "Delete user" - parameters ( - - pathParam[String]("username").description("") - - - ) - ) - - delete("/user/{username}", operation(deleteUserOperation)) { - - - val username = params.getOrElse("username", halt(400)) - - - - - - - - + summary "Delete user" + parameters(pathParam[String]("username").description("")) + ) + delete("/user/{username}",operation(deleteUserOperation)) { + + + + val username = params.getOrElse("username", halt(400)) + + println("username: " + username) - + } } \ No newline at end of file diff --git a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Category.scala b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Category.scala index fccd9bb21f..d4ee7a692e 100644 --- a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Category.scala +++ b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Category.scala @@ -1,7 +1,8 @@ package com.wordnik.client.model -case class Category( - id: Long, - name: String - ) + +case class Category ( + id: Long, + name: String +) diff --git a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Order.scala b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Order.scala index 39a4cc297c..918cf132d2 100644 --- a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Order.scala +++ b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Order.scala @@ -3,11 +3,11 @@ package com.wordnik.client.model import java.util.Date -case class Order( - id: Long, - petId: Long, - quantity: Int, - shipDate: Date, - status: String, - complete: Boolean - ) +case class Order ( + id: Long, + petId: Long, + quantity: Int, + shipDate: Date, + status: String, + complete: Boolean +) diff --git a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Pet.scala b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Pet.scala index 47ecf5f29c..cea17dedae 100644 --- a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Pet.scala +++ b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Pet.scala @@ -1,11 +1,14 @@ package com.wordnik.client.model +import com.wordnik.client.model.Category +import com.wordnik.client.model.Tag -case class Pet( - id: Long, - category: Category, - name: String, - photoUrls: List[String], - tags: List[Tag], - status: String - ) + +case class Pet ( + id: Long, + category: Category, + name: String, + photoUrls: List[String], + tags: List[Tag], + status: String +) diff --git a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Tag.scala b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Tag.scala index c38e6c1561..bd28dd4d44 100644 --- a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Tag.scala +++ b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/Tag.scala @@ -1,7 +1,8 @@ package com.wordnik.client.model -case class Tag( - id: Long, - name: String - ) + +case class Tag ( + id: Long, + name: String +) diff --git a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/User.scala b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/User.scala index 506e145349..acadf78f7a 100644 --- a/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/User.scala +++ b/samples/server/petstore/scalatra/src/main/scala/com/wordnik/client/model/User.scala @@ -1,13 +1,14 @@ package com.wordnik.client.model -case class User( - id: Long, - username: String, - firstName: String, - lastName: String, - email: String, - password: String, - phone: String, - userStatus: Int - ) + +case class User ( + id: Long, + username: String, + firstName: String, + lastName: String, + email: String, + password: String, + phone: String, + userStatus: Int +) diff --git a/samples/server/petstore/scalatra/src/main/webapp/WEB-INF/web.xml b/samples/server/petstore/scalatra/src/main/webapp/WEB-INF/web.xml index a6e529e4ae..2a08440458 100644 --- a/samples/server/petstore/scalatra/src/main/webapp/WEB-INF/web.xml +++ b/samples/server/petstore/scalatra/src/main/webapp/WEB-INF/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/* +