update php, nodejs, scalatra server for petstore

This commit is contained in:
wing328 2016-04-15 20:05:45 +08:00
parent 400cc9e6f9
commit c93fcc2643
23 changed files with 1197 additions and 1185 deletions

View File

@ -1,23 +1,37 @@
---
swagger: "2.0"
info:
description: "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io)\
\ or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample,\
\ you can use the api key `special-key` to test the authorization filters\n"
description: "This is a sample server Petstore server. You can find out more about\
\ Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\
\ For this sample, you can use the api key `special-key` to test the authorization\
\ filters."
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/"
contact:
name: "apiteam@swagger.io"
email: "apiteam@swagger.io"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
tags:
- name: "pet"
description: "Everything about your Pets"
externalDocs:
description: "Find out more"
url: "http://swagger.io"
- name: "store"
description: "Access to Petstore orders"
- name: "user"
description: "Operations about user"
externalDocs:
description: "Find out more about our store"
url: "http://swagger.io"
schemes:
- "http"
paths:
/pets:
/pet:
post:
tags:
- "pet"
@ -28,13 +42,13 @@ paths:
- "application/json"
- "application/xml"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: false
required: true
schema:
$ref: "#/definitions/Pet"
responses:
@ -42,8 +56,8 @@ paths:
description: "Invalid input"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
- "write:pets"
- "read:pets"
x-swagger-router-controller: "Pet"
put:
tags:
@ -55,13 +69,13 @@ paths:
- "application/json"
- "application/xml"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: false
required: true
schema:
$ref: "#/definitions/Pet"
responses:
@ -73,28 +87,33 @@ paths:
description: "Validation exception"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
- "write:pets"
- "read:pets"
x-swagger-router-controller: "Pet"
/pets/findByStatus:
/pet/findByStatus:
get:
tags:
- "pet"
summary: "Finds Pets by status"
description: "Multiple status values can be provided with comma seperated strings"
description: "Multiple status values can be provided with comma separated strings"
operationId: "findPetsByStatus"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "status"
in: "query"
description: "Status values that need to be considered for filter"
required: false
required: true
type: "array"
items:
type: "string"
collectionFormat: "multi"
default: "available"
enum:
- "available"
- "pending"
- "sold"
collectionFormat: "csv"
responses:
200:
description: "successful operation"
@ -106,29 +125,29 @@ paths:
description: "Invalid status value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
- "write:pets"
- "read:pets"
x-swagger-router-controller: "Pet"
/pets/findByTags:
/pet/findByTags:
get:
tags:
- "pet"
summary: "Finds Pets by tags"
description: "Muliple tags can be provided with comma seperated strings. Use\
description: "Multiple tags can be provided with comma separated strings. Use\
\ tag1, tag2, tag3 for testing."
operationId: "findPetsByTags"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "tags"
in: "query"
description: "Tags to filter by"
required: false
required: true
type: "array"
items:
type: "string"
collectionFormat: "multi"
collectionFormat: "csv"
responses:
200:
description: "successful operation"
@ -140,24 +159,23 @@ paths:
description: "Invalid tag value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
- "write:pets"
- "read:pets"
x-swagger-router-controller: "Pet"
/pets/{petId}:
/pet/{petId}:
get:
tags:
- "pet"
summary: "Find pet by ID"
description: "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate\
\ API error conditions"
description: "Returns a single pet"
operationId: "getPetById"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be fetched"
description: "ID of pet to return"
required: true
type: "integer"
format: "int64"
@ -172,9 +190,6 @@ paths:
description: "Pet not found"
security:
- api_key: []
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
post:
tags:
@ -185,31 +200,32 @@ paths:
consumes:
- "application/x-www-form-urlencoded"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be updated"
required: true
type: "string"
type: "integer"
format: "int64"
- name: "name"
in: "formData"
description: "Updated name of the pet"
required: true
required: false
type: "string"
- name: "status"
in: "formData"
description: "Updated status of the pet"
required: true
required: false
type: "string"
responses:
405:
description: "Invalid input"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
- "write:pets"
- "read:pets"
x-swagger-router-controller: "Pet"
delete:
tags:
@ -218,13 +234,12 @@ paths:
description: ""
operationId: "deletePet"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "api_key"
in: "header"
description: ""
required: true
required: false
type: "string"
- name: "petId"
in: "path"
@ -237,10 +252,69 @@ paths:
description: "Invalid pet value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
- "write:pets"
- "read:pets"
x-swagger-router-controller: "Pet"
/stores/order:
/pet/{petId}/uploadImage:
post:
tags:
- "pet"
summary: "uploads an image"
description: ""
operationId: "uploadFile"
consumes:
- "multipart/form-data"
produces:
- "application/json"
parameters:
- name: "petId"
in: "path"
description: "ID of pet to update"
required: true
type: "integer"
format: "int64"
- name: "additionalMetadata"
in: "formData"
description: "Additional data to pass to server"
required: false
type: "string"
- name: "file"
in: "formData"
description: "file to upload"
required: false
type: "file"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/ApiResponse"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
x-swagger-router-controller: "Pet"
/store/inventory:
get:
tags:
- "store"
summary: "Returns pet inventories by status"
description: "Returns a map of status codes to quantities"
operationId: "getInventory"
produces:
- "application/json"
parameters: []
responses:
200:
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "integer"
format: "int32"
security:
- api_key: []
x-swagger-router-controller: "Store"
/store/order:
post:
tags:
- "store"
@ -248,13 +322,13 @@ paths:
description: ""
operationId: "placeOrder"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "order placed for purchasing the pet"
required: false
required: true
schema:
$ref: "#/definitions/Order"
responses:
@ -265,7 +339,7 @@ paths:
400:
description: "Invalid Order"
x-swagger-router-controller: "Store"
/stores/order/{orderId}:
/store/order/{orderId}:
get:
tags:
- "store"
@ -274,14 +348,17 @@ paths:
\ values will generated exceptions"
operationId: "getOrderById"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "orderId"
in: "path"
description: "ID of pet that needs to be fetched"
required: true
type: "string"
type: "integer"
maximum: 5
minimum: 1
format: "int64"
responses:
200:
description: "successful operation"
@ -300,21 +377,22 @@ paths:
\ above 1000 or nonintegers will generate API errors"
operationId: "deleteOrder"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "orderId"
in: "path"
description: "ID of the order that needs to be deleted"
required: true
type: "string"
minimum: 1
responses:
400:
description: "Invalid ID supplied"
404:
description: "Order not found"
x-swagger-router-controller: "Store"
/users:
/user:
post:
tags:
- "user"
@ -322,20 +400,20 @@ paths:
description: "This can only be done by the logged in user."
operationId: "createUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Created user object"
required: false
required: true
schema:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/users/createWithArray:
/user/createWithArray:
post:
tags:
- "user"
@ -343,13 +421,13 @@ paths:
description: ""
operationId: "createUsersWithArrayInput"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: false
required: true
schema:
type: "array"
items:
@ -358,7 +436,7 @@ paths:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/users/createWithList:
/user/createWithList:
post:
tags:
- "user"
@ -366,13 +444,13 @@ paths:
description: ""
operationId: "createUsersWithListInput"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: false
required: true
schema:
type: "array"
items:
@ -381,7 +459,7 @@ paths:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/users/login:
/user/login:
get:
tags:
- "user"
@ -389,28 +467,37 @@ paths:
description: ""
operationId: "loginUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "username"
in: "query"
description: "The user name for login"
required: false
required: true
type: "string"
- name: "password"
in: "query"
description: "The password for login in clear text"
required: false
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "string"
headers:
X-Rate-Limit:
type: "integer"
format: "int32"
description: "calls per hour allowed by the user"
X-Expires-After:
type: "string"
format: "date-time"
description: "date in UTC when toekn expires"
400:
description: "Invalid username/password supplied"
x-swagger-router-controller: "User"
/users/logout:
/user/logout:
get:
tags:
- "user"
@ -418,14 +505,14 @@ paths:
description: ""
operationId: "logoutUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters: []
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/users/{username}:
/user/{username}:
get:
tags:
- "user"
@ -433,12 +520,12 @@ paths:
description: ""
operationId: "getUserByName"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "username"
in: "path"
description: "The name that needs to be fetched. Use user1 for testing."
description: "The name that needs to be fetched. Use user1 for testing. "
required: true
type: "string"
responses:
@ -458,8 +545,8 @@ paths:
description: "This can only be done by the logged in user."
operationId: "updateUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "username"
in: "path"
@ -469,7 +556,7 @@ paths:
- in: "body"
name: "body"
description: "Updated user object"
required: false
required: true
schema:
$ref: "#/definitions/User"
responses:
@ -485,8 +572,8 @@ paths:
description: "This can only be done by the logged in user."
operationId: "deleteUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "username"
in: "path"
@ -509,9 +596,46 @@ securityDefinitions:
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
flow: "implicit"
scopes:
write_pets: "modify pets in your account"
read_pets: "read your pets"
write:pets: "modify pets in your account"
read:pets: "read your pets"
definitions:
Order:
type: "object"
properties:
id:
type: "integer"
format: "int64"
petId:
type: "integer"
format: "int64"
quantity:
type: "integer"
format: "int32"
shipDate:
type: "string"
format: "date-time"
status:
type: "string"
description: "Order Status"
enum:
- "placed"
- "approved"
- "delivered"
complete:
type: "boolean"
default: false
xml:
name: "Order"
Category:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Category"
User:
type: "object"
properties:
@ -534,7 +658,9 @@ definitions:
type: "integer"
format: "int32"
description: "User Status"
Category:
xml:
name: "User"
Tag:
type: "object"
properties:
id:
@ -542,6 +668,8 @@ definitions:
format: "int64"
name:
type: "string"
xml:
name: "Tag"
Pet:
type: "object"
required:
@ -558,40 +686,37 @@ definitions:
example: "doggie"
photoUrls:
type: "array"
xml:
name: "photoUrl"
wrapped: true
items:
type: "string"
tags:
type: "array"
xml:
name: "tag"
wrapped: true
items:
$ref: "#/definitions/Tag"
status:
type: "string"
description: "pet status in the store"
Tag:
enum:
- "available"
- "pending"
- "sold"
xml:
name: "Pet"
ApiResponse:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
Order:
type: "object"
properties:
id:
type: "integer"
format: "int64"
petId:
type: "integer"
format: "int64"
quantity:
code:
type: "integer"
format: "int32"
shipDate:
type:
type: "string"
format: "date-time"
status:
message:
type: "string"
description: "Order Status"
complete:
type: "boolean"
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"

