forked from loafle/openapi-generator-original
[Scalatra] replace {} with : in scalatra path (#3694)
* replace {} with : in scalatra path * remove unused var in scalatra code gen
This commit is contained in:
parent
5467c41dad
commit
11ae12b09d
@ -4,6 +4,7 @@ import io.swagger.codegen.CliOption;
|
|||||||
import io.swagger.codegen.CodegenConfig;
|
import io.swagger.codegen.CodegenConfig;
|
||||||
import io.swagger.codegen.CodegenConstants;
|
import io.swagger.codegen.CodegenConstants;
|
||||||
import io.swagger.codegen.CodegenOperation;
|
import io.swagger.codegen.CodegenOperation;
|
||||||
|
import io.swagger.codegen.CodegenParameter;
|
||||||
import io.swagger.codegen.CodegenType;
|
import io.swagger.codegen.CodegenType;
|
||||||
import io.swagger.codegen.DefaultCodegen;
|
import io.swagger.codegen.DefaultCodegen;
|
||||||
import io.swagger.codegen.SupportingFile;
|
import io.swagger.codegen.SupportingFile;
|
||||||
@ -161,8 +162,29 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||||
for (CodegenOperation op : operationList) {
|
for (CodegenOperation op : operationList) {
|
||||||
|
// force http method to lower case
|
||||||
op.httpMethod = op.httpMethod.toLowerCase();
|
op.httpMethod = op.httpMethod.toLowerCase();
|
||||||
|
|
||||||
|
String[] items = op.path.split("/", -1);
|
||||||
|
String scalaPath = "";
|
||||||
|
int pathParamIndex = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < items.length; ++i) {
|
||||||
|
if (items[i].matches("^\\{(.*)\\}$")) { // wrap in {}
|
||||||
|
scalaPath = scalaPath + ":" + items[i].replace("{", "").replace("}", "");
|
||||||
|
pathParamIndex++;
|
||||||
|
} else {
|
||||||
|
scalaPath = scalaPath + items[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i != items.length -1) {
|
||||||
|
scalaPath = scalaPath + "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
op.vendorExtensions.put("x-scalatra-path", scalaPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class {{classname}} (implicit val swagger: Swagger) extends ScalatraServlet
|
|||||||
parameters({{#allParams}}{{>queryParam}}{{>pathParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
parameters({{#allParams}}{{>queryParam}}{{>pathParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||||
)
|
)
|
||||||
|
|
||||||
{{httpMethod}}("{{path}}",operation({{nickname}}Operation)) {
|
{{httpMethod}}("{{{vendorExtensions.x-scalatra-path}}}",operation({{nickname}}Operation)) {
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{#isFile}}val {{paramName}} = fileParams("{{paramName}}"){{/isFile}}
|
{{#isFile}}val {{paramName}} = fileParams("{{paramName}}"){{/isFile}}
|
||||||
{{^isFile}}{{#isPathParam}}
|
{{^isFile}}{{#isPathParam}}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
import com.wordnik.client.api._
|
import com.wordnik.client.api._
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
import io.swagger.app.{ ResourcesApp, SwaggerApp }
|
import io.swagger.app.{ResourcesApp, SwaggerApp}
|
||||||
import javax.servlet.ServletContext
|
import javax.servlet.ServletContext
|
||||||
import org.scalatra.LifeCycle
|
import org.scalatra.LifeCycle
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class ScalatraBootstrap extends LifeCycle {
|
|||||||
context mount (new PetApi, "/v2/Pet/*")
|
context mount (new PetApi, "/v2/Pet/*")
|
||||||
context mount (new StoreApi, "/v2/Store/*")
|
context mount (new StoreApi, "/v2/Store/*")
|
||||||
context mount (new UserApi, "/v2/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()
|
||||||
|
@ -27,26 +27,26 @@ package io.swagger.app
|
|||||||
import _root_.akka.actor.ActorSystem
|
import _root_.akka.actor.ActorSystem
|
||||||
|
|
||||||
import org.scalatra.swagger.{ ApiInfo, SwaggerWithAuth, Swagger }
|
import org.scalatra.swagger.{ ApiInfo, SwaggerWithAuth, Swagger }
|
||||||
import org.scalatra.swagger.{ JacksonSwaggerBase, Swagger }
|
import org.scalatra.swagger.{JacksonSwaggerBase, Swagger}
|
||||||
import org.scalatra.ScalatraServlet
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
package com.wordnik.client.api
|
package com.wordnik.client.api
|
||||||
|
|
||||||
import com.wordnik.client.model.Pet
|
import com.wordnik.client.model.Pet
|
||||||
import java.io.File
|
|
||||||
import com.wordnik.client.model.ApiResponse
|
import com.wordnik.client.model.ApiResponse
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -35,11 +35,11 @@ import org.scalatra.swagger._
|
|||||||
import org.json4s._
|
import org.json4s._
|
||||||
import org.json4s.JsonDSL._
|
import org.json4s.JsonDSL._
|
||||||
import org.scalatra.json.{ JValueResult, JacksonJsonSupport }
|
import org.scalatra.json.{ JValueResult, JacksonJsonSupport }
|
||||||
import org.scalatra.servlet.{ FileUploadSupport, MultipartConfig, SizeConstraintExceededException }
|
import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintExceededException}
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
class PetApi(implicit val swagger: Swagger) extends ScalatraServlet
|
class PetApi (implicit val swagger: Swagger) extends ScalatraServlet
|
||||||
with FileUploadSupport
|
with FileUploadSupport
|
||||||
with JacksonJsonSupport
|
with JacksonJsonSupport
|
||||||
with SwaggerSupport {
|
with SwaggerSupport {
|
||||||
@ -52,133 +52,164 @@ class PetApi(implicit val swagger: Swagger) extends ScalatraServlet
|
|||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val addPetOperation = (apiOperation[Unit]("addPet")
|
val addPetOperation = (apiOperation[Unit]("addPet")
|
||||||
summary "Add a new pet to the store"
|
summary "Add a new pet to the store"
|
||||||
parameters (bodyParam[Pet]("body").description(""))
|
parameters(bodyParam[Pet]("body").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
post("/pet", operation(addPetOperation)) {
|
post("/pet",operation(addPetOperation)) {
|
||||||
|
|
||||||
val body = parsedBody.extract[Pet]
|
|
||||||
|
val body = parsedBody.extract[Pet]
|
||||||
|
|
||||||
println("body: " + body)
|
println("body: " + body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val deletePetOperation = (apiOperation[Unit]("deletePet")
|
val deletePetOperation = (apiOperation[Unit]("deletePet")
|
||||||
summary "Deletes a pet"
|
summary "Deletes a pet"
|
||||||
parameters (pathParam[Long]("petId").description(""), headerParam[String]("apiKey").description("").optional)
|
parameters(pathParam[Long]("petId").description(""), headerParam[String]("apiKey").description("").optional)
|
||||||
)
|
)
|
||||||
|
|
||||||
delete("/pet/{petId}", operation(deletePetOperation)) {
|
delete("/pet/:petId",operation(deletePetOperation)) {
|
||||||
|
|
||||||
val petId = params.getOrElse("petId", halt(400))
|
|
||||||
|
val petId = params.getOrElse("petId", halt(400))
|
||||||
|
|
||||||
println("petId: " + petId)
|
println("petId: " + petId)
|
||||||
|
|
||||||
val apiKey = request.getHeader("apiKey")
|
|
||||||
|
val apiKey = request.getHeader("apiKey")
|
||||||
|
|
||||||
println("apiKey: " + apiKey)
|
println("apiKey: " + apiKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val findPetsByStatusOperation = (apiOperation[List[Pet]]("findPetsByStatus")
|
val findPetsByStatusOperation = (apiOperation[List[Pet]]("findPetsByStatus")
|
||||||
summary "Finds Pets by status"
|
summary "Finds Pets by status"
|
||||||
parameters (queryParam[List[String]]("status").description(""))
|
parameters(queryParam[List[String]]("status").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/pet/findByStatus", operation(findPetsByStatusOperation)) {
|
get("/pet/findByStatus",operation(findPetsByStatusOperation)) {
|
||||||
|
|
||||||
val statusString = params.getAs[String]("status")
|
|
||||||
val status = if ("multi".equals("default")) {
|
val statusString = params.getAs[String]("status")
|
||||||
statusString match {
|
val status = if("csv".equals("default")) {
|
||||||
case Some(str) => str.split(",")
|
statusString match {
|
||||||
case None => List()
|
case Some(str) => str.split(",")
|
||||||
|
case None => List()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
else
|
||||||
List()
|
List()
|
||||||
|
|
||||||
|
|
||||||
println("status: " + status)
|
println("status: " + status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val findPetsByTagsOperation = (apiOperation[List[Pet]]("findPetsByTags")
|
val findPetsByTagsOperation = (apiOperation[List[Pet]]("findPetsByTags")
|
||||||
summary "Finds Pets by tags"
|
summary "Finds Pets by tags"
|
||||||
parameters (queryParam[List[String]]("tags").description(""))
|
parameters(queryParam[List[String]]("tags").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/pet/findByTags", operation(findPetsByTagsOperation)) {
|
get("/pet/findByTags",operation(findPetsByTagsOperation)) {
|
||||||
|
|
||||||
val tagsString = params.getAs[String]("tags")
|
|
||||||
val tags = if ("multi".equals("default")) {
|
val tagsString = params.getAs[String]("tags")
|
||||||
tagsString match {
|
val tags = if("csv".equals("default")) {
|
||||||
case Some(str) => str.split(",")
|
tagsString match {
|
||||||
case None => List()
|
case Some(str) => str.split(",")
|
||||||
|
case None => List()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
else
|
||||||
List()
|
List()
|
||||||
|
|
||||||
|
|
||||||
println("tags: " + tags)
|
println("tags: " + tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val getPetByIdOperation = (apiOperation[Pet]("getPetById")
|
val getPetByIdOperation = (apiOperation[Pet]("getPetById")
|
||||||
summary "Find pet by ID"
|
summary "Find pet by ID"
|
||||||
parameters (pathParam[Long]("petId").description(""))
|
parameters(pathParam[Long]("petId").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/pet/{petId}", operation(getPetByIdOperation)) {
|
get("/pet/:petId",operation(getPetByIdOperation)) {
|
||||||
|
|
||||||
val petId = params.getOrElse("petId", halt(400))
|
|
||||||
|
val petId = params.getOrElse("petId", halt(400))
|
||||||
|
|
||||||
println("petId: " + petId)
|
println("petId: " + petId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val updatePetOperation = (apiOperation[Unit]("updatePet")
|
val updatePetOperation = (apiOperation[Unit]("updatePet")
|
||||||
summary "Update an existing pet"
|
summary "Update an existing pet"
|
||||||
parameters (bodyParam[Pet]("body").description(""))
|
parameters(bodyParam[Pet]("body").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
put("/pet", operation(updatePetOperation)) {
|
put("/pet",operation(updatePetOperation)) {
|
||||||
|
|
||||||
val body = parsedBody.extract[Pet]
|
|
||||||
|
val body = parsedBody.extract[Pet]
|
||||||
|
|
||||||
println("body: " + body)
|
println("body: " + body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val updatePetWithFormOperation = (apiOperation[Unit]("updatePetWithForm")
|
val updatePetWithFormOperation = (apiOperation[Unit]("updatePetWithForm")
|
||||||
summary "Updates a pet in the store with form data"
|
summary "Updates a pet in the store with form data"
|
||||||
parameters (pathParam[Long]("petId").description(""), formParam[String]("name").description("").optional, formParam[String]("status").description("").optional)
|
parameters(pathParam[Long]("petId").description(""), formParam[String]("name").description("").optional, formParam[String]("status").description("").optional)
|
||||||
)
|
)
|
||||||
|
|
||||||
post("/pet/{petId}", operation(updatePetWithFormOperation)) {
|
post("/pet/:petId",operation(updatePetWithFormOperation)) {
|
||||||
|
|
||||||
val petId = params.getOrElse("petId", halt(400))
|
|
||||||
|
val petId = params.getOrElse("petId", halt(400))
|
||||||
|
|
||||||
println("petId: " + petId)
|
println("petId: " + petId)
|
||||||
|
|
||||||
val name = params.getAs[String]("name")
|
|
||||||
|
val name = params.getAs[String]("name")
|
||||||
|
|
||||||
println("name: " + name)
|
println("name: " + name)
|
||||||
|
|
||||||
val status = params.getAs[String]("status")
|
|
||||||
|
val status = params.getAs[String]("status")
|
||||||
|
|
||||||
println("status: " + status)
|
println("status: " + status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val uploadFileOperation = (apiOperation[ApiResponse]("uploadFile")
|
val uploadFileOperation = (apiOperation[ApiResponse]("uploadFile")
|
||||||
summary "uploads an image"
|
summary "uploads an image"
|
||||||
parameters (pathParam[Long]("petId").description(""), formParam[String]("additionalMetadata").description("").optional, formParam[File]("file").description("").optional)
|
parameters(pathParam[Long]("petId").description(""), formParam[String]("additionalMetadata").description("").optional, formParam[File]("file").description("").optional)
|
||||||
)
|
)
|
||||||
|
|
||||||
post("/pet/{petId}/uploadImage", operation(uploadFileOperation)) {
|
post("/pet/:petId/uploadImage",operation(uploadFileOperation)) {
|
||||||
|
|
||||||
val petId = params.getOrElse("petId", halt(400))
|
|
||||||
|
val petId = params.getOrElse("petId", halt(400))
|
||||||
|
|
||||||
println("petId: " + petId)
|
println("petId: " + petId)
|
||||||
|
|
||||||
val additionalMetadata = params.getAs[String]("additionalMetadata")
|
|
||||||
|
val additionalMetadata = params.getAs[String]("additionalMetadata")
|
||||||
|
|
||||||
println("additionalMetadata: " + additionalMetadata)
|
println("additionalMetadata: " + additionalMetadata)
|
||||||
val file = fileParams("file")
|
val file = fileParams("file")
|
||||||
println("file: " + file)
|
println("file: " + file)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,11 @@ import org.scalatra.swagger._
|
|||||||
import org.json4s._
|
import org.json4s._
|
||||||
import org.json4s.JsonDSL._
|
import org.json4s.JsonDSL._
|
||||||
import org.scalatra.json.{ JValueResult, JacksonJsonSupport }
|
import org.scalatra.json.{ JValueResult, JacksonJsonSupport }
|
||||||
import org.scalatra.servlet.{ FileUploadSupport, MultipartConfig, SizeConstraintExceededException }
|
import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintExceededException}
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
class StoreApi(implicit val swagger: Swagger) extends ScalatraServlet
|
class StoreApi (implicit val swagger: Swagger) extends ScalatraServlet
|
||||||
with FileUploadSupport
|
with FileUploadSupport
|
||||||
with JacksonJsonSupport
|
with JacksonJsonSupport
|
||||||
with SwaggerSupport {
|
with SwaggerSupport {
|
||||||
@ -50,47 +50,57 @@ class StoreApi(implicit val swagger: Swagger) extends ScalatraServlet
|
|||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val deleteOrderOperation = (apiOperation[Unit]("deleteOrder")
|
val deleteOrderOperation = (apiOperation[Unit]("deleteOrder")
|
||||||
summary "Delete purchase order by ID"
|
summary "Delete purchase order by ID"
|
||||||
parameters (pathParam[Long]("orderId").description(""))
|
parameters(pathParam[String]("orderId").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
delete("/store/order/{orderId}", operation(deleteOrderOperation)) {
|
delete("/store/order/:orderId",operation(deleteOrderOperation)) {
|
||||||
|
|
||||||
val orderId = params.getOrElse("orderId", halt(400))
|
|
||||||
|
val orderId = params.getOrElse("orderId", halt(400))
|
||||||
|
|
||||||
println("orderId: " + orderId)
|
println("orderId: " + orderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val getInventoryOperation = (apiOperation[Map[String, Int]]("getInventory")
|
val getInventoryOperation = (apiOperation[Map[String, Int]]("getInventory")
|
||||||
summary "Returns pet inventories by status"
|
summary "Returns pet inventories by status"
|
||||||
parameters ()
|
parameters()
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/store/inventory", operation(getInventoryOperation)) {
|
get("/store/inventory",operation(getInventoryOperation)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val getOrderByIdOperation = (apiOperation[Order]("getOrderById")
|
val getOrderByIdOperation = (apiOperation[Order]("getOrderById")
|
||||||
summary "Find purchase order by ID"
|
summary "Find purchase order by ID"
|
||||||
parameters (pathParam[Long]("orderId").description(""))
|
parameters(pathParam[Long]("orderId").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/store/order/{orderId}", operation(getOrderByIdOperation)) {
|
get("/store/order/:orderId",operation(getOrderByIdOperation)) {
|
||||||
|
|
||||||
val orderId = params.getOrElse("orderId", halt(400))
|
|
||||||
|
val orderId = params.getOrElse("orderId", halt(400))
|
||||||
|
|
||||||
println("orderId: " + orderId)
|
println("orderId: " + orderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val placeOrderOperation = (apiOperation[Order]("placeOrder")
|
val placeOrderOperation = (apiOperation[Order]("placeOrder")
|
||||||
summary "Place an order for a pet"
|
summary "Place an order for a pet"
|
||||||
parameters (bodyParam[Order]("body").description(""))
|
parameters(bodyParam[Order]("body").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
post("/store/order", operation(placeOrderOperation)) {
|
post("/store/order",operation(placeOrderOperation)) {
|
||||||
|
|
||||||
val body = parsedBody.extract[Order]
|
|
||||||
|
val body = parsedBody.extract[Order]
|
||||||
|
|
||||||
println("body: " + body)
|
println("body: " + body)
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,11 @@ import org.scalatra.swagger._
|
|||||||
import org.json4s._
|
import org.json4s._
|
||||||
import org.json4s.JsonDSL._
|
import org.json4s.JsonDSL._
|
||||||
import org.scalatra.json.{ JValueResult, JacksonJsonSupport }
|
import org.scalatra.json.{ JValueResult, JacksonJsonSupport }
|
||||||
import org.scalatra.servlet.{ FileUploadSupport, MultipartConfig, SizeConstraintExceededException }
|
import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintExceededException}
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
class UserApi(implicit val swagger: Swagger) extends ScalatraServlet
|
class UserApi (implicit val swagger: Swagger) extends ScalatraServlet
|
||||||
with FileUploadSupport
|
with FileUploadSupport
|
||||||
with JacksonJsonSupport
|
with JacksonJsonSupport
|
||||||
with SwaggerSupport {
|
with SwaggerSupport {
|
||||||
@ -50,103 +50,127 @@ class UserApi(implicit val swagger: Swagger) extends ScalatraServlet
|
|||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
response.headers += ("Access-Control-Allow-Origin" -> "*")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val createUserOperation = (apiOperation[Unit]("createUser")
|
val createUserOperation = (apiOperation[Unit]("createUser")
|
||||||
summary "Create user"
|
summary "Create user"
|
||||||
parameters (bodyParam[User]("body").description(""))
|
parameters(bodyParam[User]("body").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
post("/user", operation(createUserOperation)) {
|
post("/user",operation(createUserOperation)) {
|
||||||
|
|
||||||
val body = parsedBody.extract[User]
|
|
||||||
|
val body = parsedBody.extract[User]
|
||||||
|
|
||||||
println("body: " + body)
|
println("body: " + body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val createUsersWithArrayInputOperation = (apiOperation[Unit]("createUsersWithArrayInput")
|
val createUsersWithArrayInputOperation = (apiOperation[Unit]("createUsersWithArrayInput")
|
||||||
summary "Creates list of users with given input array"
|
summary "Creates list of users with given input array"
|
||||||
parameters (bodyParam[List[User]]("body").description(""))
|
parameters(bodyParam[List[User]]("body").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
post("/user/createWithArray", operation(createUsersWithArrayInputOperation)) {
|
post("/user/createWithArray",operation(createUsersWithArrayInputOperation)) {
|
||||||
|
|
||||||
val body = parsedBody.extract[List[User]]
|
|
||||||
|
val body = parsedBody.extract[List[User]]
|
||||||
|
|
||||||
println("body: " + body)
|
println("body: " + body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val createUsersWithListInputOperation = (apiOperation[Unit]("createUsersWithListInput")
|
val createUsersWithListInputOperation = (apiOperation[Unit]("createUsersWithListInput")
|
||||||
summary "Creates list of users with given input array"
|
summary "Creates list of users with given input array"
|
||||||
parameters (bodyParam[List[User]]("body").description(""))
|
parameters(bodyParam[List[User]]("body").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
post("/user/createWithList", operation(createUsersWithListInputOperation)) {
|
post("/user/createWithList",operation(createUsersWithListInputOperation)) {
|
||||||
|
|
||||||
val body = parsedBody.extract[List[User]]
|
|
||||||
|
val body = parsedBody.extract[List[User]]
|
||||||
|
|
||||||
println("body: " + body)
|
println("body: " + body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val deleteUserOperation = (apiOperation[Unit]("deleteUser")
|
val deleteUserOperation = (apiOperation[Unit]("deleteUser")
|
||||||
summary "Delete user"
|
summary "Delete user"
|
||||||
parameters (pathParam[String]("username").description(""))
|
parameters(pathParam[String]("username").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
delete("/user/{username}", operation(deleteUserOperation)) {
|
delete("/user/:username",operation(deleteUserOperation)) {
|
||||||
|
|
||||||
val username = params.getOrElse("username", halt(400))
|
|
||||||
|
val username = params.getOrElse("username", halt(400))
|
||||||
|
|
||||||
println("username: " + username)
|
println("username: " + username)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val getUserByNameOperation = (apiOperation[User]("getUserByName")
|
val getUserByNameOperation = (apiOperation[User]("getUserByName")
|
||||||
summary "Get user by user name"
|
summary "Get user by user name"
|
||||||
parameters (pathParam[String]("username").description(""))
|
parameters(pathParam[String]("username").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/user/{username}", operation(getUserByNameOperation)) {
|
get("/user/:username",operation(getUserByNameOperation)) {
|
||||||
|
|
||||||
val username = params.getOrElse("username", halt(400))
|
|
||||||
|
val username = params.getOrElse("username", halt(400))
|
||||||
|
|
||||||
println("username: " + username)
|
println("username: " + username)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val loginUserOperation = (apiOperation[String]("loginUser")
|
val loginUserOperation = (apiOperation[String]("loginUser")
|
||||||
summary "Logs user into the system"
|
summary "Logs user into the system"
|
||||||
parameters (queryParam[String]("username").description(""), queryParam[String]("password").description(""))
|
parameters(queryParam[String]("username").description(""), queryParam[String]("password").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/user/login", operation(loginUserOperation)) {
|
get("/user/login",operation(loginUserOperation)) {
|
||||||
|
|
||||||
val username = params.getAs[String]("username")
|
|
||||||
|
val username = params.getAs[String]("username")
|
||||||
|
|
||||||
println("username: " + username)
|
println("username: " + username)
|
||||||
|
|
||||||
val password = params.getAs[String]("password")
|
|
||||||
|
val password = params.getAs[String]("password")
|
||||||
|
|
||||||
println("password: " + password)
|
println("password: " + password)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val logoutUserOperation = (apiOperation[Unit]("logoutUser")
|
val logoutUserOperation = (apiOperation[Unit]("logoutUser")
|
||||||
summary "Logs out current logged in user session"
|
summary "Logs out current logged in user session"
|
||||||
parameters ()
|
parameters()
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/user/logout", operation(logoutUserOperation)) {
|
get("/user/logout",operation(logoutUserOperation)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val updateUserOperation = (apiOperation[Unit]("updateUser")
|
val updateUserOperation = (apiOperation[Unit]("updateUser")
|
||||||
summary "Updated user"
|
summary "Updated user"
|
||||||
parameters (pathParam[String]("username").description(""), bodyParam[User]("body").description(""))
|
parameters(pathParam[String]("username").description(""), bodyParam[User]("body").description(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
put("/user/{username}", operation(updateUserOperation)) {
|
put("/user/:username",operation(updateUserOperation)) {
|
||||||
|
|
||||||
val username = params.getOrElse("username", halt(400))
|
|
||||||
|
val username = params.getOrElse("username", halt(400))
|
||||||
|
|
||||||
println("username: " + username)
|
println("username: " + username)
|
||||||
|
|
||||||
val body = parsedBody.extract[User]
|
|
||||||
|
val body = parsedBody.extract[User]
|
||||||
|
|
||||||
println("body: " + body)
|
println("body: " + body)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,10 @@
|
|||||||
|
|
||||||
package com.wordnik.client.model
|
package com.wordnik.client.model
|
||||||
|
|
||||||
case class ApiResponse(
|
|
||||||
|
|
||||||
|
case class ApiResponse (
|
||||||
code: Option[Int],
|
code: Option[Int],
|
||||||
_type: Option[String],
|
_type: Option[String],
|
||||||
message: Option[String])
|
message: Option[String]
|
||||||
|
)
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
|
|
||||||
package com.wordnik.client.model
|
package com.wordnik.client.model
|
||||||
|
|
||||||
case class Category(
|
|
||||||
|
|
||||||
|
case class Category (
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
name: Option[String])
|
name: Option[String]
|
||||||
|
)
|
||||||
|
@ -26,10 +26,12 @@ package com.wordnik.client.model
|
|||||||
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
case class Order(
|
|
||||||
|
case class Order (
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
petId: Option[Long],
|
petId: Option[Long],
|
||||||
quantity: Option[Int],
|
quantity: Option[Int],
|
||||||
shipDate: Option[Date],
|
shipDate: Option[Date],
|
||||||
status: Option[String], // Order Status
|
status: Option[String], // Order Status
|
||||||
complete: Option[Boolean])
|
complete: Option[Boolean]
|
||||||
|
)
|
||||||
|
@ -27,11 +27,12 @@ package com.wordnik.client.model
|
|||||||
import com.wordnik.client.model.Category
|
import com.wordnik.client.model.Category
|
||||||
import com.wordnik.client.model.Tag
|
import com.wordnik.client.model.Tag
|
||||||
|
|
||||||
case class Pet(
|
|
||||||
|
case class Pet (
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
category: Option[Category],
|
category: Option[Category],
|
||||||
name: String,
|
name: String,
|
||||||
photoUrls: List[String],
|
photoUrls: List[String],
|
||||||
tags: Option[List[Tag]],
|
tags: Option[List[Tag]],
|
||||||
status: Option[String] // pet status in the store
|
status: Option[String] // pet status in the store
|
||||||
)
|
)
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
|
|
||||||
package com.wordnik.client.model
|
package com.wordnik.client.model
|
||||||
|
|
||||||
case class Tag(
|
|
||||||
|
|
||||||
|
case class Tag (
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
name: Option[String])
|
name: Option[String]
|
||||||
|
)
|
||||||
|
@ -24,13 +24,15 @@
|
|||||||
|
|
||||||
package com.wordnik.client.model
|
package com.wordnik.client.model
|
||||||
|
|
||||||
case class User(
|
|
||||||
|
|
||||||
|
case class User (
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
username: Option[String],
|
username: Option[String],
|
||||||
firstName: Option[String],
|
firstName: Option[String],
|
||||||
lastName: Option[String],
|
lastName: Option[String],
|
||||||
email: Option[String],
|
email: Option[String],
|
||||||
password: Option[String],
|
password: Option[String],
|
||||||
phone: Option[String],
|
phone: Option[String],
|
||||||
userStatus: Option[Int] // User Status
|
userStatus: Option[Int] // User Status
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user