updated sample

This commit is contained in:
Tony Tam 2012-08-29 16:55:40 -07:00
parent 02b5a929ac
commit b7ed61b8f9
4 changed files with 91 additions and 59 deletions

View File

@ -24,6 +24,8 @@ libraryDependencies ++= Seq(
"javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided;container;test;runtime" "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided;container;test;runtime"
) )
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/" resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
ivyXML := <dependencies> ivyXML := <dependencies>

View File

@ -7,65 +7,73 @@ import org.scalatra.swagger._
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
class PetApi(implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport { 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 protected def buildFullUrl(path: String) = "http://petstore.swagger.wordnik.com/api/%s" format path
get("/:petId", get("/:petId",
summary("Find pet by ID"), summary("Find pet by ID"),
nickname("getPetById"), nickname("getPetById"),
responseClass("Pet"), responseClass("Pet"),
endpoint("{TBD}"), endpoint("/pet.{format}/{petId}"),
notes("Returns a pet based on ID"), notes("Returns a pet based on ID"),
parameters( parameters(
Parameter("petId", "ID of pet that needs to be fetched", Parameter("petId", "ID of pet that needs to be fetched",
dataType = DataType.String, dataType = DataType.String,
paramType = ParamType.Path))) { paramType = ParamType.Path)
)) {
} }
post("/", post("/",
summary("Add a new pet to the store"), summary("Add a new pet to the store"),
nickname("addPet"), nickname("addPet"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/pet.{format}"),
notes(""), notes(""),
parameters( parameters(
Parameter("body", "Pet object that needs to be added to the store", Parameter("body", "Pet object that needs to be added to the store",
dataType = DataType("Pet"), dataType = DataType("Pet"),
paramType = ParamType.Body))) { paramType = ParamType.Body)
)) {
} }
put("/", put("/",
summary("Update an existing pet"), summary("Update an existing pet"),
nickname("updatePet"), nickname("updatePet"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/pet.{format}"),
notes(""), notes(""),
parameters( parameters(
Parameter("body", "Pet object that needs to be updated in the store", Parameter("body", "Pet object that needs to be updated in the store",
dataType = DataType("Pet"), dataType = DataType("Pet"),
paramType = ParamType.Body))) { paramType = ParamType.Body)
)) {
} }
get("/findByStatus", get("/findByStatus",
summary("Finds Pets by status"), summary("Finds Pets by status"),
nickname("findPetsByStatus"), nickname("findPetsByStatus"),
responseClass("List[Pet]"), responseClass("List[Pet]"),
endpoint("{TBD}"), endpoint("/pet.{format}/findByStatus"),
notes("Multiple status values can be provided with comma seperated strings"), notes("Multiple status values can be provided with comma seperated strings"),
parameters( parameters(
Parameter("status", "Status values that need to be considered for filter", Parameter("status", "Status values that need to be considered for filter",
paramType = ParamType.Query, paramType = ParamType.Query,
required = true, required = true,
allowMultiple = true, allowMultiple = true,
allowableValues = "LIST[available,pending,sold]", defaultValue = Some("available"), allowableValues = AllowableValues("LIST[available,pending,sold]"),defaultValue = Some("available"),
dataType = DataType("String")))) { dataType = DataType("String"))
)) {
} }
get("/findByTags", get("/findByTags",
summary("Finds Pets by tags"), summary("Finds Pets by tags"),
nickname("findPetsByTags"), nickname("findPetsByTags"),
responseClass("List[Pet]"), responseClass("List[Pet]"),
endpoint("{TBD}"), endpoint("/pet.{format}/findByTags"),
notes("Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing."), notes("Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing."),
parameters( parameters(
Parameter("tags", "Tags to filter by", Parameter("tags", "Tags to filter by",
@ -73,7 +81,9 @@ class PetApi(implicit val swagger: Swagger) extends ScalatraServlet with Swagger
required = true, required = true,
allowMultiple = true, allowMultiple = true,
defaultValue = None, defaultValue = None,
dataType = DataType("String")))) { dataType = DataType("String"))
)) {
} }
} }

View File

@ -7,43 +7,49 @@ import org.scalatra.swagger._
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
class StoreApi(implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport { 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 protected def buildFullUrl(path: String) = "http://petstore.swagger.wordnik.com/api/%s" format path
get("/order/:orderId", get("/order/:orderId",
summary("Find purchase order by ID"), summary("Find purchase order by ID"),
nickname("getOrderById"), nickname("getOrderById"),
responseClass("Order"), responseClass("Order"),
endpoint("{TBD}"), endpoint("/store.{format}/order/{orderId}"),
notes("For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors"), notes("For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors"),
parameters( parameters(
Parameter("orderId", "ID of pet that needs to be fetched", Parameter("orderId", "ID of pet that needs to be fetched",
dataType = DataType.String, dataType = DataType.String,
paramType = ParamType.Path))) { paramType = ParamType.Path)
)) {
} }
delete("/order/:orderId", delete("/order/:orderId",
summary("Delete purchase order by ID"), summary("Delete purchase order by ID"),
nickname("deleteOrder"), nickname("deleteOrder"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/store.{format}/order/{orderId}"),
notes("For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"), notes("For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"),
parameters( parameters(
Parameter("orderId", "ID of the order that needs to be deleted", Parameter("orderId", "ID of the order that needs to be deleted",
dataType = DataType.String, dataType = DataType.String,
paramType = ParamType.Path))) { paramType = ParamType.Path)
)) {
} }
post("/order", post("/order",
summary("Place an order for a pet"), summary("Place an order for a pet"),
nickname("placeOrder"), nickname("placeOrder"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/store.{format}/order"),
notes(""), notes(""),
parameters( parameters(
Parameter("body", "order placed for purchasing the pet", Parameter("body", "order placed for purchasing the pet",
dataType = DataType("Order"), dataType = DataType("Order"),
paramType = ParamType.Body))) { paramType = ParamType.Body)
)) {
} }
} }

View File

@ -7,92 +7,102 @@ import org.scalatra.swagger._
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
class UserApi(implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport { 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 protected def buildFullUrl(path: String) = "http://petstore.swagger.wordnik.com/api/%s" format path
post("/createWithArray", post("/createWithArray",
summary("Creates list of users with given input array"), summary("Creates list of users with given input array"),
nickname("createUsersWithArrayInput"), nickname("createUsersWithArrayInput"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/user.{format}/createWithArray"),
notes(""), notes(""),
parameters( parameters(
Parameter("body", "List of user object", Parameter("body", "List of user object",
dataType = DataType("Array[User]"), dataType = DataType("Array[User]"),
paramType = ParamType.Body))) { paramType = ParamType.Body)
)) {
} }
post("/", post("/",
summary("Create user"), summary("Create user"),
nickname("createUser"), nickname("createUser"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/user.{format}"),
notes("This can only be done by the logged in user."), notes("This can only be done by the logged in user."),
parameters( parameters(
Parameter("body", "Created user object", Parameter("body", "Created user object",
dataType = DataType("User"), dataType = DataType("User"),
paramType = ParamType.Body))) { paramType = ParamType.Body)
)) {
} }
post("/createWithList", post("/createWithList",
summary("Creates list of users with given list input"), summary("Creates list of users with given list input"),
nickname("createUsersWithListInput"), nickname("createUsersWithListInput"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/user.{format}/createWithList"),
notes(""), notes(""),
parameters( parameters(
Parameter("body", "List of user object", Parameter("body", "List of user object",
dataType = DataType("List[User]"), dataType = DataType("List[User]"),
paramType = ParamType.Body))) { paramType = ParamType.Body)
)) {
} }
put("/:username", put("/:username",
summary("Updated user"), summary("Updated user"),
nickname("updateUser"), nickname("updateUser"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/user.{format}/{username}"),
notes("This can only be done by the logged in user."), notes("This can only be done by the logged in user."),
parameters( parameters(
Parameter("username", "name that need to be deleted", Parameter("username", "name that need to be deleted",
dataType = DataType.String, dataType = DataType.String,
paramType = ParamType.Path) paramType = ParamType.Path)
Parameter ("username", "name that need to be deleted", ,
dataType = DataType("String"),
paramType = ParamType.Body),
Parameter("body", "Updated user object", Parameter("body", "Updated user object",
dataType = DataType("User"), dataType = DataType("User"),
paramType = ParamType.Body))) { paramType = ParamType.Body)
)) {
} }
delete("/:username", delete("/:username",
summary("Delete user"), summary("Delete user"),
nickname("deleteUser"), nickname("deleteUser"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/user.{format}/{username}"),
notes("This can only be done by the logged in user."), notes("This can only be done by the logged in user."),
parameters( parameters(
Parameter("username", "The name that needs to be deleted", Parameter("username", "The name that needs to be deleted",
dataType = DataType.String, dataType = DataType.String,
paramType = ParamType.Path))) { paramType = ParamType.Path)
)) {
} }
get("/:username", get("/:username",
summary("Get user by user name"), summary("Get user by user name"),
nickname("getUserByName"), nickname("getUserByName"),
responseClass("User"), responseClass("User"),
endpoint("{TBD}"), endpoint("/user.{format}/{username}"),
notes(""), notes(""),
parameters( parameters(
Parameter("username", "The name that needs to be fetched. Use user1 for testing.", Parameter("username", "The name that needs to be fetched. Use user1 for testing.",
dataType = DataType.String, dataType = DataType.String,
paramType = ParamType.Path))) { paramType = ParamType.Path)
)) {
} }
get("/login", get("/login",
summary("Logs user into the system"), summary("Logs user into the system"),
nickname("loginUser"), nickname("loginUser"),
responseClass("String"), responseClass("String"),
endpoint("{TBD}"), endpoint("/user.{format}/login"),
notes(""), notes(""),
parameters( parameters(
Parameter("username", "The user name for login", Parameter("username", "The user name for login",
@ -100,22 +110,26 @@ class UserApi(implicit val swagger: Swagger) extends ScalatraServlet with Swagge
required = true, required = true,
allowMultiple = false, allowMultiple = false,
defaultValue = None, defaultValue = None,
dataType = DataType("String")), dataType = DataType("String"))
,
Parameter("password", "The password for login in clear text", Parameter("password", "The password for login in clear text",
paramType = ParamType.Query, paramType = ParamType.Query,
required = true, required = true,
allowMultiple = false, allowMultiple = false,
defaultValue = None, defaultValue = None,
dataType = DataType("String")))) { dataType = DataType("String"))
)) {
} }
get("/logout", get("/logout",
summary("Logs out current logged in user session"), summary("Logs out current logged in user session"),
nickname("logoutUser"), nickname("logoutUser"),
responseClass("void"), responseClass("void"),
endpoint("{TBD}"), endpoint("/user.{format}/logout"),
notes(""), notes(""),
parameters()) { parameters(
)) {
} }
} }