added scalatra support

This commit is contained in:
Tony Tam 2014-10-10 21:41:21 -07:00
parent 4d214dbcef
commit 5a70550a37
14 changed files with 996 additions and 129 deletions

View File

@ -0,0 +1,20 @@
import {{apiPackage}}._
import akka.actor.ActorSystem
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) {
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()
}
}
}

View File

@ -0,0 +1,32 @@
import org.eclipse.jetty.server.nio.SelectChannelConnector
import org.eclipse.jetty.server.{ Server }
import org.eclipse.jetty.server.handler.ContextHandlerCollection
import org.eclipse.jetty.webapp.WebAppContext
import org.eclipse.jetty.servlet.{ DefaultServlet, ServletContextHandler, ServletHolder }
object JettyMain {
def main(args: Array[String]) = {
val server: Server = new Server
println("starting jetty")
server setGracefulShutdown 5000
server setSendServerVersion false
server setSendDateHeader true
server setStopAtShutdown true
val connector = new SelectChannelConnector
connector setPort sys.env.get("PORT").map(_.toInt).getOrElse(8080)
connector setMaxIdleTime 90000
server addConnector connector
val webapp = sys.env.get("PUBLIC") getOrElse "webapp"
val webApp = new WebAppContext
webApp setContextPath "/"
webApp setResourceBase webapp
webApp setDescriptor (webapp+"/WEB-INF/web.xml");
server setHandler webApp
server.start()
}
}

View File

@ -0,0 +1,12 @@
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)
}

View File

@ -0,0 +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
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)

View File

@ -0,0 +1,39 @@
package com.wordnik.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 {
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)
}
}
class SwaggerApp extends Swagger(apiInfo = ApiSwagger.apiInfo, apiVersion = "1.0", swaggerVersion = "1.2")
object ApiSwagger {
val apiInfo = ApiInfo(
"""{{{appName}}}""",
"""{{{appDescription}}}""",
"""{{{infoUrl}}}""",
"""{{{infoEmail}}}""",
"""{{{licenseInfo}}}""",
"""{{{licenseUrl}}}""")
}

View File

@ -0,0 +1,94 @@
package {{package}}
{{#imports}}import {{import}}
{{/imports}}
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 {{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}}")
before() {
contentType = formats("json")
response.headers += ("Access-Control-Allow-Origin" -> "*")
}
{{#operations}}
{{#operation}}
{{newline}}
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}})
)
{{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}}
}
{{/operation}}
{{/operations}}
}

View File

@ -0,0 +1,59 @@
import AssemblyKeys._ // put this at the top of the file
import NativePackagerKeys._
packageArchetype.java_server
assemblySettings
scalariformSettings
organization := "com.wordnik"
seq(webSettings :_*)
mainClass in assembly := Some("JettyMain")
name := "scalatra-sample"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.10.0"
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "2.0" % "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.1.0",
"org.json4s" %% "json4s-ext" % "3.1.0",
"commons-codec" % "commons-codec" % "1.7",
"net.databinder.dispatch" %% "dispatch-core" % "0.9.5",
"net.databinder.dispatch" %% "json4s-jackson" % "0.9.5",
"com.typesafe.akka" %% "akka-actor" % "2.1.0",
"org.eclipse.jetty" % "jetty-server" % "8.1.7.v20120910" % "container;provided",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container;provided",
"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 += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "Sonatype OSS Releases" at "http://oss.sonatype.org/content/repositories/releases/"
ivyXML := <dependencies>
<exclude module="slf4j-log4j12"/>
<exclude module="grizzled-slf4j_2.9.1"/>
<exclude module="jsr311-api" />
</dependencies>
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
case "about.html" => MergeStrategy.discard
case x => old(x)
}
}

View File

