fix scalatra path with basepath (#1425) (#3448)

This commit is contained in:
Yi 2016-07-26 02:49:33 -04:00 committed by wing328
parent 30c2503f9f
commit b3403015fd
6 changed files with 17 additions and 17 deletions

View File

@ -12,7 +12,7 @@ class ScalatraBootstrap extends LifeCycle {
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}}, "{{basePathWithoutHost}}/{{baseName}}/*")
{{/apis}}{{/apiInfo}} {{/apis}}{{/apiInfo}}
context mount (new ResourcesApp, "/api-docs/*") context mount (new ResourcesApp, "/api-docs/*")
} catch { } catch {

View File

@ -16,14 +16,14 @@ 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("{{basePathWithoutHost}}/{{baseName}}")
before() { before() {
contentType = formats("json") contentType = formats("json")
@ -51,4 +51,4 @@ class {{classname}} (implicit val swagger: Swagger) extends ScalatraServlet
{{/operation}} {{/operation}}
{{/operations}} {{/operations}}
} }

View File

@ -34,10 +34,10 @@ class ScalatraBootstrap extends LifeCycle {
override def init(context: ServletContext) { override def init(context: ServletContext) {
implicit val system = ActorSystem("appActorSystem") implicit val system = ActorSystem("appActorSystem")
try { try {
context mount (new PetApi, "/Pet/*") context mount (new PetApi, "/v2/Pet/*")
context mount (new StoreApi, "/Store/*") context mount (new StoreApi, "/v2/Store/*")
context mount (new UserApi, "/User/*") context mount (new UserApi, "/v2/User/*")
context mount (new ResourcesApp, "/api-docs/*") context mount (new ResourcesApp, "/api-docs/*")
} catch { } catch {
case e: Throwable => e.printStackTrace() case e: Throwable => e.printStackTrace()

View File

@ -46,7 +46,7 @@ class PetApi(implicit val swagger: Swagger) extends ScalatraServlet
protected implicit val jsonFormats: Formats = DefaultFormats protected implicit val jsonFormats: Formats = DefaultFormats
protected val applicationDescription: String = "PetApi" protected val applicationDescription: String = "PetApi"
override protected val applicationName: Option[String] = Some("Pet") override protected val applicationName: Option[String] = Some("/v2/Pet")
before() { before() {
contentType = formats("json") contentType = formats("json")
@ -89,7 +89,7 @@ class PetApi(implicit val swagger: Swagger) extends ScalatraServlet
get("/pet/findByStatus", operation(findPetsByStatusOperation)) { get("/pet/findByStatus", operation(findPetsByStatusOperation)) {
val statusString = params.getAs[String]("status") val statusString = params.getAs[String]("status")
val status = if ("csv".equals("default")) { val status = if ("multi".equals("default")) {
statusString match { statusString match {
case Some(str) => str.split(",") case Some(str) => str.split(",")
case None => List() case None => List()
@ -108,7 +108,7 @@ class PetApi(implicit val swagger: Swagger) extends ScalatraServlet
get("/pet/findByTags", operation(findPetsByTagsOperation)) { get("/pet/findByTags", operation(findPetsByTagsOperation)) {
val tagsString = params.getAs[String]("tags") val tagsString = params.getAs[String]("tags")
val tags = if ("csv".equals("default")) { val tags = if ("multi".equals("default")) {
tagsString match { tagsString match {
case Some(str) => str.split(",") case Some(str) => str.split(",")
case None => List() case None => List()
@ -181,4 +181,4 @@ class PetApi(implicit val swagger: Swagger) extends ScalatraServlet
println("file: " + file) println("file: " + file)
} }
} }

View File

@ -44,7 +44,7 @@ class StoreApi(implicit val swagger: Swagger) extends ScalatraServlet
protected implicit val jsonFormats: Formats = DefaultFormats protected implicit val jsonFormats: Formats = DefaultFormats
protected val applicationDescription: String = "StoreApi" protected val applicationDescription: String = "StoreApi"
override protected val applicationName: Option[String] = Some("Store") override protected val applicationName: Option[String] = Some("/v2/Store")
before() { before() {
contentType = formats("json") contentType = formats("json")
@ -53,7 +53,7 @@ class StoreApi(implicit val swagger: Swagger) extends ScalatraServlet
val deleteOrderOperation = (apiOperation[Unit]("deleteOrder") val deleteOrderOperation = (apiOperation[Unit]("deleteOrder")
summary "Delete purchase order by ID" summary "Delete purchase order by ID"
parameters (pathParam[String]("orderId").description("")) parameters (pathParam[Long]("orderId").description(""))
) )
delete("/store/order/{orderId}", operation(deleteOrderOperation)) { delete("/store/order/{orderId}", operation(deleteOrderOperation)) {
@ -95,4 +95,4 @@ class StoreApi(implicit val swagger: Swagger) extends ScalatraServlet
println("body: " + body) println("body: " + body)
} }
} }

View File

@ -44,7 +44,7 @@ class UserApi(implicit val swagger: Swagger) extends ScalatraServlet
protected implicit val jsonFormats: Formats = DefaultFormats protected implicit val jsonFormats: Formats = DefaultFormats
protected val applicationDescription: String = "UserApi" protected val applicationDescription: String = "UserApi"
override protected val applicationName: Option[String] = Some("User") override protected val applicationName: Option[String] = Some("/v2/User")
before() { before() {
contentType = formats("json") contentType = formats("json")
@ -151,4 +151,4 @@ class UserApi(implicit val swagger: Swagger) extends ScalatraServlet
println("body: " + body) println("body: " + body)
} }
} }