update nodejs server sample

This commit is contained in:
wing328
2016-04-09 18:12:46 +08:00
parent 64b01f7800
commit 35edb00e9b
17 changed files with 127 additions and 1464 deletions

View File

@@ -1,24 +0,0 @@
# Swagger generated server
## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. This is an example of building a node.js server.
This example uses the [expressjs](http://expressjs.com/) framework. To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)
### Running the server
To run the server, follow these simple steps:
```
npm install
node .
```
To view the Swagger UI interface:
```
open http://localhost:8080/docs
```
This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work.

View File

@@ -1,597 +0,0 @@
---
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"
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://helloreverb.com/terms/"
contact:
name: "apiteam@swagger.io"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
schemes:
- "http"
paths:
/pets:
post:
tags:
- "pet"
summary: "Add a new pet to the store"
description: ""
operationId: "addPet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: false
schema:
$ref: "#/definitions/Pet"
responses:
405:
description: "Invalid input"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
put:
tags:
- "pet"
summary: "Update an existing pet"
description: ""
operationId: "updatePet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: false
schema:
$ref: "#/definitions/Pet"
responses:
400:
description: "Invalid ID supplied"
404:
description: "Pet not found"
405:
description: "Validation exception"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
/pets/findByStatus:
get:
tags:
- "pet"
summary: "Finds Pets by status"
description: "Multiple status values can be provided with comma seperated strings"
operationId: "findPetsByStatus"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "status"
in: "query"
description: "Status values that need to be considered for filter"
required: false
type: "array"
items:
type: "string"
collectionFormat: "multi"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/Pet"
400:
description: "Invalid status value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
/pets/findByTags:
get:
tags:
- "pet"
summary: "Finds Pets by tags"
description: "Muliple tags can be provided with comma seperated strings. Use\
\ tag1, tag2, tag3 for testing."
operationId: "findPetsByTags"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "tags"
in: "query"
description: "Tags to filter by"
required: false
type: "array"
items:
type: "string"
collectionFormat: "multi"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/Pet"
400:
description: "Invalid tag value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
/pets/{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"
operationId: "getPetById"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be fetched"
required: true
type: "integer"
format: "int64"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/Pet"
400:
description: "Invalid ID supplied"
404:
description: "Pet not found"
security:
- api_key: []
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
post:
tags:
- "pet"
summary: "Updates a pet in the store with form data"
description: ""
operationId: "updatePetWithForm"
consumes:
- "application/x-www-form-urlencoded"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be updated"
required: true
type: "string"
- name: "name"
in: "formData"
description: "Updated name of the pet"
required: true
type: "string"
- name: "status"
in: "formData"
description: "Updated status of the pet"
required: true
type: "string"
responses:
405:
description: "Invalid input"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
delete:
tags:
- "pet"
summary: "Deletes a pet"
description: ""
operationId: "deletePet"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "api_key"
in: "header"
description: ""
required: true
type: "string"
- name: "petId"
in: "path"
description: "Pet id to delete"
required: true
type: "integer"
format: "int64"
responses:
400:
description: "Invalid pet value"
security:
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
/stores/order:
post:
tags:
- "store"
summary: "Place an order for a pet"
description: ""
operationId: "placeOrder"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "order placed for purchasing the pet"
required: false
schema:
$ref: "#/definitions/Order"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/Order"
400:
description: "Invalid Order"
x-swagger-router-controller: "Store"
/stores/order/{orderId}:
get:
tags:
- "store"
summary: "Find purchase order by ID"
description: "For valid response try integer IDs with value <= 5 or > 10. Other\
\ values will generated exceptions"
operationId: "getOrderById"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "orderId"
in: "path"
description: "ID of pet that needs to be fetched"
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/Order"
400:
description: "Invalid ID supplied"
404:
description: "Order not found"
x-swagger-router-controller: "Store"
delete:
tags:
- "store"
summary: "Delete purchase order by ID"
description: "For valid response try integer IDs with value < 1000. Anything\
\ above 1000 or nonintegers will generate API errors"
operationId: "deleteOrder"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "orderId"
in: "path"
description: "ID of the order that needs to be deleted"
required: true
type: "string"
responses:
400:
description: "Invalid ID supplied"
404:
description: "Order not found"
x-swagger-router-controller: "Store"
/users:
post:
tags:
- "user"
summary: "Create user"
description: "This can only be done by the logged in user."
operationId: "createUser"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Created user object"
required: false
schema:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/users/createWithArray:
post:
tags:
- "user"
summary: "Creates list of users with given input array"
description: ""
operationId: "createUsersWithArrayInput"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: false
schema:
type: "array"
items:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/users/createWithList:
post:
tags:
- "user"
summary: "Creates list of users with given input array"
description: ""
operationId: "createUsersWithListInput"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: false
schema:
type: "array"
items:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/users/login:
get:
tags:
- "user"
summary: "Logs user into the system"
description: ""
operationId: "loginUser"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "query"
description: "The user name for login"
required: false
type: "string"
- name: "password"
in: "query"
description: "The password for login in clear text"
required: false
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "string"
400:
description: "Invalid username/password supplied"
x-swagger-router-controller: "User"
/users/logout:
get:
tags:
- "user"
summary: "Logs out current logged in user session"
description: ""
operationId: "logoutUser"
produces:
- "application/json"
- "application/xml"
parameters: []
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/users/{username}:
get:
tags:
- "user"
summary: "Get user by user name"
description: ""
operationId: "getUserByName"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "The name that needs to be fetched. Use user1 for testing."
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/User"
400:
description: "Invalid username supplied"
404:
description: "User not found"
x-swagger-router-controller: "User"
put:
tags:
- "user"
summary: "Updated user"
description: "This can only be done by the logged in user."
operationId: "updateUser"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "name that need to be deleted"
required: true
type: "string"
- in: "body"
name: "body"
description: "Updated user object"
required: false
schema:
$ref: "#/definitions/User"
responses:
400:
description: "Invalid user supplied"
404:
description: "User not found"
x-swagger-router-controller: "User"
delete:
tags:
- "user"
summary: "Delete user"
description: "This can only be done by the logged in user."
operationId: "deleteUser"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "The name that needs to be deleted"
required: true
type: "string"
responses:
400:
description: "Invalid username supplied"
404:
description: "User not found"
x-swagger-router-controller: "User"
securityDefinitions:
api_key:
type: "apiKey"
name: "api_key"
in: "header"
petstore_auth:
type: "oauth2"
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
flow: "implicit"
scopes:
write_pets: "modify pets in your account"
read_pets: "read your pets"
definitions:
User:
type: "object"
properties:
id:
type: "integer"
format: "int64"
username:
type: "string"
firstName:
type: "string"
lastName:
type: "string"
email:
type: "string"
password:
type: "string"
phone:
type: "string"
userStatus:
type: "integer"
format: "int32"
description: "User Status"
Category:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
Pet:
type: "object"
required:
- "name"
- "photoUrls"
properties:
id:
type: "integer"
format: "int64"
category:
$ref: "#/definitions/Category"
name:
type: "string"
example: "doggie"
photoUrls:
type: "array"
items:
type: "string"
tags:
type: "array"
items:
$ref: "#/definitions/Tag"
status:
type: "string"
description: "pet status in the store"
Tag:
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:
type: "integer"
format: "int32"
shipDate:
type: "string"
format: "date-time"
status:
type: "string"
description: "Order Status"
complete:
type: "boolean"

View File

@@ -1,35 +0,0 @@
'use strict';
var url = require('url');
var Pet = require('./PetService');
module.exports.addPet = function addPet (req, res, next) {
Pet.addPet(req.swagger.params, res, next);
};
module.exports.deletePet = function deletePet (req, res, next) {
Pet.deletePet(req.swagger.params, res, next);
};
module.exports.findPetsByStatus = function findPetsByStatus (req, res, next) {
Pet.findPetsByStatus(req.swagger.params, res, next);
};
module.exports.findPetsByTags = function findPetsByTags (req, res, next) {
Pet.findPetsByTags(req.swagger.params, res, next);
};
module.exports.getPetById = function getPetById (req, res, next) {
Pet.getPetById(req.swagger.params, res, next);
};
module.exports.updatePet = function updatePet (req, res, next) {
Pet.updatePet(req.swagger.params, res, next);
};
module.exports.updatePetWithForm = function updatePetWithForm (req, res, next) {
Pet.updatePetWithForm(req.swagger.params, res, next);
};

View File

@@ -1,151 +0,0 @@
'use strict';
exports.addPet = function(args, res, next) {
/**
* parameters expected in the args:
* body (Pet)
**/
// no response value expected for this operation
res.end();
}
exports.deletePet = function(args, res, next) {
/**
* parameters expected in the args:
* apiKey (String)
* petId (Long)
**/
// no response value expected for this operation
res.end();
}
exports.findPetsByStatus = function(args, res, next) {
/**
* parameters expected in the args:
* status (List)
**/
var examples = {};
examples['application/json'] = [ {
"tags" : [ {
"id" : 123456789,
"name" : "aeiou"
} ],
"id" : 123456789,
"category" : {
"id" : 123456789,
"name" : "aeiou"
},
"status" : "aeiou",
"name" : "doggie",
"photoUrls" : [ "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();
}
}
exports.findPetsByTags = function(args, res, next) {
/**
* parameters expected in the args:
* tags (List)
**/
var examples = {};
examples['application/json'] = [ {
"tags" : [ {
"id" : 123456789,
"name" : "aeiou"
} ],
"id" : 123456789,
"category" : {
"id" : 123456789,
"name" : "aeiou"
},
"status" : "aeiou",
"name" : "doggie",
"photoUrls" : [ "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();
}
}
exports.getPetById = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
**/
var examples = {};
examples['application/json'] = {
"tags" : [ {
"id" : 123456789,
"name" : "aeiou"
} ],
"id" : 123456789,
"category" : {
"id" : 123456789,
"name" : "aeiou"
},
"status" : "aeiou",
"name" : "doggie",
"photoUrls" : [ "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();
}
}
exports.updatePet = function(args, res, next) {
/**
* parameters expected in the args:
* body (Pet)
**/
// no response value expected for this operation
res.end();
}
exports.updatePetWithForm = function(args, res, next) {
/**
* parameters expected in the args:
* petId (String)
* name (String)
* status (String)
**/
// no response value expected for this operation
res.end();
}

View File

@@ -1,19 +0,0 @@
'use strict';
var url = require('url');
var Store = require('./StoreService');
module.exports.deleteOrder = function deleteOrder (req, res, next) {
Store.deleteOrder(req.swagger.params, res, next);
};
module.exports.getOrderById = function getOrderById (req, res, next) {
Store.getOrderById(req.swagger.params, res, next);
};
module.exports.placeOrder = function placeOrder (req, res, next) {
Store.placeOrder(req.swagger.params, res, next);
};

View File

@@ -1,69 +0,0 @@
'use strict';
exports.deleteOrder = function(args, res, next) {
/**
* parameters expected in the args:
* orderId (String)
**/
// no response value expected for this operation
res.end();
}
exports.getOrderById = function(args, res, next) {
/**
* parameters expected in the args:
* orderId (String)
**/
var examples = {};
examples['application/json'] = {
"id" : 123456789,
"petId" : 123456789,
"complete" : true,
"status" : "aeiou",
"quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+0000"
};
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.placeOrder = function(args, res, next) {
/**
* parameters expected in the args:
* body (Order)
**/
var examples = {};
examples['application/json'] = {
"id" : 123456789,
"petId" : 123456789,
"complete" : true,
"status" : "aeiou",
"quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+0000"
};
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

@@ -1,39 +0,0 @@
'use strict';
var url = require('url');
var User = require('./UserService');
module.exports.createUser = function createUser (req, res, next) {
User.createUser(req.swagger.params, res, next);
};
module.exports.createUsersWithArrayInput = function createUsersWithArrayInput (req, res, next) {
User.createUsersWithArrayInput(req.swagger.params, res, next);
};
module.exports.createUsersWithListInput = function createUsersWithListInput (req, res, next) {
User.createUsersWithListInput(req.swagger.params, res, next);
};
module.exports.deleteUser = function deleteUser (req, res, next) {
User.deleteUser(req.swagger.params, res, next);
};
module.exports.getUserByName = function getUserByName (req, res, next) {
User.getUserByName(req.swagger.params, res, next);
};
module.exports.loginUser = function loginUser (req, res, next) {
User.loginUser(req.swagger.params, res, next);
};
module.exports.logoutUser = function logoutUser (req, res, next) {
User.logoutUser(req.swagger.params, res, next);
};
module.exports.updateUser = function updateUser (req, res, next) {
User.updateUser(req.swagger.params, res, next);
};

View File

@@ -1,120 +0,0 @@
'use strict';
exports.createUser = function(args, res, next) {
/**
* parameters expected in the args:
* body (User)
**/
// no response value expected for this operation
res.end();
}
exports.createUsersWithArrayInput = function(args, res, next) {
/**
* parameters expected in the args:
* body (List)
**/
// no response value expected for this operation
res.end();
}
exports.createUsersWithListInput = function(args, res, next) {
/**
* parameters expected in the args:
* body (List)
**/
// no response value expected for this operation
res.end();
}
exports.deleteUser = function(args, res, next) {
/**
* parameters expected in the args:
* username (String)
**/
// no response value expected for this operation
res.end();
}
exports.getUserByName = function(args, res, next) {
/**
* parameters expected in the args:
* username (String)
**/
var examples = {};
examples['application/json'] = {
"id" : 123456789,
"lastName" : "aeiou",
"phone" : "aeiou",
"username" : "aeiou",
"email" : "aeiou",
"userStatus" : 123,
"firstName" : "aeiou",
"password" : "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();
}
}
exports.loginUser = function(args, res, next) {
/**
* parameters expected in the args:
* username (String)
* password (String)
**/
var examples = {};
examples['application/json'] = "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();
}
}
exports.logoutUser = function(args, res, next) {
/**
* parameters expected in the args:
**/
// no response value expected for this operation
res.end();
}
exports.updateUser = function(args, res, next) {
/**
* parameters expected in the args:
* username (String)
* body (User)
**/
// no response value expected for this operation
res.end();
}

View File

@@ -1,40 +0,0 @@
'use strict';
var app = require('connect')();
var http = require('http');
var swaggerTools = require('swagger-tools');
var jsyaml = require('js-yaml');
var fs = require('fs');
var serverPort = 8080;
// swaggerRouter configuration
var options = {
swaggerUi: '/swagger.json',
controllers: './controllers',
useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)
};
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
var spec = fs.readFileSync('./api/swagger.yaml', 'utf8');
var swaggerDoc = jsyaml.safeLoad(spec);
// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
app.use(middleware.swaggerMetadata());
// Validate Swagger requests
app.use(middleware.swaggerValidator());
// Route validated requests to appropriate controller
app.use(middleware.swaggerRouter(options));
// Serve the Swagger documents and Swagger UI
app.use(middleware.swaggerUi());
// Start the server
http.createServer(app).listen(serverPort, function () {
console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
});
});

View File

@@ -1,16 +0,0 @@
{
"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",
"main": "index.js",
"keywords": [
"swagger"
],
"license": "MIT",
"private": true,
"dependencies": {
"connect": "^3.2.0",
"js-yaml": "^3.3.0",
"swagger-tools": "0.9.*"
}
}

View File

@@ -1,53 +1,40 @@
---
swagger: "2.0"
info:
description: "This is a sample server Petstore server. You can find out more about\n\
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\n\
For this sample, you can use the api key `special-key` to test the authorization\
\ filters.\n"
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"
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/"
termsOfService: "http://helloreverb.com/terms/"
contact:
email: "apiteam@swagger.io"
name: "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:
/pet:
/pets:
post:
tags:
- "pet"
summary: "Add a new pet to the store"
description: ""
operationId: "addPet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
required: false
schema:
$ref: "#/definitions/Pet"
responses:
@@ -55,25 +42,26 @@ paths:
description: "Invalid input"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
put:
tags:
- "pet"
summary: "Update an existing pet"
description: ""
operationId: "updatePet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
required: false
schema:
$ref: "#/definitions/Pet"
responses:
@@ -85,32 +73,27 @@ paths:
description: "Validation exception"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
/pet/findByStatus:
/pets/findByStatus:
get:
tags:
- "pet"
summary: "Finds Pets by status"
description: "Multiple status values can be provided with comma separated strings"
description: "Multiple status values can be provided with comma seperated strings"
operationId: "findPetsByStatus"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "status"
in: "query"
description: "Status values that need to be considered for filter"
required: true
required: false
type: "array"
items:
type: "string"
default: "available"
enum:
- "available"
- "pending"
- "sold"
collectionFormat: "multi"
responses:
200:
@@ -123,25 +106,25 @@ paths:
description: "Invalid status value"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
/pet/findByTags:
/pets/findByTags:
get:
tags:
- "pet"
summary: "Finds Pets by tags"
description: "Muliple tags can be provided with comma separated strings. Use\n\
tag1, tag2, tag3 for testing.\n"
description: "Muliple tags can be provided with comma seperated strings. Use\
\ tag1, tag2, tag3 for testing."
operationId: "findPetsByTags"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "tags"
in: "query"
description: "Tags to filter by"
required: true
required: false
type: "array"
items:
type: "string"
@@ -157,24 +140,24 @@ paths:
description: "Invalid tag value"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
deprecated: true
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
/pet/{petId}:
/pets/{petId}:
get:
tags:
- "pet"
summary: "Find pet by ID"
description: "Returns a single pet"
description: "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate\
\ API error conditions"
operationId: "getPetById"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "petId"
in: "path"
description: "ID of pet to return"
description: "ID of pet that needs to be fetched"
required: true
type: "integer"
format: "int64"
@@ -189,55 +172,59 @@ paths:
description: "Pet not found"
security:
- api_key: []
- petstore_auth:
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
post:
tags:
- "pet"
summary: "Updates a pet in the store with form data"
description: "null"
description: ""
operationId: "updatePetWithForm"
consumes:
- "application/x-www-form-urlencoded"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be updated"
required: true
type: "integer"
format: "int64"
type: "string"
- name: "name"
in: "formData"
description: "Updated name of the pet"
required: false
required: true
type: "string"
- name: "status"
in: "formData"
description: "Updated status of the pet"
required: false
required: true
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:
- "pet"
summary: "Deletes a pet"
description: ""
operationId: "deletePet"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "api_key"
in: "header"
required: false
description: ""
required: true
type: "string"
- name: "petId"
in: "path"
@@ -247,86 +234,27 @@ paths:
format: "int64"
responses:
400:
description: "Invalid ID supplied"
404:
description: "Pet not found"
description: "Invalid pet value"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
- "write_pets"
- "read_pets"
x-swagger-router-controller: "Pet"
/pet/{petId}/uploadImage:
post:
tags:
- "pet"
summary: "uploads an image"
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:
/stores/order:
post:
tags:
- "store"
summary: "Place an order for a pet"
description: ""
operationId: "placeOrder"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "order placed for purchasing the pet"
required: true
required: false
schema:
$ref: "#/definitions/Order"
responses:
@@ -337,26 +265,23 @@ paths:
400:
description: "Invalid Order"
x-swagger-router-controller: "Store"
/store/order/{orderId}:
/stores/order/{orderId}:
get:
tags:
- "store"
summary: "Find purchase order by ID"
description: "For valid response try integer IDs with value >= 1 and <= 10.\n\
Other values will generated exceptions\n"
description: "For valid response try integer IDs with value <= 5 or > 10. Other\
\ values will generated exceptions"
operationId: "getOrderById"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "orderId"
in: "path"
description: "ID of pet that needs to be fetched"
required: true
type: "integer"
maximum: 10
minimum: 1
format: "int64"
type: "string"
responses:
200:
description: "successful operation"
@@ -371,27 +296,25 @@ paths:
tags:
- "store"
summary: "Delete purchase order by ID"
description: "For valid response try integer IDs with positive integer value.\\\
\ \\ Negative or non-integer values will generate API errors"
description: "For valid response try integer IDs with value < 1000. Anything\
\ above 1000 or nonintegers will generate API errors"
operationId: "deleteOrder"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "orderId"
in: "path"
description: "ID of the order that needs to be deleted"
required: true
type: "integer"
minimum: 1
format: "int64"
type: "string"
responses:
400:
description: "Invalid ID supplied"
404:
description: "Order not found"
x-swagger-router-controller: "Store"
/user:
/users:
post:
tags:
- "user"
@@ -399,33 +322,34 @@ paths:
description: "This can only be done by the logged in user."
operationId: "createUser"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Created user object"
required: true
required: false
schema:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/user/createWithArray:
/users/createWithArray:
post:
tags:
- "user"
summary: "Creates list of users with given input array"
description: ""
operationId: "createUsersWithArrayInput"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: true
required: false
schema:
type: "array"
items:
@@ -434,20 +358,21 @@ paths:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/user/createWithList:
/users/createWithList:
post:
tags:
- "user"
summary: "Creates list of users with given input array"
description: ""
operationId: "createUsersWithListInput"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: true
required: false
schema:
type: "array"
items:
@@ -456,67 +381,60 @@ paths:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/user/login:
/users/login:
get:
tags:
- "user"
summary: "Logs user into the system"
description: ""
operationId: "loginUser"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "query"
description: "The user name for login"
required: true
required: false
type: "string"
- name: "password"
in: "query"
description: "The password for login in clear text"
required: true
required: false
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 token expires"
400:
description: "Invalid username/password supplied"
x-swagger-router-controller: "User"
/user/logout:
/users/logout:
get:
tags:
- "user"
summary: "Logs out current logged in user session"
description: "null"
description: ""
operationId: "logoutUser"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters: []
responses:
default:
description: "successful operation"
x-swagger-router-controller: "User"
/user/{username}:
/users/{username}:
get:
tags:
- "user"
summary: "Get user by user name"
description: ""
operationId: "getUserByName"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
@@ -540,18 +458,18 @@ paths:
description: "This can only be done by the logged in user."
operationId: "updateUser"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "name that need to be updated"
description: "name that need to be deleted"
required: true
type: "string"
- in: "body"
name: "body"
description: "Updated user object"
required: true
required: false
schema:
$ref: "#/definitions/User"
responses:
@@ -567,8 +485,8 @@ paths:
description: "This can only be done by the logged in user."
operationId: "deleteUser"
produces:
- "application/xml"
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
@@ -588,39 +506,12 @@ securityDefinitions:
in: "header"
petstore_auth:
type: "oauth2"
authorizationUrl: "http://petstore.swagger.io/oauth/dialog"
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"
User:
type: "object"
properties:
@@ -643,8 +534,6 @@ definitions:
type: "integer"
format: "int32"
description: "User Status"
xml:
name: "User"
Category:
type: "object"
properties:
@@ -653,18 +542,6 @@ definitions:
format: "int64"
name:
type: "string"
xml:
name: "Category"
Tag:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Tag"
Pet:
type: "object"
required:
@@ -681,37 +558,40 @@ 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"
enum:
- "available"
- "pending"
- "sold"
xml:
name: "Pet"
ApiResponse:
Tag:
type: "object"
properties:
code:
id:
type: "integer"
format: "int64"
name:
type: "string"
Order:
type: "object"
properties:
id:
type: "integer"
format: "int64"
petId:
type: "integer"
format: "int64"
quantity:
type: "integer"
format: "int32"
type:
shipDate:
type: "string"
message:
format: "date-time"
status:
type: "string"
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"
description: "Order Status"
complete:
type: "boolean"

View File

@@ -33,7 +33,3 @@ 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

@@ -6,20 +6,16 @@ exports.addPet = function(args, res, next) {
* body (Pet)
**/
// no response value expected for this operation
res.end();
}
exports.deletePet = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
* apiKey (String)
* petId (Long)
**/
// no response value expected for this operation
res.end();
}
@@ -28,8 +24,6 @@ exports.findPetsByStatus = function(args, res, next) {
* parameters expected in the args:
* status (List)
**/
var examples = {};
examples['application/json'] = [ {
"tags" : [ {
@@ -45,7 +39,6 @@ exports.findPetsByStatus = function(args, res, next) {
"name" : "doggie",
"photoUrls" : [ "aeiou" ]
} ];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
@@ -54,7 +47,6 @@ exports.findPetsByStatus = function(args, res, next) {
res.end();
}
}
exports.findPetsByTags = function(args, res, next) {
@@ -62,8 +54,6 @@ exports.findPetsByTags = function(args, res, next) {
* parameters expected in the args:
* tags (List)
**/
var examples = {};
examples['application/json'] = [ {
"tags" : [ {
@@ -79,7 +69,6 @@ exports.findPetsByTags = function(args, res, next) {
"name" : "doggie",
"photoUrls" : [ "aeiou" ]
} ];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
@@ -88,7 +77,6 @@ exports.findPetsByTags = function(args, res, next) {
res.end();
}
}
exports.getPetById = function(args, res, next) {
@@ -96,8 +84,6 @@ exports.getPetById = function(args, res, next) {
* parameters expected in the args:
* petId (Long)
**/
var examples = {};
examples['application/json'] = {
"tags" : [ {
@@ -113,7 +99,6 @@ exports.getPetById = function(args, res, next) {
"name" : "doggie",
"photoUrls" : [ "aeiou" ]
};
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
@@ -122,7 +107,6 @@ exports.getPetById = function(args, res, next) {
res.end();
}
}
exports.updatePet = function(args, res, next) {
@@ -131,48 +115,17 @@ exports.updatePet = function(args, res, next) {
* body (Pet)
**/
// no response value expected for this operation
res.end();
}
exports.updatePetWithForm = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
* petId (String)
* name (String)
* status (String)
**/
// no response value expected for this operation
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,10 +10,6 @@ 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

@@ -3,43 +3,17 @@
exports.deleteOrder = function(args, res, next) {
/**
* parameters expected in the args:
* orderId (Long)
* orderId (String)
**/
// no response value expected for this operation
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 (Long)
* orderId (String)
**/
var examples = {};
examples['application/json'] = {
"id" : 123456789,
@@ -49,7 +23,6 @@ exports.getOrderById = function(args, res, next) {
"quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+0000"
};
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
@@ -58,7 +31,6 @@ exports.getOrderById = function(args, res, next) {
res.end();
}
}
exports.placeOrder = function(args, res, next) {
@@ -66,8 +38,6 @@ exports.placeOrder = function(args, res, next) {
* parameters expected in the args:
* body (Order)
**/
var examples = {};
examples['application/json'] = {
"id" : 123456789,
@@ -77,7 +47,6 @@ exports.placeOrder = function(args, res, next) {
"quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+0000"
};
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
@@ -86,6 +55,5 @@ exports.placeOrder = function(args, res, next) {
res.end();
}
}

View File

@@ -6,8 +6,6 @@ exports.createUser = function(args, res, next) {
* body (User)
**/
// no response value expected for this operation
res.end();
}
@@ -17,8 +15,6 @@ exports.createUsersWithArrayInput = function(args, res, next) {
* body (List)
**/
// no response value expected for this operation
res.end();
}
@@ -28,8 +24,6 @@ exports.createUsersWithListInput = function(args, res, next) {
* body (List)
**/
// no response value expected for this operation
res.end();
}
@@ -39,8 +33,6 @@ exports.deleteUser = function(args, res, next) {
* username (String)
**/
// no response value expected for this operation
res.end();
}
@@ -49,8 +41,6 @@ exports.getUserByName = function(args, res, next) {
* parameters expected in the args:
* username (String)
**/
var examples = {};
examples['application/json'] = {
"id" : 123456789,
@@ -62,7 +52,6 @@ exports.getUserByName = function(args, res, next) {
"firstName" : "aeiou",
"password" : "aeiou"
};
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
@@ -71,7 +60,6 @@ exports.getUserByName = function(args, res, next) {
res.end();
}
}
exports.loginUser = function(args, res, next) {
@@ -80,11 +68,8 @@ exports.loginUser = function(args, res, next) {
* username (String)
* password (String)
**/
var examples = {};
examples['application/json'] = "aeiou";
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
@@ -93,7 +78,6 @@ exports.loginUser = function(args, res, next) {
res.end();
}
}
exports.logoutUser = function(args, res, next) {
@@ -101,8 +85,6 @@ exports.logoutUser = function(args, res, next) {
* parameters expected in the args:
**/
// no response value expected for this operation
res.end();
}
@@ -113,8 +95,6 @@ exports.updateUser = function(args, res, next) {
* body (User)
**/
// no response value expected for this operation
res.end();
}

View File

@@ -1,7 +1,7 @@
{
"name": "swagger-petstore",
"version": "1.0.0",
"description": "This is a sample server Petstore server. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\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.\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",
"main": "index.js",
"keywords": [
"swagger"