@ -0,0 +1,15 @@
package {{package}}
{{#imports}}import {{import}}
{{/imports}}
{{#models}}
{{#model}}
case class {{classname}} (
{{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}] {{#description}} // {{description}}{{/description}}
{{/isNotRequired}}{{#hasMore}},
{{/hasMore}}{{/vars}}
)
{{/model}}
{{/models}}

View File

@ -0,0 +1 @@
sbt.version=0.13.0

View File

@ -0,0 +1,7 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.10.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.6.4")
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "0.6.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.1")

518
src/main/resources/scalatra/sbt Executable file
View File

@ -0,0 +1,518 @@
#!/usr/bin/env bash
#
# A more capable sbt runner, coincidentally also called sbt.
# Author: Paul Phillips <paulp@typesafe.com>
# todo - make this dynamic
declare -r sbt_release_version=0.12.4
declare -r sbt_beta_version=0.13.0-RC4
declare -r sbt_snapshot_version=0.13.0-SNAPSHOT
declare sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
declare scala_version java_home sbt_explicit_version
declare verbose debug quiet noshare batch trace_level log_level
declare sbt_saved_stty
echoerr () { [[ -z $quiet ]] && echo "$@" >&2; }
vlog () { [[ -n "$verbose$debug" ]] && echoerr "$@"; }
dlog () { [[ -n $debug ]] && echoerr "$@"; }
# we'd like these set before we get around to properly processing arguments
for arg in "$@"; do
case $arg in
-q|-quiet) quiet=true ;;
-d|-debug) debug=true ;;
-v|-verbose) verbose=true ;;
*) ;;
esac
done
build_props_sbt () {
if [[ -r project/build.properties ]]; then
versionLine=$(grep ^sbt.version project/build.properties | tr -d '\r')
versionString=${versionLine##sbt.version=}
echo "$versionString"
fi
}
update_build_props_sbt () {
local ver="$1"
local old=$(build_props_sbt)
if [[ $ver == $old ]]; then
return
elif [[ -r project/build.properties ]]; then
perl -pi -e "s/^sbt\.version=.*\$/sbt.version=${ver}/" project/build.properties
grep -q '^sbt.version=' project/build.properties || echo "sbt.version=${ver}" >> project/build.properties
echoerr !!!
echoerr !!! Updated file project/build.properties setting sbt.version to: $ver
echoerr !!! Previous value was: $old
echoerr !!!
fi
}
sbt_version () {
if [[ -n $sbt_explicit_version ]]; then
echo $sbt_explicit_version
else
local v=$(build_props_sbt)
if [[ -n $v ]]; then
echo $v
else
echo $sbt_release_version
fi
fi
}
# restore stty settings (echo in particular)
onSbtRunnerExit() {
[[ -n $sbt_saved_stty ]] || return
dlog ""
dlog "restoring stty: $sbt_saved_stty"
stty $sbt_saved_stty
unset sbt_saved_stty
}
# save stty and trap exit, to ensure echo is reenabled if we are interrupted.
trap onSbtRunnerExit EXIT
sbt_saved_stty=$(stty -g 2>/dev/null)
dlog "Saved stty: $sbt_saved_stty"
# this seems to cover the bases on OSX, and someone will
# have to tell me about the others.
get_script_path () {
local path="$1"
[[ -L "$path" ]] || { echo "$path" ; return; }
local target=$(readlink "$path")
if [[ "${target:0:1}" == "/" ]]; then
echo "$target"
else
echo "$(dirname $path)/$target"
fi
}
die() {
echo "Aborting: $@"
exit 1
}
make_url () {
groupid="$1"
category="$2"
version="$3"
echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar"
}
readarr () {
while read ; do
eval "$1+=(\"$REPLY\")"
done
}
init_default_option_file () {
local overriding_var=${!1}
local default_file=$2
if [[ ! -r "$default_file" && $overriding_var =~ ^@(.*)$ ]]; then
local envvar_file=${BASH_REMATCH[1]}
if [[ -r $envvar_file ]]; then
default_file=$envvar_file
fi
fi
echo $default_file
}
declare -r default_jvm_opts="-Dfile.encoding=UTF8 -XX:MaxPermSize=256m -Xms512m -Xmx1g -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC"
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
declare -r latest_28="2.8.2"
declare -r latest_29="2.9.3"
declare -r latest_210="2.10.0"
declare -r script_path=$(get_script_path "$BASH_SOURCE")
declare -r script_dir="$(dirname $script_path)"
declare -r script_name="$(basename $script_path)"
# some non-read-onlies set with defaults
declare java_cmd=java
declare sbt_opts_file=$(init_default_option_file SBT_OPTS .sbtopts)
declare jvm_opts_file=$(init_default_option_file JVM_OPTS .jvmopts)
# pull -J and -D options to give to java.
declare -a residual_args
declare -a java_args
declare -a scalac_args
declare -a sbt_commands
# args to jvm/sbt via files or environment variables
declare -a extra_jvm_opts extra_sbt_opts
# if set, use JAVA_HOME over java found in path
[[ -e "$JAVA_HOME/bin/java" ]] && java_cmd="$JAVA_HOME/bin/java"
# directory to store sbt launchers
declare sbt_launch_dir="$HOME/.sbt/launchers"
[[ -d "$sbt_launch_dir" ]] || mkdir -p "$sbt_launch_dir"
[[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$(mktemp -d -t sbt_extras_launchers)"
build_props_scala () {
if [[ -r project/build.properties ]]; then
versionLine=$(grep ^build.scala.versions project/build.properties)
versionString=${versionLine##build.scala.versions=}
echo ${versionString%% .*}
fi
}
execRunner () {
# print the arguments one to a line, quoting any containing spaces
[[ $verbose || $debug ]] && echo "# Executing command line:" && {
for arg; do
if [[ -n "$arg" ]]; then
if printf "%s\n" "$arg" | grep -q ' '; then
printf "\"%s\"\n" "$arg"
else
printf "%s\n" "$arg"
fi
fi
done
echo ""
}
if [[ -n $batch ]]; then
# the only effective way I've found to avoid sbt hanging when backgrounded.
exec 0<&-
( "$@" & )
# I'm sure there's some way to get our hands on the pid and wait for it
# but it exceeds my present level of ambition.
else
{ "$@"; }
fi
}
sbt_groupid () {
case $(sbt_version) in
0.7.*) echo org.scala-tools.sbt ;;
0.10.*) echo org.scala-tools.sbt ;;
0.11.[12]) echo org.scala-tools.sbt ;;
*) echo org.scala-sbt ;;
esac
}
sbt_artifactory_list () {
local version0=$(sbt_version)
local version=${version0%-SNAPSHOT}
local url="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/$(sbt_groupid)/sbt-launch/"
dlog "Looking for snapshot list at: $url "
curl -s --list-only "$url" | \
grep -F $version | \
perl -e 'print reverse <>' | \
perl -pe 's#^<a href="([^"/]+).*#$1#;'
}
make_release_url () {
make_url $(sbt_groupid) releases $(sbt_version)
}
# argument is e.g. 0.13.0-SNAPSHOT
# finds the actual version (with the build id) at artifactory
make_snapshot_url () {
for ver in $(sbt_artifactory_list); do
local url=$(make_url $(sbt_groupid) snapshots $ver)
dlog "Testing $url"
curl -s --head "$url" >/dev/null
dlog "curl returned: $?"
echo "$url"
return
done
}
jar_url () {
case $(sbt_version) in
0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;;
*-SNAPSHOT) make_snapshot_url ;;
*) make_release_url ;;
esac
}
jar_file () {
case $1 in
0.13.*) echo "$sbt_launch_dir/$1/sbt-launch.jar" ;;
*) echo "$sbt_launch_dir/$sbt_release_version/sbt-launch.jar" ;;
esac
}
download_url () {
local url="$1"
local jar="$2"
echo "Downloading sbt launcher $(sbt_version):"
echo " From $url"
echo " To $jar"
mkdir -p $(dirname "$jar") && {
if which curl >/dev/null; then
curl --fail --silent "$url" --output "$jar"
elif which wget >/dev/null; then
wget --quiet -O "$jar" "$url"
fi
} && [[ -r "$jar" ]]
}
acquire_sbt_jar () {
sbt_url="$(jar_url)"
sbt_jar="$(jar_file $(sbt_version))"
[[ -r "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar"
}
usage () {
cat <<EOM
Usage: $script_name [options]
-h | -help print this message
-v | -verbose this runner is chattier
-d | -debug set sbt log level to Debug
-q | -quiet set sbt log level to Error
-trace <level> display stack traces with a max of <level> frames (default: -1, traces suppressed)
-no-colors disable ANSI color codes
-sbt-create start sbt even if current directory contains no sbt project
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt/<version>)
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11+)
-ivy <path> path to local Ivy repository (default: ~/.ivy2)
-no-share use all local caches; no sharing
-offline put sbt in offline mode
-jvm-debug <port> Turn on JVM debugging, open at the given port.
-batch Disable interactive mode
-prompt <expr> Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted
# sbt version (default: from project/build.properties if present, else latest release)
!!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which
!!! contains an sbt.version property is to update the file on disk. That's what this does.
-sbt-version <version> use the specified version of sbt (default: $sbt_release_version)
-sbt-jar <path> use the specified jar as the sbt launcher
-sbt-beta use a beta version of sbt (currently: $sbt_beta_version)
-sbt-snapshot use a snapshot version of sbt (currently: $sbt_snapshot_version)
-sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
# scala version (default: as chosen by sbt)
-28 use $latest_28
-29 use $latest_29
-210 use $latest_210
-scala-home <path> use the scala build at the specified directory
-scala-version <version> use the specified version of scala
-binary-version <version> use the specified scala version when searching for dependencies
# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
-java-home <path> alternate JAVA_HOME
# passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution
# The default set is used if JVM_OPTS is unset and no -jvm-opts file is found
<default> $default_jvm_opts
JVM_OPTS environment variable holding either the jvm args directly, or
the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts')
Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument.
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
-Dkey=val pass -Dkey=val directly to the jvm
-J-X pass option -X directly to the jvm (-J is stripped)
# passing options to sbt, OR to this runner
SBT_OPTS environment variable holding either the sbt args directly, or
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
-S-X add -X to sbt's scalacOptions (-S is stripped)
EOM
}
addJava () {
dlog "[addJava] arg = '$1'"
java_args=( "${java_args[@]}" "$1" )
}
addSbt () {
dlog "[addSbt] arg = '$1'"
sbt_commands=( "${sbt_commands[@]}" "$1" )
}
addScalac () {
dlog "[addScalac] arg = '$1'"
scalac_args=( "${scalac_args[@]}" "$1" )
}
addResidual () {
dlog "[residual] arg = '$1'"
residual_args=( "${residual_args[@]}" "$1" )
}
addResolver () {
addSbt "set resolvers in ThisBuild += $1"
}
addDebugger () {
addJava "-Xdebug"
addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
}
setScalaVersion () {
addSbt "set scalaVersion in ThisBuild := \"$1\""
if [[ "$1" == *SNAPSHOT* ]]; then
addResolver Opts.resolver.sonatypeSnapshots
fi
}
process_args ()
{
require_arg () {
local type="$1"
local opt="$2"
local arg="$3"
if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
die "$opt requires <$type> argument"
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
-h|-help) usage; exit 1 ;;
-v|-verbose) verbose=true && log_level=Info && shift ;;
-d|-debug) debug=true && log_level=Debug && shift ;;
-q|-quiet) quiet=true && log_level=Error && shift ;;
-trace) require_arg integer "$1" "$2" && trace_level=$2 && shift 2 ;;
-ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
-no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
-no-share) noshare=true && shift ;;
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
-sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
-offline) addSbt "set offline := true" && shift ;;
-jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
-batch) batch=true && shift ;;
-prompt) require_arg "expr" "$1" "$2" && addSbt "set shellPrompt in ThisBuild := (s => { val e = Project.extract(s) ; $2 })" && shift 2 ;;
-sbt-create) sbt_create=true && shift ;;
-sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;;
-sbt-beta) sbt_explicit_version=$sbt_beta_version && shift ;;
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
-sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
-scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;;
-binary-version) require_arg version "$1" "$2" && addSbt "set scalaBinaryVersion in ThisBuild := \"$2\"" && shift 2 ;;
-scala-home) require_arg path "$1" "$2" && addSbt "set every scalaHome := Some(file(\"$2\"))" && shift 2 ;;
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
-sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;;
-jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;;
-D*) addJava "$1" && shift ;;
-J*) addJava "${1:2}" && shift ;;
-S*) addScalac "${1:2}" && shift ;;
-28) addSbt "++ $latest_28" && shift ;;
-29) addSbt "++ $latest_29" && shift ;;
-210) addSbt "++ $latest_210" && shift ;;
*) addResidual "$1" && shift ;;
esac
done
}
# process the direct command line arguments
process_args "$@"
# skip #-styled comments
readConfigFile() {
while read line; do echo ${line/\#*/} | grep -vE '^\s*$'; done < $1
}
# if there are file/environment sbt_opts, process again so we
# can supply args to this runner
if [[ -r "$sbt_opts_file" ]]; then
vlog "Using sbt options defined in file $sbt_opts_file"
readarr extra_sbt_opts < <(readConfigFile "$sbt_opts_file")
elif [[ -n "$SBT_OPTS" && !($SBT_OPTS =~ ^@.*) ]]; then
vlog "Using sbt options defined in variable \$SBT_OPTS"
extra_sbt_opts=( $SBT_OPTS )
else
vlog "No extra sbt options have been defined"
fi
[[ -n $extra_sbt_opts ]] && process_args "${extra_sbt_opts[@]}"
# reset "$@" to the residual args
set -- "${residual_args[@]}"
argumentCount=$#
# only exists in 0.12+
setTraceLevel() {
case $(sbt_version) in
0.{7,10,11}.*) echoerr "Cannot set trace level in sbt version $(sbt_version)" ;;
*) addSbt "set every traceLevel := $trace_level" ;;
esac
}
# set scalacOptions if we were given any -S opts
[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\""
# Update build.properties no disk to set explicit version - sbt gives us no choice
[[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
vlog "Detected sbt version $(sbt_version)"
[[ -n "$scala_version" ]] && echoerr "Overriding scala version to $scala_version"
# no args - alert them there's stuff in here
(( $argumentCount > 0 )) || vlog "Starting $script_name: invoke with -help for other options"
# verify this is an sbt dir or -create was given
[[ -r ./build.sbt || -d ./project || -n "$sbt_create" ]] || {
cat <<EOM
$(pwd) doesn't appear to be an sbt project.
If you want to start sbt anyway, run:
$0 -sbt-create
EOM
exit 1
}
# pick up completion if present; todo
[[ -r .sbt_completion.sh ]] && source .sbt_completion.sh
# no jar? download it.
[[ -r "$sbt_jar" ]] || acquire_sbt_jar || {
# still no jar? uh-oh.
echo "Download failed. Obtain the jar manually and place it at $sbt_jar"
exit 1
}
if [[ -n $noshare ]]; then
addJava "$noshare_opts"
else
[[ -n "$sbt_dir" ]] || {
sbt_dir=~/.sbt/$(sbt_version)
vlog "Using $sbt_dir as sbt dir, -sbt-dir to override."
}
addJava "-Dsbt.global.base=$sbt_dir"
fi
if [[ -r "$jvm_opts_file" ]]; then
vlog "Using jvm options defined in file $jvm_opts_file"
readarr extra_jvm_opts < <(readConfigFile "$jvm_opts_file")
elif [[ -n "$JVM_OPTS" && !($JVM_OPTS =~ ^@.*) ]]; then
vlog "Using jvm options defined in \$JVM_OPTS variable"
extra_jvm_opts=( $JVM_OPTS )
else
vlog "Using default jvm options"
extra_jvm_opts=( $default_jvm_opts )
fi
# since sbt 0.7 doesn't understand iflast
[[ ${#residual_args[@]} -eq 0 ]] && [[ -z "$batch" ]] && residual_args=( "shell" )
# traceLevel is 0.12+
[[ -n $trace_level ]] && setTraceLevel
[[ -n $log_level ]] && [[ $log_level != Info ]] && logLevalArg="set logLevel in Global := Level.$log_level"
# run sbt
execRunner "$java_cmd" \
"${extra_jvm_opts[@]}" \
"${java_args[@]}" \
-jar "$sbt_jar" \
"$logLevalArg" \
"${sbt_commands[@]}" \
"${residual_args[@]}"

View File

@ -0,0 +1,17 @@
<?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>/*.html</url-pattern>
<url-pattern>/css/*</url-pattern>
<url-pattern>/js/*.js</url-pattern>
<url-pattern>/images/*</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -18,9 +18,31 @@
<ul>
{{#allParams}}
<div class="parameter">
{{#isContainer}}
{{#complexType}}
<!-- container / complex -->
{{/complexType}}
{{#simpleType}}
<!-- container / simple -->
<div class="param">{{paramName}}&nbsp;:&nbsp;{{dataType}}&nbsp;({{type}})</div>
<span>{{#optional}}optional{{/optional}}</span>
</div>
{{/simpleType}}
{{/isContainer}}
{{#isNotContainer}}
{{#simpleType}}
<!-- not container / simple -->
<div class="param">{{paramName}}&nbsp;:&nbsp;{{dataType}}&nbsp;({{type}})</div>
<span>{{#optional}}optional{{/optional}}</span>
</div>
{{/simpleType}}
{{/isNotContainer}}
{{#foo}}
<div class="param">{{paramName}}&nbsp;:&nbsp;{{#complexType}}&nbsp;<div class="model" id="{{complexType}}"><a href="#">{{dataType}}</a>{{/complexType}}{{#simpleType}}{{dataType}}{{/simpleType}}&nbsp;({{type}})</div>
<span>{{#optional}}optional{{/optional}}</span>
</div>
{{/foo}}
<p class="param-description">{{description}}</p>
</div>
{{/allParams}}

View File

@ -1,136 +1,157 @@
{
"swagger": 2,
"info": {
"title": "HR API",
"description": "A way to manage people in our organization",
"version": "1.0.0"
},
"host": "my.api.com",
"basePath": "/v2",
"paths": {
"/users": {
"get": {
"operationId": "getUsers",
"tags": [
"users are awesome"
],
"parameters": [
{
"in": "query",
"description": "number of records to skip",
"name": "skip",
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "successful response",
"schema": {
"type": "array",
"items": {
"$ref": "User"
}
}
},
"400": {
"description": "bad input",
"schema": {
"$ref": "ErrorModel"
}
},
"default": {
"description": "got a response"
}
}
"swagger": 2,
"info": {
"title": "HR API",
"description": "A way to manage people in our organization",
"version": "1.0.0"
},
"host": "my.api.com",
"basePath": "/v2",
"paths": {
"/": {
"get": {
"tags": [
"users are awesome"
],
"parameters": [
{
"in": "query",
"description": "number of records to skip",
"name": "skip",
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "successful response",
"schema": {
"type": "array",
"items": {
"$ref": "User"
}
}
},
"/users/{id}": {
"get": {
"tags": [
"users"
],
"operationId": "getUserById",
"parameters": [
{
"in": "path",
"name": "id",
"type": "integer",
"format": "int64",
"description": "user id to look up by"
}
],
"responses": {
"default": {
"description": "got a response"
}
}
}
},
"/places": {
"get": {
"tags": [
"locations"
],
"operationId": "getPlaces",
"responses": {
"default": {
"description": "got a response"
}
}
}
},
"/photos": {
"get": {
"tags": [
"users"
],
"operationId": "getPhotos",
"responses": {
"default": {
"description": "got a response"
}
}
},
"400": {
"description": "bad input",
"schema": {
"$ref": "ErrorModel"
}
},
"default": {
"description": "got a response"
}
}
}
},
"definitions": {
"ErrorModel": {
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int64"
},
"message": {
"type": "string"
}
}
},
"User": {
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int32"
},
"lastUpdated": {
"type": "string",
"format": "date-time"
}
}
"/users/{id}": {
"get": {
"tags": [
"users"
],
"operationId": "getUserById",
"parameters": [
{
"in": "path",
"name": "id",
"type": "integer",
"format": "int64",
"description": "user id to look up by"
}
],
"responses": {
"default": {
"description": "got a response"
}
}
}
},
"/places": {
"get": {
"tags": [
"locations"
],
"operationId": "getPlaces",
"responses": {
"default": {
"description": "got a response"
}
}
}
},
"/photos": {
"get": {
"tags": [
"users"
],
"operationId": "getPhotos",
"responses": {
"default": {
"description": "got a response"
}
}
}
}
}
},
"definitions": {
"ErrorModel": {
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int64"
},
"message": {
"type": "string"
}
}
},
"User": {
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int32"
},
"lastUpdated": {
"type": "string",
"format": "date-time"
}
}
},
"User2": {
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int32"
},
"lastUpdated": {
"type": "string",
"format": "date-time"
}
}
}
}
}