forked from loafle/openapi-generator-original
rollback scalatra template
This commit is contained in:
parent
b636d2a2c9
commit
f2ee63da3b
@ -5,16 +5,16 @@ import javax.servlet.ServletContext
|
|||||||
import org.scalatra.LifeCycle
|
import org.scalatra.LifeCycle
|
||||||
|
|
||||||
class ScalatraBootstrap extends LifeCycle {
|
class ScalatraBootstrap extends LifeCycle {
|
||||||
implicit val swagger = new SwaggerApp
|
implicit val swagger = new SwaggerApp
|
||||||
|
|
||||||
override def init(context: ServletContext) {
|
override def init(context: ServletContext) {
|
||||||
implicit val system = ActorSystem("appActorSystem")
|
implicit val system = ActorSystem("appActorSystem")
|
||||||
try {
|
try {
|
||||||
{{#apiInfo}}{{#apis}}context mount (new {{classname}}, "/{{baseName}}/*")
|
{{#apiInfo}}{{#apis}}context mount (new {{classname}}, "/{{baseName}}/*")
|
||||||
{{/apis}}{{/apiInfo}}
|
{{/apis}}{{/apiInfo}}
|
||||||
context mount (new ResourcesApp, "/api-docs/*")
|
context mount (new ResourcesApp, "/api-docs/*")
|
||||||
} catch {
|
} catch {
|
||||||
case e: Throwable => e.printStackTrace()
|
case e: Throwable => e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,17 @@
|
|||||||
|
import org.eclipse.jetty.server._
|
||||||
|
import org.eclipse.jetty.webapp.WebAppContext
|
||||||
|
import org.scalatra.servlet.ScalatraListener
|
||||||
|
|
||||||
object JettyMain {
|
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]) = {
|
def main(args: Array[String]) = {
|
||||||
val server: Server = new Server
|
val server: Server = new Server
|
||||||
println("starting jetty")
|
println("starting jetty")
|
||||||
@ -30,12 +40,4 @@ object JettyMain {
|
|||||||
|
|
||||||
server.start()
|
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 "/"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package json
|
package json
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.module.scala.DefaultScalaModule
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator.Feature
|
||||||
import com.fasterxml.jackson.databind._
|
import com.fasterxml.jackson.databind._
|
||||||
|
|
||||||
object JsonUtil {
|
object JsonUtil {
|
||||||
|
@ -8,32 +8,32 @@ import org.scalatra.ScalatraServlet
|
|||||||
import org.json4s.{DefaultFormats, Formats}
|
import org.json4s.{DefaultFormats, Formats}
|
||||||
|
|
||||||
class ResourcesApp(implicit protected val system: ActorSystem, val swagger: SwaggerApp)
|
class ResourcesApp(implicit protected val system: ActorSystem, val swagger: SwaggerApp)
|
||||||
extends ScalatraServlet with JacksonSwaggerBase {
|
extends ScalatraServlet with JacksonSwaggerBase {
|
||||||
before() {
|
before() {
|
||||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def buildFullUrl(path: String) = if (path.startsWith("http")) path else {
|
protected def buildFullUrl(path: String) = if (path.startsWith("http")) path else {
|
||||||
val port = request.getServerPort
|
val port = request.getServerPort
|
||||||
val h = request.getServerName
|
val h = request.getServerName
|
||||||
val prot = if (port == 443) "https" else "http"
|
val prot = if (port == 443) "https" else "http"
|
||||||
val (proto, host) = if (port != 80 && port != 443) ("http", h+":"+port.toString) else (prot, h)
|
val (proto, host) = if (port != 80 && port != 443) ("http", h+":"+port.toString) else (prot, h)
|
||||||
"%s://%s%s%s".format(
|
"%s://%s%s%s".format(
|
||||||
proto,
|
proto,
|
||||||
host,
|
host,
|
||||||
request.getContextPath,
|
request.getContextPath,
|
||||||
path)
|
path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SwaggerApp extends Swagger(apiInfo = ApiSwagger.apiInfo, apiVersion = "1.0", swaggerVersion = "1.2")
|
class SwaggerApp extends Swagger(apiInfo = ApiSwagger.apiInfo, apiVersion = "1.0", swaggerVersion = "1.2")
|
||||||
|
|
||||||
object ApiSwagger {
|
object ApiSwagger {
|
||||||
val apiInfo = ApiInfo(
|
val apiInfo = ApiInfo(
|
||||||
"""{{{appName}}}""",
|
"""{{{appName}}}""",
|
||||||
"""{{{appDescription}}}""",
|
"""{{{appDescription}}}""",
|
||||||
"""{{{infoUrl}}}""",
|
"""{{{infoUrl}}}""",
|
||||||
"""{{{infoEmail}}}""",
|
"""{{{infoEmail}}}""",
|
||||||
"""{{{licenseInfo}}}""",
|
"""{{{licenseInfo}}}""",
|
||||||
"""{{{licenseUrl}}}""")
|
"""{{{licenseUrl}}}""")
|
||||||
}
|
}
|
@ -15,20 +15,20 @@ import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintE
|
|||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
class {{classname}} (implicit val swagger: Swagger) extends ScalatraServlet
|
class {{classname}} (implicit val swagger: Swagger) extends ScalatraServlet
|
||||||
with FileUploadSupport
|
with FileUploadSupport
|
||||||
with JacksonJsonSupport
|
with JacksonJsonSupport
|
||||||
with SwaggerSupport {
|
with SwaggerSupport {
|
||||||
protected implicit val jsonFormats: Formats = DefaultFormats
|
protected implicit val jsonFormats: Formats = DefaultFormats
|
||||||
|
|
||||||
protected val applicationDescription: String = "{{classname}}"
|
protected val applicationDescription: String = "{{classname}}"
|
||||||
override protected val applicationName: Option[String] = Some("{{baseName}}")
|
override protected val applicationName: Option[String] = Some("{{baseName}}")
|
||||||
|
|
||||||
before() {
|
before() {
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||||
}
|
}
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
{{newline}}
|
{{newline}}
|
||||||
|
|
||||||
val {{nickname}}Operation = (apiOperation[{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]("{{nickname}}")
|
val {{nickname}}Operation = (apiOperation[{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]("{{nickname}}")
|
||||||
@ -89,6 +89,6 @@ response.headers += ("Access-Control-Allow-Origin" -> "*")
|
|||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
}
|
}
|
@ -1,6 +1,4 @@
|
|||||||
|
import AssemblyKeys._ // put this at the top of the file
|
||||||
|
|
||||||
// put this at the top of the file
|
|
||||||
|
|
||||||
import NativePackagerKeys._
|
import NativePackagerKeys._
|
||||||
|
|
||||||
@ -12,7 +10,7 @@ scalariformSettings
|
|||||||
|
|
||||||
organization := "io.swagger"
|
organization := "io.swagger"
|
||||||
|
|
||||||
seq(webSettings: _*)
|
seq(webSettings :_*)
|
||||||
|
|
||||||
mainClass in assembly := Some("JettyMain")
|
mainClass in assembly := Some("JettyMain")
|
||||||
|
|
||||||
@ -44,7 +42,7 @@ libraryDependencies ++= Seq(
|
|||||||
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;compile;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))
|
"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 Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
|
||||||
|
|
||||||
@ -53,8 +51,8 @@ resolvers += "Sonatype OSS Releases" at "http://oss.sonatype.org/content/reposit
|
|||||||
ivyXML := <dependencies>
|
ivyXML := <dependencies>
|
||||||
<exclude module="slf4j-log4j12"/>
|
<exclude module="slf4j-log4j12"/>
|
||||||
<exclude module="grizzled-slf4j_2.9.1"/>
|
<exclude module="grizzled-slf4j_2.9.1"/>
|
||||||
<exclude module="jsr311-api"/>
|
<exclude module="jsr311-api" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
mergeStrategy in assembly <<= (mergeStrategy in assembly) {
|
mergeStrategy in assembly <<= (mergeStrategy in assembly) {
|
||||||
(old) => {
|
(old) => {
|
||||||
|
@ -5,11 +5,11 @@ package {{package}}
|
|||||||
|
|
||||||
{{#models}}
|
{{#models}}
|
||||||
|
|
||||||
{{#model}}
|
{{#model}}
|
||||||
case class {{classname}} (
|
case class {{classname}} (
|
||||||
{{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}] {{#description}} // {{description}}{{/description}}
|
{{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}] {{#description}} // {{description}}{{/description}}
|
||||||
{{/isNotRequired}}{{#hasMore}},
|
{{/isNotRequired}}{{#hasMore}},
|
||||||
{{/hasMore}}{{/vars}}
|
{{/hasMore}}{{/vars}}
|
||||||
)
|
)
|
||||||
{{/model}}
|
{{/model}}
|
||||||
{{/models}}
|
{{/models}}
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
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"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||||
version="3.0">
|
version="3.0">
|
||||||
<listener>
|
<listener>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user