mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 10:58:55 +00:00
updated files
This commit is contained in:
parent
cdc1bbc133
commit
21265454ab
@ -43,7 +43,8 @@ object ScalatraServerGenerator extends BasicScalaGenerator {
|
||||
override def supportingFiles = List(
|
||||
("README.mustache", outputFolder, "README.md"),
|
||||
("build.sbt", outputFolder, "build.sbt"),
|
||||
("JsonUtil.scala", destinationDir, "JsonUtil.scala"),
|
||||
("web.xml", outputFolder + "/src/main/webapp/WEB-INF", "web.xml"),
|
||||
("Bootstrap.mustache", destinationDir, "ScalatraBootstrap.scala"),
|
||||
("ServletApp.mustache", destinationDir, "ServletApp.scala"),
|
||||
("project/build.properties", outputFolder, "project/build.properties"),
|
||||
("project/plugins.sbt", outputFolder, "project/plugins.sbt"))
|
||||
|
@ -1,3 +1,5 @@
|
||||
import com.github.siasia.PluginKeys._
|
||||
|
||||
organization := "com.wordnik"
|
||||
|
||||
name := "swagger-scalatra-server"
|
||||
@ -6,28 +8,23 @@ version := "0.1.0-SNAPSHOT"
|
||||
|
||||
scalaVersion := "2.9.2"
|
||||
|
||||
scalaSource in Compile <<= baseDirectory.identity
|
||||
|
||||
seq(webSettings :_*)
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"com.fasterxml.jackson.module" % "jackson-module-scala" % "2.0.0" % "compile;container;test;runtime",
|
||||
"org.scalatra" % "scalatra" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-scalate" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-specs2" % "2.2.0-SNAPSHOT" % "test",
|
||||
"org.scalatra" % "scalatra-swagger" % "2.2.0-SNAPSHOT",
|
||||
"com.wordnik" % "swagger-core_2.9.1" % "1.1.0",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.0" % "runtime",
|
||||
"org.eclipse.jetty" % "jetty-server" % "8.1.3.v20120416" % "compile;container;test;runtime",
|
||||
"org.eclipse.jetty" % "jetty-servlet" % "8.1.3.v20120416" % "compile;container;test;runtime",
|
||||
"org.eclipse.jetty" % "jetty-webapp" % "8.1.3.v20120416" % "compile;container;test;runtime",
|
||||
"javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided;container;test;runtime"
|
||||
)
|
||||
"org.scalatra" % "scalatra" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-scalate" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-specs2" % "2.2.0-SNAPSHOT" % "test",
|
||||
"org.scalatra" % "scalatra-swagger" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-json" % "2.2.0-SNAPSHOT",
|
||||
"org.json4s" %% "json4s-jackson" % "3.0.0-SNAPSHOT",
|
||||
"com.wordnik" % "swagger-core_2.9.1" % "1.1-SNAPSHOT",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
|
||||
"org.eclipse.jetty" % "jetty-webapp" % "8.1.5.v20120716" % "container",
|
||||
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar")))
|
||||
|
||||
resolvers += Resolver.url("local-ivy", new URL("file://" + Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns)
|
||||
|
||||
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
|
||||
|
||||
ivyXML := <dependencies>
|
||||
<exclude org="org.eclipse.jetty.orbit" />
|
||||
</dependencies>
|
||||
apps in container.Configuration <<= (deployment in Compile) map (d => Seq("/api" -> d))
|
||||
|
||||
ivyXML := <dependencies><exclude module="slf4j-log4j12"/></dependencies>
|
||||
|
@ -1 +1 @@
|
||||
sbt.version=0.11.3
|
||||
sbt.version=0.12.0
|
||||
|
@ -1 +1,7 @@
|
||||
libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % (v+"-0.2.11.1"))
|
||||
libraryDependencies <+= sbtVersion(v => v match {
|
||||
case "0.11.0" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.0-0.2.8"
|
||||
case "0.11.1" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10"
|
||||
case "0.11.2" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.2-0.2.11"
|
||||
case "0.11.3" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.3-0.2.11.1"
|
||||
case x if (x.startsWith("0.12")) => "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1"
|
||||
})
|
@ -1,12 +0,0 @@
|
||||
package json
|
||||
|
||||
import com.fasterxml.jackson.module.scala.DefaultScalaModule
|
||||
import com.fasterxml.jackson.core.JsonGenerator.Feature
|
||||
import com.fasterxml.jackson.databind._
|
||||
|
||||
object JsonUtil {
|
||||
val mapper = new ObjectMapper()
|
||||
mapper.registerModule(new DefaultScalaModule())
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
import apis._
|
||||
import com.wordnik.swagger.app.{ResourcesApp, SwaggerApp}
|
||||
import javax.servlet.ServletContext
|
||||
import org.scalatra.LifeCycle
|
||||
|
||||
class ScalatraBootstrap extends LifeCycle {
|
||||
implicit val swagger = new SwaggerApp
|
||||
|
||||
override def init(context: ServletContext) {
|
||||
try {
|
||||
context mount (new StoreApi, "/store/*")
|
||||
context mount (new PetApi, "/pet/*")
|
||||
context mount (new UserApi, "/user/*")
|
||||
context mount (new ResourcesApp, "/*")
|
||||
} catch {
|
||||
case e: Throwable => e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +1,30 @@
|
||||
package com.wordnik.swagger.sample
|
||||
|
||||
import apis._
|
||||
package com.wordnik.swagger.app
|
||||
|
||||
import com.wordnik.swagger.core.SwaggerSpec
|
||||
import org.scalatra.swagger.{JacksonSwaggerBase, Swagger}
|
||||
|
||||
import org.scalatra.{ ScalatraServlet }
|
||||
import org.scalatra.swagger.{ Swagger, SwaggerBase }
|
||||
import org.scalatra.ScalatraServlet
|
||||
import org.json4s.{DefaultFormats, Formats}
|
||||
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector
|
||||
import org.eclipse.jetty.server.Server
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection
|
||||
import org.eclipse.jetty.servlet.{ ServletContextHandler, ServletHolder }
|
||||
class ResourcesApp(implicit val swagger: Swagger) extends ScalatraServlet with JacksonSwaggerBase {
|
||||
protected implicit val jsonFormats: Formats = DefaultFormats
|
||||
|
||||
object ServletApp extends App {
|
||||
val server = new Server
|
||||
implicit val swagger = new SwaggerApp
|
||||
|
||||
server setGracefulShutdown 5000
|
||||
server setSendServerVersion false
|
||||
server setSendDateHeader true
|
||||
server setStopAtShutdown true
|
||||
|
||||
val connector = new SelectChannelConnector
|
||||
connector setPort 8002
|
||||
connector setMaxIdleTime 90000
|
||||
|
||||
server addConnector connector
|
||||
|
||||
val apiServlets = new ServletContextHandler(ServletContextHandler.SESSIONS)
|
||||
apiServlets setContextPath "/api"
|
||||
|
||||
val handlers = new ContextHandlerCollection
|
||||
handlers addHandler apiServlets
|
||||
|
||||
val petServlet = new PetApi
|
||||
swagger register ("pet", "/pet", "", petServlet)
|
||||
apiServlets addServlet (new ServletHolder(petServlet), "/pet/*")
|
||||
apiServlets addServlet (new ServletHolder(new ResourcesApp), "/*")
|
||||
|
||||
val storeServlet = new StoreApi
|
||||
swagger register ("store", "/store", "", storeServlet)
|
||||
apiServlets addServlet (new ServletHolder(storeServlet), "/pet/*")
|
||||
apiServlets addServlet (new ServletHolder(new ResourcesApp), "/*")
|
||||
|
||||
val userServlet = new UserApi
|
||||
swagger register ("user", "/user", "", userServlet)
|
||||
apiServlets addServlet (new ServletHolder(userServlet), "/pet/*")
|
||||
apiServlets addServlet (new ServletHolder(new ResourcesApp), "/*")
|
||||
|
||||
server setHandler handlers
|
||||
server start ()
|
||||
}
|
||||
|
||||
class ResourcesApp(implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase {
|
||||
before() {
|
||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||
}
|
||||
|
||||
protected def buildFullUrl(path: String) = if (path.startsWith("http")) path else {
|
||||
"http://%s:%s%s%s".format(
|
||||
request.getServerName,
|
||||
request.getServerPort,
|
||||
request.getContextPath,
|
||||
path)
|
||||
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(SwaggerSpec.version, "1")
|
||||
|
||||
|
@ -1,14 +1,34 @@
|
||||
package apis
|
||||
|
||||
import com.wordnik.swagger.core.ApiPropertiesReader
|
||||
import com.wordnik.client.model.Pet
|
||||
import org.scalatra.ScalatraServlet
|
||||
import com.wordnik.swagger.core.ApiPropertiesReader
|
||||
import org.scalatra.{ TypedParamSupport, ScalatraServlet }
|
||||
import org.scalatra.swagger._
|
||||
import org.scalatra.json._
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import org.json4s.{ DefaultFormats, Formats }
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
class PetApi (implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport {
|
||||
protected def buildFullUrl(path: String) = "http://petstore.swagger.wordnik.com/api/%s" format path
|
||||
class PetApi (implicit val swagger: Swagger) extends ScalatraServlet with TypedParamSupport with JacksonJsonSupport with JValueResult with SwaggerSupport {
|
||||
protected implicit val jsonFormats: Formats = DefaultFormats
|
||||
|
||||
protected val applicationDescription: String = "PetApi"
|
||||
|
||||
def swaggerToModel(cls: Class[_]) = {
|
||||
val docObj = ApiPropertiesReader.read(cls)
|
||||
val name = docObj.getName
|
||||
val fields = for (field <- docObj.getFields.asScala.filter(d => d.paramType != null))
|
||||
yield (field.name -> ModelField(field.name, field.notes, DataType(field.paramType)))
|
||||
|
||||
Model(name, name, fields.toMap)
|
||||
}
|
||||
|
||||
before() {
|
||||
contentType = formats("json")
|
||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||
}
|
||||
|
||||
get("/:petId",
|
||||
summary("Find pet by ID"),
|
||||
|
@ -1,14 +1,34 @@
|
||||
package apis
|
||||
|
||||
import com.wordnik.swagger.core.ApiPropertiesReader
|
||||
import com.wordnik.client.model.Order
|
||||
import org.scalatra.ScalatraServlet
|
||||
import com.wordnik.swagger.core.ApiPropertiesReader
|
||||
import org.scalatra.{ TypedParamSupport, ScalatraServlet }
|
||||
import org.scalatra.swagger._
|
||||
import org.scalatra.json._
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import org.json4s.{ DefaultFormats, Formats }
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
class StoreApi (implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport {
|
||||
protected def buildFullUrl(path: String) = "http://petstore.swagger.wordnik.com/api/%s" format path
|
||||
class StoreApi (implicit val swagger: Swagger) extends ScalatraServlet with TypedParamSupport with JacksonJsonSupport with JValueResult with SwaggerSupport {
|
||||
protected implicit val jsonFormats: Formats = DefaultFormats
|
||||
|
||||
protected val applicationDescription: String = "StoreApi"
|
||||
|
||||
def swaggerToModel(cls: Class[_]) = {
|
||||
val docObj = ApiPropertiesReader.read(cls)
|
||||
val name = docObj.getName
|
||||
val fields = for (field <- docObj.getFields.asScala.filter(d => d.paramType != null))
|
||||
yield (field.name -> ModelField(field.name, field.notes, DataType(field.paramType)))
|
||||
|
||||
Model(name, name, fields.toMap)
|
||||
}
|
||||
|
||||
before() {
|
||||
contentType = formats("json")
|
||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||
}
|
||||
|
||||
get("/order/:orderId",
|
||||
summary("Find purchase order by ID"),
|
||||
|
@ -1,14 +1,34 @@
|
||||
package apis
|
||||
|
||||
import com.wordnik.swagger.core.ApiPropertiesReader
|
||||
import com.wordnik.client.model.User
|
||||
import org.scalatra.ScalatraServlet
|
||||
import com.wordnik.swagger.core.ApiPropertiesReader
|
||||
import org.scalatra.{ TypedParamSupport, ScalatraServlet }
|
||||
import org.scalatra.swagger._
|
||||
import org.scalatra.json._
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import org.json4s.{ DefaultFormats, Formats }
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
class UserApi (implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport {
|
||||
protected def buildFullUrl(path: String) = "http://petstore.swagger.wordnik.com/api/%s" format path
|
||||
class UserApi (implicit val swagger: Swagger) extends ScalatraServlet with TypedParamSupport with JacksonJsonSupport with JValueResult with SwaggerSupport {
|
||||
protected implicit val jsonFormats: Formats = DefaultFormats
|
||||
|
||||
protected val applicationDescription: String = "UserApi"
|
||||
|
||||
def swaggerToModel(cls: Class[_]) = {
|
||||
val docObj = ApiPropertiesReader.read(cls)
|
||||
val name = docObj.getName
|
||||
val fields = for (field <- docObj.getFields.asScala.filter(d => d.paramType != null))
|
||||
yield (field.name -> ModelField(field.name, field.notes, DataType(field.paramType)))
|
||||
|
||||
Model(name, name, fields.toMap)
|
||||
}
|
||||
|
||||
before() {
|
||||
contentType = formats("json")
|
||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||
}
|
||||
|
||||
post("/createWithArray",
|
||||
summary("Creates list of users with given input array"),
|
||||
|
@ -3,6 +3,6 @@ package com.wordnik.client.model
|
||||
import scala.reflect.BeanProperty
|
||||
|
||||
case class Category (
|
||||
var id: Long,
|
||||
var name: String)
|
||||
id: Long,
|
||||
name: String)
|
||||
|
||||
|
@ -4,10 +4,10 @@ import java.util.Date
|
||||
import scala.reflect.BeanProperty
|
||||
|
||||
case class Order (
|
||||
var id: Long,
|
||||
var petId: Long,
|
||||
id: Long,
|
||||
petId: Long,
|
||||
/* Order Status */
|
||||
var status: String,
|
||||
var quantity: Int,
|
||||
var shipDate: Date)
|
||||
status: String,
|
||||
quantity: Int,
|
||||
shipDate: Date)
|
||||
|
||||
|
@ -5,11 +5,11 @@ import com.wordnik.client.model.Tag
|
||||
import scala.reflect.BeanProperty
|
||||
|
||||
case class Pet (
|
||||
var id: Long,
|
||||
var tags: java.util.List[Tag],
|
||||
var category: Category,
|
||||
id: Long,
|
||||
tags: java.util.List[Tag],
|
||||
category: Category,
|
||||
/* pet status in the store */
|
||||
var status: String,
|
||||
var name: String,
|
||||
var photoUrls: java.util.List[String])
|
||||
status: String,
|
||||
name: String,
|
||||
photoUrls: java.util.List[String])
|
||||
|
||||
|
@ -3,6 +3,6 @@ package com.wordnik.client.model
|
||||
import scala.reflect.BeanProperty
|
||||
|
||||
case class Tag (
|
||||
var id: Long,
|
||||
var name: String)
|
||||
id: Long,
|
||||
name: String)
|
||||
|
||||
|
@ -3,13 +3,13 @@ package com.wordnik.client.model
|
||||
import scala.reflect.BeanProperty
|
||||
|
||||
case class User (
|
||||
var id: Long,
|
||||
var lastName: String,
|
||||
var username: String,
|
||||
var phone: String,
|
||||
var email: String,
|
||||
id: Long,
|
||||
lastName: String,
|
||||
username: String,
|
||||
phone: String,
|
||||
email: String,
|
||||
/* User Status */
|
||||
var userStatus: Int,
|
||||
var firstName: String,
|
||||
var password: String)
|
||||
userStatus: Int,
|
||||
firstName: String,
|
||||
password: String)
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||
version="3.0">
|
||||
<listener>
|
||||
<listener-class>org.scalatra.servlet.ScalatraListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>default</servlet-name>
|
||||
<url-pattern>/img/*</url-pattern>
|
||||
<url-pattern>/css/*</url-pattern>
|
||||
<url-pattern>/js/*</url-pattern>
|
||||
<url-pattern>/assets/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<context-param>
|
||||
<param-name>org.scalatra.LifeCycle</param-name>
|
||||
<param-value>com.wordnik.swagger.sample.Scalatra</param-value>
|
||||
</context-param>
|
||||
</web-app>
|
@ -0,0 +1,20 @@
|
||||
import {{apiPackage}}._
|
||||
import com.wordnik.swagger.app.{ResourcesApp, SwaggerApp}
|
||||
import javax.servlet.ServletContext
|
||||
import org.scalatra.LifeCycle
|
||||
|
||||
class ScalatraBootstrap extends LifeCycle {
|
||||
implicit val swagger = new SwaggerApp
|
||||
|
||||
override def init(context: ServletContext) {
|
||||
try {
|
||||
{{#apis}}
|
||||
context mount (new {{className}}, "/{{name}}/*")
|
||||
{{/apis}}
|
||||
|
||||
context mount (new ResourcesApp, "/*")
|
||||
} catch {
|
||||
case e: Throwable => e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +1,28 @@
|
||||
package com.wordnik.swagger.sample
|
||||
|
||||
import {{apiPackage}}._
|
||||
package com.wordnik.swagger.app
|
||||
|
||||
import com.wordnik.swagger.core.SwaggerSpec
|
||||
import org.scalatra.swagger.{JacksonSwaggerBase, Swagger}
|
||||
import org.scalatra.ScalatraServlet
|
||||
import org.json4s.{DefaultFormats, Formats}
|
||||
|
||||
import org.scalatra.{ ScalatraServlet }
|
||||
import org.scalatra.swagger.{ Swagger, SwaggerBase }
|
||||
class ResourcesApp(implicit val swagger: Swagger) extends ScalatraServlet with JacksonSwaggerBase {
|
||||
protected implicit val jsonFormats: Formats = DefaultFormats
|
||||
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector
|
||||
import org.eclipse.jetty.server.Server
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection
|
||||
import org.eclipse.jetty.servlet.{ ServletContextHandler, ServletHolder }
|
||||
|
||||
object ServletApp extends App {
|
||||
val server = new Server
|
||||
implicit val swagger = new SwaggerApp
|
||||
|
||||
server setGracefulShutdown 5000
|
||||
server setSendServerVersion false
|
||||
server setSendDateHeader true
|
||||
server setStopAtShutdown true
|
||||
|
||||
val connector = new SelectChannelConnector
|
||||
connector setPort 8002
|
||||
connector setMaxIdleTime 90000
|
||||
|
||||
server addConnector connector
|
||||
|
||||
val apiServlets = new ServletContextHandler(ServletContextHandler.SESSIONS)
|
||||
apiServlets setContextPath "/api"
|
||||
|
||||
val handlers = new ContextHandlerCollection
|
||||
handlers addHandler apiServlets
|
||||
|
||||
{{#apis}}
|
||||
val {{name}}Servlet = new {{className}}
|
||||
swagger register ("{{name}}", "/{{name}}", "{{{description}}}", {{name}}Servlet)
|
||||
apiServlets addServlet (new ServletHolder({{name}}Servlet), "/pet/*")
|
||||
apiServlets addServlet (new ServletHolder(new ResourcesApp), "/*")
|
||||
|
||||
{{/apis}}
|
||||
|
||||
server setHandler handlers
|
||||
server start ()
|
||||
}
|
||||
|
||||
class ResourcesApp(implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase {
|
||||
before() {
|
||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||
}
|
||||
|
||||
protected def buildFullUrl(path: String) = if (path.startsWith("http")) path else {
|
||||
"http://%s:%s%s%s".format(
|
||||
request.getServerName,
|
||||
request.getServerPort,
|
||||
request.getContextPath,
|
||||
path)
|
||||
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(SwaggerSpec.version, "1")
|
||||
class SwaggerApp extends Swagger(SwaggerSpec.version, "1")
|
||||
|
@ -1,15 +1,35 @@
|
||||
package {{package}}
|
||||
|
||||
import com.wordnik.swagger.core.ApiPropertiesReader
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
import org.scalatra.ScalatraServlet
|
||||
import com.wordnik.swagger.core.ApiPropertiesReader
|
||||
import org.scalatra.{ TypedParamSupport, ScalatraServlet }
|
||||
import org.scalatra.swagger._
|
||||
import org.scalatra.json._
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import org.json4s.{ DefaultFormats, Formats }
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
class {{className}} (implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport {
|
||||
protected def buildFullUrl(path: String) = "{{basePath}}/%s" format path
|
||||
class {{className}} (implicit val swagger: Swagger) extends ScalatraServlet with TypedParamSupport with JacksonJsonSupport with JValueResult with SwaggerSupport {
|
||||
protected implicit val jsonFormats: Formats = DefaultFormats
|
||||
|
||||
protected val applicationDescription: String = "{{className}}"
|
||||
|
||||
def swaggerToModel(cls: Class[_]) = {
|
||||
val docObj = ApiPropertiesReader.read(cls)
|
||||
val name = docObj.getName
|
||||
val fields = for (field <- docObj.getFields.asScala.filter(d => d.paramType != null))
|
||||
yield (field.name -> ModelField(field.name, field.notes, DataType(field.paramType)))
|
||||
|
||||
Model(name, name, fields.toMap)
|
||||
}
|
||||
|
||||
before() {
|
||||
contentType = formats("json")
|
||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||
}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import com.github.siasia.PluginKeys._
|
||||
|
||||
organization := "com.wordnik"
|
||||
|
||||
name := "swagger-scalatra-server"
|
||||
@ -6,28 +8,23 @@ version := "0.1.0-SNAPSHOT"
|
||||
|
||||
scalaVersion := "2.9.2"
|
||||
|
||||
scalaSource in Compile <<= baseDirectory.identity
|
||||
|
||||
seq(webSettings :_*)
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"com.fasterxml.jackson.module" % "jackson-module-scala" % "2.0.0" % "compile;container;test;runtime",
|
||||
"org.scalatra" % "scalatra" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-scalate" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-specs2" % "2.2.0-SNAPSHOT" % "test",
|
||||
"org.scalatra" % "scalatra-swagger" % "2.2.0-SNAPSHOT",
|
||||
"com.wordnik" % "swagger-core_2.9.1" % "1.1.0",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.0" % "runtime",
|
||||
"org.eclipse.jetty" % "jetty-server" % "8.1.3.v20120416" % "compile;container;test;runtime",
|
||||
"org.eclipse.jetty" % "jetty-servlet" % "8.1.3.v20120416" % "compile;container;test;runtime",
|
||||
"org.eclipse.jetty" % "jetty-webapp" % "8.1.3.v20120416" % "compile;container;test;runtime",
|
||||
"javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided;container;test;runtime"
|
||||
)
|
||||
"org.scalatra" % "scalatra" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-scalate" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-specs2" % "2.2.0-SNAPSHOT" % "test",
|
||||
"org.scalatra" % "scalatra-swagger" % "2.2.0-SNAPSHOT",
|
||||
"org.scalatra" % "scalatra-json" % "2.2.0-SNAPSHOT",
|
||||
"org.json4s" %% "json4s-jackson" % "3.0.0-SNAPSHOT",
|
||||
"com.wordnik" % "swagger-core_2.9.1" % "1.1-SNAPSHOT",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
|
||||
"org.eclipse.jetty" % "jetty-webapp" % "8.1.5.v20120716" % "container",
|
||||
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar")))
|
||||
|
||||
resolvers += Resolver.url("local-ivy", new URL("file://" + Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns)
|
||||
|
||||
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
|
||||
|
||||
ivyXML := <dependencies>
|
||||
<exclude org="org.eclipse.jetty.orbit" />
|
||||
</dependencies>
|
||||
apps in container.Configuration <<= (deployment in Compile) map (d => Seq("/api" -> d))
|
||||
|
||||
ivyXML := <dependencies><exclude module="slf4j-log4j12"/></dependencies>
|
||||
|
@ -1,27 +0,0 @@
|
||||
var express = require("express")
|
||||
, url = require("url")
|
||||
, swagger = require("./Common/node/swagger.js")
|
||||
, db = false
|
||||
|
||||
var app = express.createServer(
|
||||
function(req, res, next) { if (req.db === undefined) { req.db = db; } next(); });
|
||||
app.use(express.bodyParser());
|
||||
swagger.setAppHandler(app);
|
||||
|
||||
// resources for the demo
|
||||
{{#apis}}
|
||||
var {{name}} = require("./apis/{{name}}.js");
|
||||
{{/apis}}
|
||||
|
||||
swagger.addModels(models)
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
{{#operation}}.add{{httpMethod}}({{name}}.{{nickname}}){{/operation}}{{newline}}
|
||||
{{/operations}}
|
||||
{{/apis}};
|
||||
|
||||
// configures the app
|
||||
swagger.configure("http://localhost:8002", "0.1");
|
||||
|
||||
// start the server
|
||||
app.listen(8002);
|
@ -14,7 +14,7 @@ case class {{classname}} (
|
||||
{{/notes}}
|
||||
{{#description}}/* {{description}} */
|
||||
{{/description}}
|
||||
var {{name}}: {{datatype}}{{#hasMore}},{{newline}} {{/hasMore}}
|
||||
{{name}}: {{datatype}}{{#hasMore}},{{newline}} {{/hasMore}}
|
||||
{{/vars}}
|
||||
)
|
||||
{{/model}}
|
||||
|
@ -1 +1 @@
|
||||
sbt.version=0.11.3
|
||||
sbt.version=0.12.0
|
||||
|
@ -1 +1,7 @@
|
||||
libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % (v+"-0.2.11.1"))
|
||||
libraryDependencies <+= sbtVersion(v => v match {
|
||||
case "0.11.0" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.0-0.2.8"
|
||||
case "0.11.1" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10"
|
||||
case "0.11.2" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.2-0.2.11"
|
||||
case "0.11.3" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.3-0.2.11.1"
|
||||
case x if (x.startsWith("0.12")) => "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1"
|
||||
})
|
20
samples/server-generator/scalatra/templates/web.xml
Normal file
20
samples/server-generator/scalatra/templates/web.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||
version="3.0">
|
||||
<listener>
|
||||
<listener-class>org.scalatra.servlet.ScalatraListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>default</servlet-name>
|
||||
<url-pattern>/img/*</url-pattern>
|
||||
<url-pattern>/css/*</url-pattern>
|
||||
<url-pattern>/js/*</url-pattern>
|
||||
<url-pattern>/assets/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<context-param>
|
||||
<param-name>org.scalatra.LifeCycle</param-name>
|
||||
<param-value>com.wordnik.swagger.sample.Scalatra</param-value>
|
||||
</context-param>
|
||||
</web-app>
|
Loading…
Reference in New Issue
Block a user