View File

@ -33,3 +33,7 @@ module.exports.updatePet = function updatePet (req, res, next) {
module.exports.updatePetWithForm = function updatePetWithForm (req, res, next) {
Pet.updatePetWithForm(req.swagger.params, res, next);
};
module.exports.uploadFile = function uploadFile (req, res, next) {
Pet.uploadFile(req.swagger.params, res, next);
};

View File

@ -12,8 +12,8 @@ exports.addPet = function(args, res, next) {
exports.deletePet = function(args, res, next) {
/**
* parameters expected in the args:
* apiKey (String)
* petId (Long)
* apiKey (String)
**/
// no response value expected for this operation
res.end();
@ -121,7 +121,7 @@ exports.updatePet = function(args, res, next) {
exports.updatePetWithForm = function(args, res, next) {
/**
* parameters expected in the args:
* petId (String)
* petId (Long)
* name (String)
* status (String)
**/
@ -129,3 +129,26 @@ exports.updatePetWithForm = function(args, res, next) {
res.end();
}
exports.uploadFile = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
* additionalMetadata (String)
* file (file)
**/
var examples = {};
examples['application/json'] = {
"message" : "aeiou",
"code" : 123,
"type" : "aeiou"
};
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}

View File

@ -10,6 +10,10 @@ module.exports.deleteOrder = function deleteOrder (req, res, next) {
Store.deleteOrder(req.swagger.params, res, next);
};
module.exports.getInventory = function getInventory (req, res, next) {
Store.getInventory(req.swagger.params, res, next);
};
module.exports.getOrderById = function getOrderById (req, res, next) {
Store.getOrderById(req.swagger.params, res, next);
};

View File

@ -9,10 +9,28 @@ exports.deleteOrder = function(args, res, next) {
res.end();
}
exports.getInventory = function(args, res, next) {
/**
* parameters expected in the args:
**/
var examples = {};
examples['application/json'] = {
"key" : 123
};
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.getOrderById = function(args, res, next) {
/**
* parameters expected in the args:
* orderId (String)
* orderId (Long)
**/
var examples = {};
examples['application/json'] = {

View File

@ -1,7 +1,7 @@
{
"name": "swagger-petstore",
"version": "1.0.0",
"description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n",
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
"main": "index.js",
"keywords": [
"swagger"

View File

@ -2,7 +2,7 @@
## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
[swagger-spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
[OpenAPI-Spec](https://github.com/swagger-api/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:

View File

@ -1,6 +1,6 @@
import com.wordnik.client.api._
import akka.actor.ActorSystem
import io.swagger.app.{ResourcesApp, SwaggerApp}
import io.swagger.app.{ ResourcesApp, SwaggerApp }
import javax.servlet.ServletContext
import org.scalatra.LifeCycle
@ -10,9 +10,9 @@ class ScalatraBootstrap extends LifeCycle {
override def init(context: ServletContext) {
implicit val system = ActorSystem("appActorSystem")
try {
context mount (new UserApi, "/User/*")
context mount (new PetApi, "/Pet/*")
context mount (new StoreApi, "/Store/*")
context mount (new UserApi, "/User/*")
context mount (new ResourcesApp, "/api-docs/*")
} catch {

View File

@ -3,9 +3,9 @@ package io.swagger.app
import _root_.akka.actor.ActorSystem
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.json4s.{DefaultFormats, Formats}
import org.json4s.{ DefaultFormats, Formats }
class ResourcesApp(implicit protected val system: ActorSystem, val swagger: SwaggerApp)
extends ScalatraServlet with JacksonSwaggerBase {
@ -17,7 +17,7 @@ class ResourcesApp(implicit protected val system: ActorSystem, val swagger: Swag
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)
val (proto, host) = if (port != 80 && port != 443) ("http", h + ":" + port.toString) else (prot, h)
"%s://%s%s%s".format(
proto,
host,
@ -31,7 +31,7 @@ class SwaggerApp extends Swagger(apiInfo = ApiSwagger.apiInfo, apiVersion = "1.0
object ApiSwagger {
val apiInfo = ApiInfo(
"""Swagger Petstore""",
"""This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters""",
"""This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.""",
"""""",
"""apiteam@swagger.io""",
"""Apache 2.0""",

View File

@ -1,6 +1,7 @@
package com.wordnik.client.api
import com.wordnik.client.model.Pet
import com.wordnik.client.model.ApiResponse
import java.io.File
import java.io.File
@ -29,156 +30,16 @@ class PetApi (implicit val swagger: Swagger) extends ScalatraServlet
}
val updatePetOperation = (apiOperation[Unit]("updatePet")
summary "Update an existing pet"
parameters(bodyParam[Pet]("body").description("").optional)
)
put("/pet",operation(updatePetOperation)) {
bodyParam[Pet]("body").description("").optional
println("body: " + body)
}
val addPetOperation = (apiOperation[Unit]("addPet")
summary "Add a new pet to the store"
parameters(bodyParam[Pet]("body").description("").optional)
parameters(bodyParam[Pet]("body").description(""))
)
post("/pet",operation(addPetOperation)) {
bodyParam[Pet]("body").description("").optional
bodyParam[Pet]("body").description("")
println("body: " + body)
}
val findPetsByStatusOperation = (apiOperation[List[Pet]]("findPetsByStatus")
summary "Finds Pets by status"
parameters(queryParam[List[String]]("status").description("").optional.defaultValue(available))
)
get("/pet/findByStatus",operation(findPetsByStatusOperation)) {
val statusString = params.getAs[String]("status")
val status = if("multi".equals("default")) {
statusString match {
case Some(str) => str.split(",")
case None => List()
}
}
else
List()
println("status: " + status)
}
val findPetsByTagsOperation = (apiOperation[List[Pet]]("findPetsByTags")
summary "Finds Pets by tags"
parameters(queryParam[List[String]]("tags").description("").optional)
)
get("/pet/findByTags",operation(findPetsByTagsOperation)) {
val tagsString = params.getAs[String]("tags")
val tags = if("multi".equals("default")) {
tagsString match {
case Some(str) => str.split(",")
case None => List()
}
}
else
List()
println("tags: " + tags)
}
val getPetByIdOperation = (apiOperation[Pet]("getPetById")
summary "Find pet by ID"
parameters(pathParam[Long]("petId").description(""))
)
get("/pet/{petId}",operation(getPetByIdOperation)) {
val petId = params.getOrElse("petId", halt(400))
println("petId: " + petId)
}
val updatePetWithFormOperation = (apiOperation[Unit]("updatePetWithForm")
summary "Updates a pet in the store with form data"
parameters(pathParam[String]("petId").description(""),
formParam[String]("name").description("").optional,
formParam[String]("status").description("").optional)
)
post("/pet/{petId}",operation(updatePetWithFormOperation)) {
val petId = params.getOrElse("petId", halt(400))
println("petId: " + petId)
val name = params.getAs[String]("name")
println("name: " + name)
val status = params.getAs[String]("status")
println("status: " + status)
}
@ -192,27 +53,123 @@ bodyParam[Pet]("body").description("").optional
delete("/pet/{petId}",operation(deletePetOperation)) {
val petId = params.getOrElse("petId", halt(400))
println("petId: " + petId)
val apiKey = request.getHeader("apiKey")
println("apiKey: " + apiKey)
}
val uploadFileOperation = (apiOperation[Unit]("uploadFile")
val findPetsByStatusOperation = (apiOperation[List[Pet]]("findPetsByStatus")
summary "Finds Pets by status"
parameters(queryParam[List[String]]("status").description(""))
)
get("/pet/findByStatus",operation(findPetsByStatusOperation)) {
val statusString = params.getAs[String]("status")
val status = if("csv".equals("default")) {
statusString match {
case Some(str) => str.split(",")
case None => List()
}
}
else
List()
println("status: " + status)
}
val findPetsByTagsOperation = (apiOperation[List[Pet]]("findPetsByTags")
summary "Finds Pets by tags"
parameters(queryParam[List[String]]("tags").description(""))
)
get("/pet/findByTags",operation(findPetsByTagsOperation)) {
val tagsString = params.getAs[String]("tags")
val tags = if("csv".equals("default")) {
tagsString match {
case Some(str) => str.split(",")
case None => List()
}
}
else
List()
println("tags: " + tags)
}
val getPetByIdOperation = (apiOperation[Pet]("getPetById")
summary "Find pet by ID"
parameters(pathParam[Long]("petId").description(""))
)
get("/pet/{petId}",operation(getPetByIdOperation)) {
val petId = params.getOrElse("petId", halt(400))
println("petId: " + petId)
}
val updatePetOperation = (apiOperation[Unit]("updatePet")
summary "Update an existing pet"
parameters(bodyParam[Pet]("body").description(""))
)
put("/pet",operation(updatePetOperation)) {
bodyParam[Pet]("body").description("")
println("body: " + body)
}
val updatePetWithFormOperation = (apiOperation[Unit]("updatePetWithForm")
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)
)
post("/pet/{petId}",operation(updatePetWithFormOperation)) {
val petId = params.getOrElse("petId", halt(400))
println("petId: " + petId)
val name = params.getAs[String]("name")
println("name: " + name)
val status = params.getAs[String]("status")
println("status: " + status)
}
val uploadFileOperation = (apiOperation[ApiResponse]("uploadFile")
summary "uploads an image"
parameters(pathParam[Long]("petId").description(""),
formParam[String]("additionalMetadata").description("").optional,
@ -222,26 +179,16 @@ bodyParam[Pet]("body").description("").optional
post("/pet/{petId}/uploadImage",operation(uploadFileOperation)) {
val petId = params.getOrElse("petId", halt(400))
println("petId: " + petId)
val additionalMetadata = params.getAs[String]("additionalMetadata")
println("additionalMetadata: " + additionalMetadata)
val file = fileParams("file")
println("file: " + file)
}
}

View File

@ -9,11 +9,11 @@ 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 org.scalatra.servlet.{ FileUploadSupport, MultipartConfig, SizeConstraintExceededException }
import scala.collection.JavaConverters._
class StoreApi (implicit val swagger: Swagger) extends ScalatraServlet
class StoreApi(implicit val swagger: Swagger) extends ScalatraServlet
with FileUploadSupport
with JacksonJsonSupport
with SwaggerSupport {
@ -27,70 +27,47 @@ class StoreApi (implicit val swagger: Swagger) extends ScalatraServlet
response.headers += ("Access-Control-Allow-Origin" -> "*")
}
val deleteOrderOperation = (apiOperation[Unit]("deleteOrder")
summary "Delete purchase order by ID"
parameters (pathParam[String]("orderId").description(""))
)
delete("/store/order/{orderId}", operation(deleteOrderOperation)) {
val orderId = params.getOrElse("orderId", halt(400))
println("orderId: " + orderId)
}
val getInventoryOperation = (apiOperation[Map[String, Int]]("getInventory")
summary "Returns pet inventories by status"
parameters()
parameters ()
)
get("/store/inventory",operation(getInventoryOperation)) {
get("/store/inventory", operation(getInventoryOperation)) {
}
val placeOrderOperation = (apiOperation[Order]("placeOrder")
summary "Place an order for a pet"
parameters(bodyParam[Order]("body").description("").optional)
)
post("/store/order",operation(placeOrderOperation)) {
bodyParam[Order]("body").description("").optional
println("body: " + body)
}
val getOrderByIdOperation = (apiOperation[Order]("getOrderById")
summary "Find purchase order by ID"
parameters(pathParam[String]("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))
println("orderId: " + orderId)
}
val deleteOrderOperation = (apiOperation[Unit]("deleteOrder")
summary "Delete purchase order by ID"
parameters(pathParam[String]("orderId").description(""))
val placeOrderOperation = (apiOperation[Order]("placeOrder")
summary "Place an order for a pet"
parameters (bodyParam[Order]("body").description(""))
)
delete("/store/order/{orderId}",operation(deleteOrderOperation)) {
val orderId = params.getOrElse("orderId", halt(400))
println("orderId: " + orderId)
post("/store/order", operation(placeOrderOperation)) {
bodyParam[Order]("body").description("")
println("body: " + body)
}
}

View File

@ -9,11 +9,11 @@ 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 org.scalatra.servlet.{ FileUploadSupport, MultipartConfig, SizeConstraintExceededException }
import scala.collection.JavaConverters._
class UserApi (implicit val swagger: Swagger) extends ScalatraServlet
class UserApi(implicit val swagger: Swagger) extends ScalatraServlet
with FileUploadSupport
with JacksonJsonSupport
with SwaggerSupport {
@ -27,165 +27,102 @@ class UserApi (implicit val swagger: Swagger) extends ScalatraServlet
response.headers += ("Access-Control-Allow-Origin" -> "*")
}
val createUserOperation = (apiOperation[Unit]("createUser")
summary "Create user"
parameters(bodyParam[User]("body").description("").optional)
parameters (bodyParam[User]("body").description(""))
)
post("/user",operation(createUserOperation)) {
bodyParam[User]("body").description("").optional
post("/user", operation(createUserOperation)) {
bodyParam[User]("body").description("")
println("body: " + body)
}
val createUsersWithArrayInputOperation = (apiOperation[Unit]("createUsersWithArrayInput")
summary "Creates list of users with given input array"
parameters(bodyParam[List[User]]("body").description("").optional)
parameters (bodyParam[List[User]]("body").description(""))
)
post("/user/createWithArray",operation(createUsersWithArrayInputOperation)) {
bodyParam[List[User]]("body").description("").optional
post("/user/createWithArray", operation(createUsersWithArrayInputOperation)) {
bodyParam[List[User]]("body").description("")
println("body: " + body)
}
val createUsersWithListInputOperation = (apiOperation[Unit]("createUsersWithListInput")
summary "Creates list of users with given input array"
parameters(bodyParam[List[User]]("body").description("").optional)
parameters (bodyParam[List[User]]("body").description(""))
)
post("/user/createWithList",operation(createUsersWithListInputOperation)) {
bodyParam[List[User]]("body").description("").optional
post("/user/createWithList", operation(createUsersWithListInputOperation)) {
bodyParam[List[User]]("body").description("")
println("body: " + body)
}
val loginUserOperation = (apiOperation[String]("loginUser")
summary "Logs user into the system"
parameters(queryParam[String]("username").description("").optional,
queryParam[String]("password").description("").optional)
)
get("/user/login",operation(loginUserOperation)) {
val username = params.getAs[String]("username")
println("username: " + username)
val password = params.getAs[String]("password")
println("password: " + password)
}
val logoutUserOperation = (apiOperation[Unit]("logoutUser")
summary "Logs out current logged in user session"
parameters()
)
get("/user/logout",operation(logoutUserOperation)) {
}
val getUserByNameOperation = (apiOperation[User]("getUserByName")
summary "Get user by user name"
parameters(pathParam[String]("username").description(""))
)
get("/user/{username}",operation(getUserByNameOperation)) {
val username = params.getOrElse("username", halt(400))
println("username: " + username)
}
val updateUserOperation = (apiOperation[Unit]("updateUser")
summary "Updated user"
parameters(pathParam[String]("username").description(""),
bodyParam[User]("body").description("").optional)
)
put("/user/{username}",operation(updateUserOperation)) {
val username = params.getOrElse("username", halt(400))
println("username: " + username)
bodyParam[User]("body").description("").optional
println("body: " + body)
}
val deleteUserOperation = (apiOperation[Unit]("deleteUser")
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))
println("username: " + username)
}
val getUserByNameOperation = (apiOperation[User]("getUserByName")
summary "Get user by user name"
parameters (pathParam[String]("username").description(""))
)
get("/user/{username}", operation(getUserByNameOperation)) {
val username = params.getOrElse("username", halt(400))
println("username: " + username)
}
val loginUserOperation = (apiOperation[String]("loginUser")
summary "Logs user into the system"
parameters (queryParam[String]("username").description(""),
queryParam[String]("password").description(""))
)
get("/user/login", operation(loginUserOperation)) {
val username = params.getAs[String]("username")
println("username: " + username)
val password = params.getAs[String]("password")
println("password: " + password)
}
val logoutUserOperation = (apiOperation[Unit]("logoutUser")
summary "Logs out current logged in user session"
parameters ()
)
get("/user/logout", operation(logoutUserOperation)) {
}
val updateUserOperation = (apiOperation[Unit]("updateUser")
summary "Updated user"
parameters (pathParam[String]("username").description(""),
bodyParam[User]("body").description(""))
)
put("/user/{username}", operation(updateUserOperation)) {
val username = params.getOrElse("username", halt(400))
println("username: " + username)
bodyParam[User]("body").description("")
println("body: " + body)
}
}

View File

@ -1,8 +1,5 @@
package com.wordnik.client.model
case class Category (
id: Long,
name: String
)
case class Category(
id: Option[Long],
name: Option[String])

View File

@ -2,12 +2,10 @@ package com.wordnik.client.model
import java.util.Date
case class Order (
id: Long,
petId: Long,
quantity: Int,
shipDate: Date,
status: String,
complete: Boolean
)
case class Order(
id: Option[Long],
petId: Option[Long],
quantity: Option[Int],
shipDate: Option[Date],
status: Option[String], // Order Status
complete: Option[Boolean])

View File

@ -3,12 +3,11 @@ package com.wordnik.client.model
import com.wordnik.client.model.Category
import com.wordnik.client.model.Tag
case class Pet (
id: Long,
category: Category,
case class Pet(
id: Option[Long],
category: Option[Category],
name: String,
photoUrls: List[String],
tags: List[Tag],
status: String
)
tags: Option[List[Tag]],
status: Option[String] // pet status in the store
)

View File

@ -1,8 +1,5 @@
package com.wordnik.client.model
case class Tag (
id: Long,
name: String
)
case class Tag(
id: Option[Long],
name: Option[String])

View File

@ -1,14 +1,12 @@
package com.wordnik.client.model
case class User (
id: Long,
username: String,
firstName: String,
lastName: String,
email: String,
password: String,
phone: String,
userStatus: Int
)
case class User(
id: Option[Long],
username: Option[String],
firstName: Option[String],
lastName: Option[String],
email: Option[String],
password: Option[String],
phone: Option[String],
userStatus: Option[Int] // User Status
)

View File

@ -8,85 +8,6 @@ use Silex\Application;
$app = new Silex\Application();
$app->POST('/user', function(Application $app, Request $request) {
return new Response('How about implementing createUser as a POST method ?');
});
$app->POST('/user/createWithArray', function(Application $app, Request $request) {
return new Response('How about implementing createUsersWithArrayInput as a POST method ?');
});
$app->POST('/user/createWithList', function(Application $app, Request $request) {
return new Response('How about implementing createUsersWithListInput as a POST method ?');
});
$app->GET('/user/login', function(Application $app, Request $request) {
$username = $request->get('username'); $password = $request->get('password');
return new Response('How about implementing loginUser as a GET method ?');
});
$app->GET('/user/logout', function(Application $app, Request $request) {
return new Response('How about implementing logoutUser as a GET method ?');
});
$app->GET('/user/{username}', function(Application $app, Request $request, $username) {
return new Response('How about implementing getUserByName as a GET method ?');
});
$app->PUT('/user/{username}', function(Application $app, Request $request, $username) {
return new Response('How about implementing updateUser as a PUT method ?');
});
$app->DELETE('/user/{username}', function(Application $app, Request $request, $username) {
return new Response('How about implementing deleteUser as a DELETE method ?');
});
$app->PUT('/pet', function(Application $app, Request $request) {
return new Response('How about implementing updatePet as a PUT method ?');
});
$app->POST('/pet', function(Application $app, Request $request) {
@ -94,39 +15,6 @@ $app->POST('/pet', function(Application $app, Request $request) {
});
$app->GET('/pet/findByStatus', function(Application $app, Request $request) {
$status = $request->get('status');
return new Response('How about implementing findPetsByStatus as a GET method ?');
});
$app->GET('/pet/findByTags', function(Application $app, Request $request) {
$tags = $request->get('tags');
return new Response('How about implementing findPetsByTags as a GET method ?');
});
$app->GET('/pet/{petId}', function(Application $app, Request $request, $pet_id) {
return new Response('How about implementing getPetById as a GET method ?');
});
$app->POST('/pet/{petId}', function(Application $app, Request $request, $pet_id) {
$name = $request->get('name'); $status = $request->get('status');
return new Response('How about implementing updatePetWithForm as a POST method ?');
});
$app->DELETE('/pet/{petId}', function(Application $app, Request $request, $pet_id) {
@ -134,6 +22,40 @@ $app->DELETE('/pet/{petId}', function(Application $app, Request $request, $pet_i
});
$app->GET('/pet/findByStatus', function(Application $app, Request $request) {
$status = $request->get('status');
return new Response('How about implementing findPetsByStatus as a GET method ?');
});
$app->GET('/pet/findByTags', function(Application $app, Request $request) {
$tags = $request->get('tags');
return new Response('How about implementing findPetsByTags as a GET method ?');
});
$app->GET('/pet/{petId}', function(Application $app, Request $request, $pet_id) {
return new Response('How about implementing getPetById as a GET method ?');
});
$app->PUT('/pet', function(Application $app, Request $request) {
return new Response('How about implementing updatePet as a PUT method ?');
});
$app->POST('/pet/{petId}', function(Application $app, Request $request, $pet_id) {
$name = $request->get('name'); $status = $request->get('status');
return new Response('How about implementing updatePetWithForm as a POST method ?');
});
$app->POST('/pet/{petId}/uploadImage', function(Application $app, Request $request, $pet_id) {
@ -142,51 +64,6 @@ $app->POST('/pet/{petId}/uploadImage', function(Application $app, Request $reque
});
$app->GET('/pet/{petId}?testing_byte_array=true', function(Application $app, Request $request, $pet_id) {
return new Response('How about implementing getPetByIdWithByteArray as a GET method ?');
});
$app->POST('/pet?testing_byte_array=true', function(Application $app, Request $request) {
return new Response('How about implementing addPetUsingByteArray as a POST method ?');
});
$app->GET('/store/inventory', function(Application $app, Request $request) {
return new Response('How about implementing getInventory as a GET method ?');
});
$app->POST('/store/order', function(Application $app, Request $request) {
return new Response('How about implementing placeOrder as a POST method ?');
});
$app->GET('/store/order/{orderId}', function(Application $app, Request $request, $order_id) {
return new Response('How about implementing getOrderById as a GET method ?');
});
$app->DELETE('/store/order/{orderId}', function(Application $app, Request $request, $order_id) {
@ -194,7 +71,81 @@ $app->DELETE('/store/order/{orderId}', function(Application $app, Request $reque
});
$app->GET('/store/inventory', function(Application $app, Request $request) {
return new Response('How about implementing getInventory as a GET method ?');
});
$app->GET('/store/order/{orderId}', function(Application $app, Request $request, $order_id) {
return new Response('How about implementing getOrderById as a GET method ?');
});
$app->POST('/store/order', function(Application $app, Request $request) {
return new Response('How about implementing placeOrder as a POST method ?');
});
$app->POST('/user', function(Application $app, Request $request) {
return new Response('How about implementing createUser as a POST method ?');
});
$app->POST('/user/createWithArray', function(Application $app, Request $request) {
return new Response('How about implementing createUsersWithArrayInput as a POST method ?');
});
$app->POST('/user/createWithList', function(Application $app, Request $request) {
return new Response('How about implementing createUsersWithListInput as a POST method ?');
});
$app->DELETE('/user/{username}', function(Application $app, Request $request, $username) {
return new Response('How about implementing deleteUser as a DELETE method ?');
});
$app->GET('/user/{username}', function(Application $app, Request $request, $username) {
return new Response('How about implementing getUserByName as a GET method ?');
});
$app->GET('/user/login', function(Application $app, Request $request) {
$username = $request->get('username'); $password = $request->get('password');
return new Response('How about implementing loginUser as a GET method ?');
});
$app->GET('/user/logout', function(Application $app, Request $request) {
return new Response('How about implementing logoutUser as a GET method ?');
});
$app->PUT('/user/{username}', function(Application $app, Request $request, $username) {
return new Response('How about implementing updateUser as a PUT method ?');
});
$app->run();

View File

@ -1,25 +1,20 @@
require 'json'
MyApp.add_route('POST', '/v2/pets', {
MyApp.add_route('POST', '/v2/pet', {
"resourcePath" => "/Pet",
"summary" => "Add a new pet to the store",
"nickname" => "add_pet",
"responseClass" => "void",
"endpoint" => "/pets",
"endpoint" => "/pet",
"notes" => "",
"parameters" => [
{
"name" => "body",
"description" => "Pet object that needs to be added to the store",
"dataType" => "Pet",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here
@ -28,32 +23,26 @@ MyApp.add_route('POST', '/v2/pets', {
end
MyApp.add_route('DELETE', '/v2/pets/{petId}', {
MyApp.add_route('DELETE', '/v2/pet/{petId}', {
"resourcePath" => "/Pet",
"summary" => "Deletes a pet",
"nickname" => "delete_pet",
"responseClass" => "void",
"endpoint" => "/pets/{petId}",
"endpoint" => "/pet/{petId}",
"notes" => "",
"parameters" => [
{
"name" => "pet_id",
"description" => "Pet id to delete",
"dataType" => "int",
"paramType" => "path",
},
{
"name" => "api_key",
"description" => "",
"dataType" => "string",
"paramType" => "header",
},
]}) do
cross_origin
# the guts live here
@ -62,28 +51,23 @@ MyApp.add_route('DELETE', '/v2/pets/{petId}', {
end
MyApp.add_route('GET', '/v2/pets/findByStatus', {
MyApp.add_route('GET', '/v2/pet/findByStatus', {
"resourcePath" => "/Pet",
"summary" => "Finds Pets by status",
"nickname" => "find_pets_by_status",
"responseClass" => "array[Pet]",
"endpoint" => "/pets/findByStatus",
"notes" => "Multiple status values can be provided with comma seperated strings",
"endpoint" => "/pet/findByStatus",
"notes" => "Multiple status values can be provided with comma separated strings",
"parameters" => [
{
"name" => "status",
"description" => "Status values that need to be considered for filter",
"dataType" => "array[string]",
"paramType" => "query",
"collectionFormat" => "multi",
"collectionFormat" => "csv",
"allowableValues" => "",
},
]}) do
cross_origin
# the guts live here
@ -92,28 +76,23 @@ MyApp.add_route('GET', '/v2/pets/findByStatus', {
end
MyApp.add_route('GET', '/v2/pets/findByTags', {
MyApp.add_route('GET', '/v2/pet/findByTags', {
"resourcePath" => "/Pet",
"summary" => "Finds Pets by tags",
"nickname" => "find_pets_by_tags",
"responseClass" => "array[Pet]",
"endpoint" => "/pets/findByTags",
"notes" => "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
"endpoint" => "/pet/findByTags",
"notes" => "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
"parameters" => [
{
"name" => "tags",
"description" => "Tags to filter by",
"dataType" => "array[string]",
"paramType" => "query",
"collectionFormat" => "multi",
"collectionFormat" => "csv",
"allowableValues" => "",
},
]}) do
cross_origin
# the guts live here
@ -122,25 +101,20 @@ MyApp.add_route('GET', '/v2/pets/findByTags', {
end
MyApp.add_route('GET', '/v2/pets/{petId}', {
MyApp.add_route('GET', '/v2/pet/{petId}', {
"resourcePath" => "/Pet",
"summary" => "Find pet by ID",
"nickname" => "get_pet_by_id",
"responseClass" => "Pet",
"endpoint" => "/pets/{petId}",
"notes" => "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
"endpoint" => "/pet/{petId}",
"notes" => "Returns a single pet",
"parameters" => [
{
"name" => "pet_id",
"description" => "ID of pet that needs to be fetched",
"description" => "ID of pet to return",
"dataType" => "int",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
@ -149,25 +123,20 @@ MyApp.add_route('GET', '/v2/pets/{petId}', {
end
MyApp.add_route('PUT', '/v2/pets', {
MyApp.add_route('PUT', '/v2/pet', {
"resourcePath" => "/Pet",
"summary" => "Update an existing pet",
"nickname" => "update_pet",
"responseClass" => "void",
"endpoint" => "/pets",
"endpoint" => "/pet",
"notes" => "",
"parameters" => [
{
"name" => "body",
"description" => "Pet object that needs to be added to the store",
"dataType" => "Pet",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here
@ -176,25 +145,42 @@ MyApp.add_route('PUT', '/v2/pets', {
end
MyApp.add_route('POST', '/v2/pets/{petId}', {
MyApp.add_route('POST', '/v2/pet/{petId}', {
"resourcePath" => "/Pet",
"summary" => "Updates a pet in the store with form data",
"nickname" => "update_pet_with_form",
"responseClass" => "void",
"endpoint" => "/pets/{petId}",
"endpoint" => "/pet/{petId}",
"notes" => "",
"parameters" => [
{
"name" => "pet_id",
"description" => "ID of pet that needs to be updated",
"dataType" => "string",
"dataType" => "int",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('POST', '/v2/pet/{petId}/uploadImage', {
"resourcePath" => "/Pet",
"summary" => "uploads an image",
"nickname" => "upload_file",
"responseClass" => "ApiResponse",
"endpoint" => "/pet/{petId}/uploadImage",
"notes" => "",
"parameters" => [
{
"name" => "pet_id",
"description" => "ID of pet to update",
"dataType" => "int",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here

View File

@ -1,25 +1,20 @@
require 'json'
MyApp.add_route('DELETE', '/v2/stores/order/{orderId}', {
MyApp.add_route('DELETE', '/v2/store/order/{orderId}', {
"resourcePath" => "/Store",
"summary" => "Delete purchase order by ID",
"nickname" => "delete_order",
"responseClass" => "void",
"endpoint" => "/stores/order/{orderId}",
"endpoint" => "/store/order/{orderId}",
"notes" => "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
"parameters" => [
{
"name" => "order_id",
"description" => "ID of the order that needs to be deleted",
"dataType" => "string",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
@ -28,25 +23,36 @@ MyApp.add_route('DELETE', '/v2/stores/order/{orderId}', {
end
MyApp.add_route('GET', '/v2/stores/order/{orderId}', {
MyApp.add_route('GET', '/v2/store/inventory', {
"resourcePath" => "/Store",
"summary" => "Returns pet inventories by status",
"nickname" => "get_inventory",
"responseClass" => "map[string,int]",
"endpoint" => "/store/inventory",
"notes" => "Returns a map of status codes to quantities",
"parameters" => [
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('GET', '/v2/store/order/{orderId}', {
"resourcePath" => "/Store",
"summary" => "Find purchase order by ID",
"nickname" => "get_order_by_id",
"responseClass" => "Order",
"endpoint" => "/stores/order/{orderId}",
"endpoint" => "/store/order/{orderId}",
"notes" => "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
"parameters" => [
{
"name" => "order_id",
"description" => "ID of pet that needs to be fetched",
"dataType" => "string",
"dataType" => "int",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
@ -55,25 +61,20 @@ MyApp.add_route('GET', '/v2/stores/order/{orderId}', {
end
MyApp.add_route('POST', '/v2/stores/order', {
MyApp.add_route('POST', '/v2/store/order', {
"resourcePath" => "/Store",
"summary" => "Place an order for a pet",
"nickname" => "place_order",
"responseClass" => "Order",
"endpoint" => "/stores/order",
"endpoint" => "/store/order",
"notes" => "",
"parameters" => [
{
"name" => "body",
"description" => "order placed for purchasing the pet",
"dataType" => "Order",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here

View File

@ -1,25 +1,20 @@
require 'json'
MyApp.add_route('POST', '/v2/users', {
MyApp.add_route('POST', '/v2/user', {
"resourcePath" => "/User",
"summary" => "Create user",
"nickname" => "create_user",
"responseClass" => "void",
"endpoint" => "/users",
"endpoint" => "/user",
"notes" => "This can only be done by the logged in user.",
"parameters" => [
{
"name" => "body",
"description" => "Created user object",
"dataType" => "User",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here
@ -28,25 +23,20 @@ MyApp.add_route('POST', '/v2/users', {
end
MyApp.add_route('POST', '/v2/users/createWithArray', {
MyApp.add_route('POST', '/v2/user/createWithArray', {
"resourcePath" => "/User",
"summary" => "Creates list of users with given input array",
"nickname" => "create_users_with_array_input",
"responseClass" => "void",
"endpoint" => "/users/createWithArray",
"endpoint" => "/user/createWithArray",
"notes" => "",
"parameters" => [
{
"name" => "body",
"description" => "List of user object",
"dataType" => "array[User]",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here
@ -55,25 +45,20 @@ MyApp.add_route('POST', '/v2/users/createWithArray', {
end
MyApp.add_route('POST', '/v2/users/createWithList', {
MyApp.add_route('POST', '/v2/user/createWithList', {
"resourcePath" => "/User",
"summary" => "Creates list of users with given input array",
"nickname" => "create_users_with_list_input",
"responseClass" => "void",
"endpoint" => "/users/createWithList",
"endpoint" => "/user/createWithList",
"notes" => "",
"parameters" => [
{
"name" => "body",
"description" => "List of user object",
"dataType" => "array[User]",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here
@ -82,25 +67,20 @@ MyApp.add_route('POST', '/v2/users/createWithList', {
end
MyApp.add_route('DELETE', '/v2/users/{username}', {
MyApp.add_route('DELETE', '/v2/user/{username}', {
"resourcePath" => "/User",
"summary" => "Delete user",
"nickname" => "delete_user",
"responseClass" => "void",
"endpoint" => "/users/{username}",
"endpoint" => "/user/{username}",
"notes" => "This can only be done by the logged in user.",
"parameters" => [
{
"name" => "username",
"description" => "The name that needs to be deleted",
"dataType" => "string",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
@ -109,25 +89,20 @@ MyApp.add_route('DELETE', '/v2/users/{username}', {
end
MyApp.add_route('GET', '/v2/users/{username}', {
MyApp.add_route('GET', '/v2/user/{username}', {
"resourcePath" => "/User",
"summary" => "Get user by user name",
"nickname" => "get_user_by_name",
"responseClass" => "User",
"endpoint" => "/users/{username}",
"endpoint" => "/user/{username}",
"notes" => "",
"parameters" => [
{
"name" => "username",
"description" => "The name that needs to be fetched. Use user1 for testing.",
"description" => "The name that needs to be fetched. Use user1 for testing. ",
"dataType" => "string",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
@ -136,15 +111,14 @@ MyApp.add_route('GET', '/v2/users/{username}', {
end
MyApp.add_route('GET', '/v2/users/login', {
MyApp.add_route('GET', '/v2/user/login', {
"resourcePath" => "/User",
"summary" => "Logs user into the system",
"nickname" => "login_user",
"responseClass" => "string",
"endpoint" => "/users/login",
"endpoint" => "/user/login",
"notes" => "",
"parameters" => [
{
"name" => "username",
"description" => "The user name for login",
@ -154,7 +128,6 @@ MyApp.add_route('GET', '/v2/users/login', {
"allowableValues" => "",
},
{
"name" => "password",
"description" => "The password for login in clear text",
@ -164,10 +137,6 @@ MyApp.add_route('GET', '/v2/users/login', {
"allowableValues" => "",
},
]}) do
cross_origin
# the guts live here
@ -176,18 +145,14 @@ MyApp.add_route('GET', '/v2/users/login', {
end
MyApp.add_route('GET', '/v2/users/logout', {
MyApp.add_route('GET', '/v2/user/logout', {
"resourcePath" => "/User",
"summary" => "Logs out current logged in user session",
"nickname" => "logout_user",
"responseClass" => "void",
"endpoint" => "/users/logout",
"endpoint" => "/user/logout",
"notes" => "",
"parameters" => [
]}) do
cross_origin
# the guts live here
@ -196,32 +161,26 @@ MyApp.add_route('GET', '/v2/users/logout', {
end
MyApp.add_route('PUT', '/v2/users/{username}', {
MyApp.add_route('PUT', '/v2/user/{username}', {
"resourcePath" => "/User",
"summary" => "Updated user",
"nickname" => "update_user",
"responseClass" => "void",
"endpoint" => "/users/{username}",
"endpoint" => "/user/{username}",
"notes" => "This can only be done by the logged in user.",
"parameters" => [
{
"name" => "username",
"description" => "name that need to be deleted",
"dataType" => "string",
"paramType" => "path",
},
{
"name" => "body",
"description" => "Updated user object",
"dataType" => "User",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here

View File

@ -1,23 +1,37 @@
---
swagger: "2.0"
info:
description: "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io)\
\ or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample,\
\ you can use the api key `special-key` to test the authorization filters\n"
description: "This is a sample server Petstore server. You can find out more about\
\ Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\
\ For this sample, you can use the api key `special-key` to test the authorization\
\ filters."
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://helloreverb.com/terms/"
termsOfService: "http://swagger.io/terms/"
contact:
name: "apiteam@swagger.io"
email: "apiteam@swagger.io"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
tags:
- name: "pet"
description: "Everything about your Pets"
externalDocs:
description: "Find out more"
url: "http://swagger.io"
- name: "store"
description: "Access to Petstore orders"
- name: "user"
description: "Operations about user"
externalDocs:
description: "Find out more about our store"
url: "http://swagger.io"
schemes:
- "http"
paths:
/pets:
/pet:
post:
tags:
- "pet"
@ -28,13 +42,13 @@ paths:
- "application/json"
- "application/xml"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: false
required: true
schema:
$ref: "#/definitions/Pet"
responses:
@ -42,8 +56,8 @@ paths:
description: "Invalid input"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
- "write:pets"
- "read:pets"
put:
tags:
- "pet"
@ -54,13 +68,13 @@ paths:
- "application/json"
- "application/xml"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: false
required: true
schema:
$ref: "#/definitions/Pet"
responses:
@ -72,27 +86,32 @@ paths:
description: "Validation exception"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
/pets/findByStatus:
- "write:pets"
- "read:pets"
/pet/findByStatus:
get:
tags:
- "pet"
summary: "Finds Pets by status"
description: "Multiple status values can be provided with comma seperated strings"
description: "Multiple status values can be provided with comma separated strings"
operationId: "findPetsByStatus"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "status"
in: "query"
description: "Status values that need to be considered for filter"
required: false
required: true
type: "array"
items:
type: "string"
collectionFormat: "multi"
default: "available"
enum:
- "available"
- "pending"
- "sold"
collectionFormat: "csv"
responses:
200:
description: "successful operation"
@ -104,28 +123,28 @@ paths:
description: "Invalid status value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
/pets/findByTags:
- "write:pets"
- "read:pets"
/pet/findByTags:
get:
tags:
- "pet"
summary: "Finds Pets by tags"
description: "Muliple tags can be provided with comma seperated strings. Use\
description: "Multiple tags can be provided with comma separated strings. Use\
\ tag1, tag2, tag3 for testing."
operationId: "findPetsByTags"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "tags"
in: "query"
description: "Tags to filter by"
required: false
required: true
type: "array"
items:
type: "string"
collectionFormat: "multi"
collectionFormat: "csv"
responses:
200:
description: "successful operation"
@ -137,23 +156,22 @@ paths:
description: "Invalid tag value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
/pets/{petId}:
- "write:pets"
- "read:pets"
/pet/{petId}:
get:
tags:
- "pet"
summary: "Find pet by ID"
description: "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate\
\ API error conditions"
description: "Returns a single pet"
operationId: "getPetById"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be fetched"
description: "ID of pet to return"
required: true
type: "integer"
format: "int64"
@ -168,9 +186,6 @@ paths:
description: "Pet not found"
security:
- api_key: []
- petstore_auth:
- "write_pets"
- "read_pets"
post:
tags:
- "pet"
@ -180,31 +195,32 @@ paths:
consumes:
- "application/x-www-form-urlencoded"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be updated"
required: true
type: "string"
type: "integer"
format: "int64"
- name: "name"
in: "formData"
description: "Updated name of the pet"
required: true
required: false
type: "string"
- name: "status"
in: "formData"
description: "Updated status of the pet"
required: true
required: false
type: "string"
responses:
405:
description: "Invalid input"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
- "write:pets"
- "read:pets"
delete:
tags:
- "pet"
@ -212,13 +228,12 @@ paths:
description: ""
operationId: "deletePet"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "api_key"
in: "header"
description: ""
required: true
required: false
type: "string"
- name: "petId"
in: "path"
@ -231,9 +246,66 @@ paths:
description: "Invalid pet value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
/stores/order:
- "write:pets"
- "read:pets"
/pet/{petId}/uploadImage:
post:
tags:
- "pet"
summary: "uploads an image"
description: ""
operationId: "uploadFile"
consumes:
- "multipart/form-data"
produces:
- "application/json"
parameters:
- name: "petId"
in: "path"
description: "ID of pet to update"
required: true
type: "integer"
format: "int64"
- name: "additionalMetadata"
in: "formData"
description: "Additional data to pass to server"
required: false
type: "string"
- name: "file"
in: "formData"
description: "file to upload"
required: false
type: "file"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/ApiResponse"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
/store/inventory:
get:
tags:
- "store"
summary: "Returns pet inventories by status"
description: "Returns a map of status codes to quantities"
operationId: "getInventory"
produces:
- "application/json"
parameters: []
responses:
200:
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "integer"
format: "int32"
security:
- api_key: []
/store/order:
post:
tags:
- "store"
@ -241,13 +313,13 @@ paths:
description: ""
operationId: "placeOrder"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "order placed for purchasing the pet"
required: false
required: true
schema:
$ref: "#/definitions/Order"
responses:
@ -257,7 +329,7 @@ paths:
$ref: "#/definitions/Order"
400:
description: "Invalid Order"
/stores/order/{orderId}:
/store/order/{orderId}:
get:
tags:
- "store"
@ -266,14 +338,17 @@ paths:
\ values will generated exceptions"
operationId: "getOrderById"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "orderId"
in: "path"
description: "ID of pet that needs to be fetched"
required: true
type: "string"
type: "integer"
maximum: 5.0
minimum: 1.0
format: "int64"
responses:
200:
description: "successful operation"
@ -291,20 +366,21 @@ paths:
\ above 1000 or nonintegers will generate API errors"
operationId: "deleteOrder"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "orderId"
in: "path"
description: "ID of the order that needs to be deleted"
required: true
type: "string"
minimum: 1.0
responses:
400:
description: "Invalid ID supplied"
404:
description: "Order not found"
/users:
/user:
post:
tags:
- "user"
@ -312,19 +388,19 @@ paths:
description: "This can only be done by the logged in user."
operationId: "createUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Created user object"
required: false
required: true
schema:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
/users/createWithArray:
/user/createWithArray:
post:
tags:
- "user"
@ -332,13 +408,13 @@ paths:
description: ""
operationId: "createUsersWithArrayInput"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: false
required: true
schema:
type: "array"
items:
@ -346,7 +422,7 @@ paths:
responses:
default:
description: "successful operation"
/users/createWithList:
/user/createWithList:
post:
tags:
- "user"
@ -354,13 +430,13 @@ paths:
description: ""
operationId: "createUsersWithListInput"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: false
required: true
schema:
type: "array"
items:
@ -368,7 +444,7 @@ paths:
responses:
default:
description: "successful operation"
/users/login:
/user/login:
get:
tags:
- "user"
@ -376,27 +452,36 @@ paths:
description: ""
operationId: "loginUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "username"
in: "query"
description: "The user name for login"
required: false
required: true
type: "string"
- name: "password"
in: "query"
description: "The password for login in clear text"
required: false
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "string"
headers:
X-Rate-Limit:
type: "integer"
format: "int32"
description: "calls per hour allowed by the user"
X-Expires-After:
type: "string"
format: "date-time"
description: "date in UTC when toekn expires"
400:
description: "Invalid username/password supplied"
/users/logout:
/user/logout:
get:
tags:
- "user"
@ -404,13 +489,13 @@ paths:
description: ""
operationId: "logoutUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters: []
responses:
default:
description: "successful operation"
/users/{username}:
/user/{username}:
get:
tags:
- "user"
@ -418,12 +503,12 @@ paths:
description: ""
operationId: "getUserByName"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "username"
in: "path"
description: "The name that needs to be fetched. Use user1 for testing."
description: "The name that needs to be fetched. Use user1 for testing. "
required: true
type: "string"
responses:
@ -442,8 +527,8 @@ paths:
description: "This can only be done by the logged in user."
operationId: "updateUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "username"
in: "path"
@ -453,7 +538,7 @@ paths:
- in: "body"
name: "body"
description: "Updated user object"
required: false
required: true
schema:
$ref: "#/definitions/User"
responses:
@ -468,8 +553,8 @@ paths:
description: "This can only be done by the logged in user."
operationId: "deleteUser"
produces:
- "application/json"
- "application/xml"
- "application/json"
parameters:
- name: "username"
in: "path"
@ -491,9 +576,46 @@ securityDefinitions:
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
flow: "implicit"
scopes:
write_pets: "modify pets in your account"
read_pets: "read your pets"
write:pets: "modify pets in your account"
read:pets: "read your pets"
definitions:
Order:
type: "object"
properties:
id:
type: "integer"
format: "int64"
petId:
type: "integer"
format: "int64"
quantity:
type: "integer"
format: "int32"
shipDate:
type: "string"
format: "date-time"
status:
type: "string"
description: "Order Status"
enum:
- "placed"
- "approved"
- "delivered"
complete:
type: "boolean"
default: false
xml:
name: "Order"
Category:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Category"
User:
type: "object"
properties:
@ -516,7 +638,9 @@ definitions:
type: "integer"
format: "int32"
description: "User Status"
Category:
xml:
name: "User"
Tag:
type: "object"
properties:
id:
@ -524,6 +648,8 @@ definitions:
format: "int64"
name:
type: "string"
xml:
name: "Tag"
Pet:
type: "object"
required:
@ -540,40 +666,37 @@ definitions:
example: "doggie"
photoUrls:
type: "array"
xml:
name: "photoUrl"
wrapped: true
items:
type: "string"
tags:
type: "array"
xml:
name: "tag"
wrapped: true
items:
$ref: "#/definitions/Tag"
status:
type: "string"
description: "pet status in the store"
Tag:
enum:
- "available"
- "pending"
- "sold"
xml:
name: "Pet"
ApiResponse:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
Order:
type: "object"
properties:
id:
type: "integer"
format: "int64"
petId:
type: "integer"
format: "int64"
quantity:
code:
type: "integer"
format: "int32"
shipDate:
type:
type: "string"
format: "date-time"
status:
message:
type: "string"
description: "Order Status"
complete:
type: "boolean"
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"

View File

@ -9,11 +9,205 @@ require_once __DIR__ . '/vendor/autoload.php';
$app = new Slim\App();
/**
* POST addPet
* Summary: Add a new pet to the store
* Notes:
* Output-Formats: [application/xml, application/json]
*/
$app->POST('/pet', function($request, $response, $args) {
$body = $request->getParsedBody();
$response->write('How about implementing addPet as a POST method ?');
return $response;
});
/**
* DELETE deletePet
* Summary: Deletes a pet
* Notes:
* Output-Formats: [application/xml, application/json]
*/
$app->DELETE('/pet/{petId}', function($request, $response, $args) {
$headers = $request->getHeaders();
$response->write('How about implementing deletePet as a DELETE method ?');
return $response;
});
/**
* GET findPetsByStatus
* Summary: Finds Pets by status
* Notes: Multiple status values can be provided with comma separated strings
* Output-Formats: [application/xml, application/json]
*/
$app->GET('/pet/findByStatus', function($request, $response, $args) {
$queryParams = $request->getQueryParams();
$status = $queryParams['status'];
$response->write('How about implementing findPetsByStatus as a GET method ?');
return $response;
});
/**
* GET findPetsByTags
* Summary: Finds Pets by tags
* Notes: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* Output-Formats: [application/xml, application/json]
*/
$app->GET('/pet/findByTags', function($request, $response, $args) {
$queryParams = $request->getQueryParams();
$tags = $queryParams['tags'];
$response->write('How about implementing findPetsByTags as a GET method ?');
return $response;
});
/**
* GET getPetById
* Summary: Find pet by ID
* Notes: Returns a single pet
* Output-Formats: [application/xml, application/json]
*/
$app->GET('/pet/{petId}', function($request, $response, $args) {
$response->write('How about implementing getPetById as a GET method ?');
return $response;
});
/**
* PUT updatePet
* Summary: Update an existing pet
* Notes:
* Output-Formats: [application/xml, application/json]
*/
$app->PUT('/pet', function($request, $response, $args) {
$body = $request->getParsedBody();
$response->write('How about implementing updatePet as a PUT method ?');
return $response;
});
/**
* POST updatePetWithForm
* Summary: Updates a pet in the store with form data
* Notes:
* Output-Formats: [application/xml, application/json]
*/
$app->POST('/pet/{petId}', function($request, $response, $args) {
$name = $args['name']; $status = $args['status'];
$response->write('How about implementing updatePetWithForm as a POST method ?');
return $response;
});
/**
* POST uploadFile
* Summary: uploads an image
* Notes:
* Output-Formats: [application/json]
*/
$app->POST('/pet/{petId}/uploadImage', function($request, $response, $args) {
$additionalMetadata = $args['additionalMetadata']; $file = $args['file'];
$response->write('How about implementing uploadFile as a POST method ?');
return $response;
});
/**
* DELETE deleteOrder
* Summary: Delete purchase order by ID
* Notes: For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
* Output-Formats: [application/xml, application/json]
*/
$app->DELETE('/store/order/{orderId}', function($request, $response, $args) {
$response->write('How about implementing deleteOrder as a DELETE method ?');
return $response;
});
/**
* GET getInventory
* Summary: Returns pet inventories by status
* Notes: Returns a map of status codes to quantities
* Output-Formats: [application/json]
*/
$app->GET('/store/inventory', function($request, $response, $args) {
$response->write('How about implementing getInventory as a GET method ?');
return $response;
});
/**
* GET getOrderById
* Summary: Find purchase order by ID
* Notes: For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
* Output-Formats: [application/xml, application/json]
*/
$app->GET('/store/order/{orderId}', function($request, $response, $args) {
$response->write('How about implementing getOrderById as a GET method ?');
return $response;
});
/**
* POST placeOrder
* Summary: Place an order for a pet
* Notes:
* Output-Formats: [application/xml, application/json]
*/
$app->POST('/store/order', function($request, $response, $args) {
$body = $request->getParsedBody();
$response->write('How about implementing placeOrder as a POST method ?');
return $response;
});
/**
* POST createUser
* Summary: Create user
* Notes: This can only be done by the logged in user.
* Output-Formats: [application/json, application/xml]
* Output-Formats: [application/xml, application/json]
*/
$app->POST('/user', function($request, $response, $args) {
@ -29,7 +223,7 @@ $app->POST('/user', function($request, $response, $args) {
* POST createUsersWithArrayInput
* Summary: Creates list of users with given input array
* Notes:
* Output-Formats: [application/json, application/xml]
* Output-Formats: [application/xml, application/json]
*/
$app->POST('/user/createWithArray', function($request, $response, $args) {
@ -45,7 +239,7 @@ $app->POST('/user/createWithArray', function($request, $response, $args) {
* POST createUsersWithListInput
* Summary: Creates list of users with given input array
* Notes:
* Output-Formats: [application/json, application/xml]
* Output-Formats: [application/xml, application/json]
*/
$app->POST('/user/createWithList', function($request, $response, $args) {
@ -57,11 +251,43 @@ $app->POST('/user/createWithList', function($request, $response, $args) {
});
/**
* DELETE deleteUser
* Summary: Delete user
* Notes: This can only be done by the logged in user.
* Output-Formats: [application/xml, application/json]
*/
$app->DELETE('/user/{username}', function($request, $response, $args) {
$response->write('How about implementing deleteUser as a DELETE method ?');
return $response;
});
/**
* GET getUserByName
* Summary: Get user by user name
* Notes:
* Output-Formats: [application/xml, application/json]
*/
$app->GET('/user/{username}', function($request, $response, $args) {
$response->write('How about implementing getUserByName as a GET method ?');
return $response;
});
/**
* GET loginUser
* Summary: Logs user into the system
* Notes:
* Output-Formats: [application/json, application/xml]
* Output-Formats: [application/xml, application/json]
*/
$app->GET('/user/login', function($request, $response, $args) {
@ -78,7 +304,7 @@ $app->GET('/user/login', function($request, $response, $args) {
* GET logoutUser
* Summary: Logs out current logged in user session
* Notes:
* Output-Formats: [application/json, application/xml]
* Output-Formats: [application/xml, application/json]
*/
$app->GET('/user/logout', function($request, $response, $args) {
@ -90,27 +316,11 @@ $app->GET('/user/logout', function($request, $response, $args) {
});
/**
* GET getUserByName
* Summary: Get user by user name
* Notes:
* Output-Formats: [application/json, application/xml]
*/
$app->GET('/user/{username}', function($request, $response, $args) {
$response->write('How about implementing getUserByName as a GET method ?');
return $response;
});
/**
* PUT updateUser
* Summary: Updated user
* Notes: This can only be done by the logged in user.
* Output-Formats: [application/json, application/xml]
* Output-Formats: [application/xml, application/json]
*/
$app->PUT('/user/{username}', function($request, $response, $args) {
@ -122,247 +332,5 @@ $app->PUT('/user/{username}', function($request, $response, $args) {
});
/**
* DELETE deleteUser
* Summary: Delete user
* Notes: This can only be done by the logged in user.
* Output-Formats: [application/json, application/xml]
*/
$app->DELETE('/user/{username}', function($request, $response, $args) {
$response->write('How about implementing deleteUser as a DELETE method ?');
return $response;
});
/**
* PUT updatePet
* Summary: Update an existing pet
* Notes:
* Output-Formats: [application/json, application/xml]
*/
$app->PUT('/pet', function($request, $response, $args) {
$body = $request->getParsedBody();
$response->write('How about implementing updatePet as a PUT method ?');
return $response;
});
/**
* POST addPet
* Summary: Add a new pet to the store
* Notes:
* Output-Formats: [application/json, application/xml]
*/
$app->POST('/pet', function($request, $response, $args) {
$body = $request->getParsedBody();
$response->write('How about implementing addPet as a POST method ?');
return $response;
});
/**
* GET findPetsByStatus
* Summary: Finds Pets by status
* Notes: Multiple status values can be provided with comma seperated strings
* Output-Formats: [application/json, application/xml]
*/
$app->GET('/pet/findByStatus', function($request, $response, $args) {
$queryParams = $request->getQueryParams();
$status = $queryParams['status'];
$response->write('How about implementing findPetsByStatus as a GET method ?');
return $response;
});
/**
* GET findPetsByTags
* Summary: Finds Pets by tags
* Notes: Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
* Output-Formats: [application/json, application/xml]
*/
$app->GET('/pet/findByTags', function($request, $response, $args) {
$queryParams = $request->getQueryParams();
$tags = $queryParams['tags'];
$response->write('How about implementing findPetsByTags as a GET method ?');
return $response;
});
/**
* GET getPetById
* Summary: Find pet by ID
* Notes: Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* Output-Formats: [application/json, application/xml]
*/
$app->GET('/pet/{petId}', function($request, $response, $args) {
$response->write('How about implementing getPetById as a GET method ?');
return $response;
});
/**
* POST updatePetWithForm
* Summary: Updates a pet in the store with form data
* Notes:
* Output-Formats: [application/json, application/xml]
*/
$app->POST('/pet/{petId}', function($request, $response, $args) {
$name = $args['name']; $status = $args['status'];
$response->write('How about implementing updatePetWithForm as a POST method ?');
return $response;
});
/**
* DELETE deletePet
* Summary: Deletes a pet
* Notes:
* Output-Formats: [application/json, application/xml]
*/
$app->DELETE('/pet/{petId}', function($request, $response, $args) {
$headers = $request->getHeaders();
$response->write('How about implementing deletePet as a DELETE method ?');
return $response;
});
/**
* POST uploadFile
* Summary: uploads an image
* Notes:
* Output-Formats: [application/json, application/xml]
*/
$app->POST('/pet/{petId}/uploadImage', function($request, $response, $args) {
$additionalMetadata = $args['additionalMetadata']; $file = $args['file'];
$response->write('How about implementing uploadFile as a POST method ?');
return $response;
});
/**
* GET getPetByIdWithByteArray
* Summary: Fake endpoint to test byte array return by &#39;Find pet by ID&#39;
* Notes: Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* Output-Formats: [application/json, application/xml]
*/
$app->GET('/pet/{petId}?testing_byte_array=true', function($request, $response, $args) {
$response->write('How about implementing getPetByIdWithByteArray as a GET method ?');
return $response;
});
/**
* POST addPetUsingByteArray
* Summary: Fake endpoint to test byte array in body parameter for adding a new pet to the store
* Notes:
* Output-Formats: [application/json, application/xml]
*/
$app->POST('/pet?testing_byte_array=true', function($request, $response, $args) {
$body = $request->getParsedBody();
$response->write('How about implementing addPetUsingByteArray as a POST method ?');
return $response;
});
/**
* GET getInventory
* Summary: Returns pet inventories by status
* Notes: Returns a map of status codes to quantities
* Output-Formats: [application/json, application/xml]
*/
$app->GET('/store/inventory', function($request, $response, $args) {
$response->write('How about implementing getInventory as a GET method ?');
return $response;
});
/**
* POST placeOrder
* Summary: Place an order for a pet
* Notes:
* Output-Formats: [application/json, application/xml]
*/
$app->POST('/store/order', function($request, $response, $args) {
$body = $request->getParsedBody();
$response->write('How about implementing placeOrder as a POST method ?');
return $response;
});
/**
* GET getOrderById
* Summary: Find purchase order by ID
* Notes: For valid response try integer IDs with value &lt;= 5 or &gt; 10. Other values will generated exceptions
* Output-Formats: [application/json, application/xml]
*/
$app->GET('/store/order/{orderId}', function($request, $response, $args) {
$response->write('How about implementing getOrderById as a GET method ?');
return $response;
});
/**
* DELETE deleteOrder
* Summary: Delete purchase order by ID
* Notes: For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
* Output-Formats: [application/json, application/xml]
*/
$app->DELETE('/store/order/{orderId}', function($request, $response, $args) {
$response->write('How about implementing deleteOrder as a DELETE method ?');
return $response;
});
$app->run();