diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..74e0465 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +coverage +templates diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..80f0b96 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,25 @@ +{ + "rules": { + "indent": [ + 2, + 4 + ], + "quotes": [ + 2, + "single" + ], + "linebreak-style": [ + 2, + "unix" + ], + "semi": [ + 2, + "always" + ] + }, + "env": { + "es6": true, + "node": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7be1880 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz +*.orig + +work +build +pids +logs +results +coverage +lib-cov +html-report +xunit.xml +node_modules +npm-debug.log + +.project +.idea +.settings +.iml +*.sublime-workspace +*.sublime-project + +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db +.AppleDouble +.LSOverride +.Spotlight-V100 +.Trashes + +test/temp diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..a75e2a4 --- /dev/null +++ b/.npmignore @@ -0,0 +1,51 @@ +# Automatically ignored per: +# https://www.npmjs.org/doc/developers.html#Keeping-files-out-of-your-package +# +# .*.swp +# ._* +# .DS_Store +# .git +# .hg +# .lock-wscript +# .svn +# .wafpickle-* +# CVS +# npm-debug.log +# node_modules + +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz +*.orig + +work +build +test +pids +logs +results +coverage +lib-cov +html-report +xunit.xml + +.project +.idea +.settings +.iml +*.sublime-workspace +*.sublime-project + +ehthumbs.db +Icon? +Thumbs.db +.AppleDouble +.LSOverride +.Spotlight-V100 +.Trashes + +test/temp diff --git a/README.md b/README.md index 6f828e0..524dcb7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # react-redux-swaggerize-express -React client app, redux stage management, passport oauth2, paypal rest api and swagger based express node.js server + +Swagger api [location](./config/swagger.json) diff --git a/config/swagger.json b/config/swagger.json new file mode 100644 index 0000000..bef6dc6 --- /dev/null +++ b/config/swagger.json @@ -0,0 +1,1035 @@ +{ + "swagger": "2.0", + "info": { + "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": { + "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": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "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" + ] + } + ] + } + }, + "/pet/findByStatus": { + "get": { + "tags": [ + "pet" + ], + "summary": "Finds Pets by status", + "description": "Multiple status values can be provided with comma separated strings", + "operationId": "findPetsByStatus", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "status", + "in": "query", + "description": "Status values that need to be considered for filter", + "required": true, + "type": "array", + "items": { + "type": "string", + "enum": [ + "available", + "pending", + "sold" + ], + "default": "available" + }, + "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" + ] + } + ] + } + }, + "/pet/findByTags": { + "get": { + "tags": [ + "pet" + ], + "summary": "Finds Pets by tags", + "description": "Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId": "findPetsByTags", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "Tags to filter by", + "required": true, + "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" + ] + } + ], + "deprecated": true + } + }, + "/pet/{petId}": { + "get": { + "tags": [ + "pet" + ], + "summary": "Find pet by ID", + "description": "Returns a single pet", + "operationId": "getPetById", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet to return", + "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": [] + } + ] + }, + "post": { + "tags": [ + "pet" + ], + "summary": "Updates a pet in the store with form data", + "description": "", + "operationId": "updatePetWithForm", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet that needs to be updated", + "required": true, + "type": "integer", + "format": "int64" + }, + { + "name": "name", + "in": "formData", + "description": "Updated name of the pet", + "required": false, + "type": "string" + }, + { + "name": "status", + "in": "formData", + "description": "Updated status of the pet", + "required": false, + "type": "string" + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + }, + "delete": { + "tags": [ + "pet" + ], + "summary": "Deletes a pet", + "description": "", + "operationId": "deletePet", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "api_key", + "in": "header", + "required": false, + "type": "string" + }, + { + "name": "petId", + "in": "path", + "description": "Pet id to delete", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + } + }, + "security": [ + { + "petstore_auth": [ + "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" + ], + "summary": "Place an order for a pet", + "description": "", + "operationId": "placeOrder", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "order placed for purchasing the pet", + "required": true, + "schema": { + "$ref": "#/definitions/Order" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Order" + } + }, + "400": { + "description": "Invalid Order" + } + } + } + }, + "/store/order/{orderId}": { + "get": { + "tags": [ + "store" + ], + "summary": "Find purchase order by ID", + "description": "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions", + "operationId": "getOrderById", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "orderId", + "in": "path", + "description": "ID of pet that needs to be fetched", + "required": true, + "type": "integer", + "maximum": 10, + "minimum": 1, + "format": "int64" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Order" + } + }, + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Order not found" + } + } + }, + "delete": { + "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", + "operationId": "deleteOrder", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "orderId", + "in": "path", + "description": "ID of the order that needs to be deleted", + "required": true, + "type": "integer", + "minimum": 1, + "format": "int64" + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Order not found" + } + } + } + }, + "/user": { + "post": { + "tags": [ + "user" + ], + "summary": "Create user", + "description": "This can only be done by the logged in user.", + "operationId": "createUser", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Created user object", + "required": true, + "schema": { + "$ref": "#/definitions/User" + } + } + ], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/user/createWithArray": { + "post": { + "tags": [ + "user" + ], + "summary": "Creates list of users with given input array", + "description": "", + "operationId": "createUsersWithArrayInput", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "List of user object", + "required": true, + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/User" + } + } + } + ], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/user/createWithList": { + "post": { + "tags": [ + "user" + ], + "summary": "Creates list of users with given input array", + "description": "", + "operationId": "createUsersWithListInput", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "List of user object", + "required": true, + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/User" + } + } + } + ], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/user/login": { + "get": { + "tags": [ + "user" + ], + "summary": "Logs user into the system", + "description": "", + "operationId": "loginUser", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "username", + "in": "query", + "description": "The user name for login", + "required": true, + "type": "string" + }, + { + "name": "password", + "in": "query", + "description": "The password for login in clear text", + "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 token expires" + } + } + }, + "400": { + "description": "Invalid username/password supplied" + } + } + } + }, + "/user/logout": { + "get": { + "tags": [ + "user" + ], + "summary": "Logs out current logged in user session", + "description": "", + "operationId": "logoutUser", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/user/{username}": { + "get": { + "tags": [ + "user" + ], + "summary": "Get user by user name", + "description": "", + "operationId": "getUserByName", + "produces": [ + "application/xml", + "application/json" + ], + "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" + } + } + }, + "put": { + "tags": [ + "user" + ], + "summary": "Updated user", + "description": "This can only be done by the logged in user.", + "operationId": "updateUser", + "produces": [ + "application/xml", + "application/json" + ], + "parameters": [ + { + "name": "username", + "in": "path", + "description": "name that need to be updated", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "description": "Updated user object", + "required": true, + "schema": { + "$ref": "#/definitions/User" + } + } + ], + "responses": { + "400": { + "description": "Invalid user supplied" + }, + "404": { + "description": "User not found" + } + } + }, + "delete": { + "tags": [ + "user" + ], + "summary": "Delete user", + "description": "This can only be done by the logged in user.", + "operationId": "deleteUser", + "produces": [ + "application/xml", + "application/json" + ], + "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" + } + } + } + } + }, + "securityDefinitions": { + "petstore_auth": { + "type": "oauth2", + "authorizationUrl": "http://petstore.swagger.io/oauth/dialog", + "flow": "implicit", + "scopes": { + "write:pets": "modify pets in your account", + "read:pets": "read your pets" + } + }, + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "header" + } + }, + "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": { + "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" + } + }, + "xml": { + "name": "User" + } + }, + "Tag": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Tag" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "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": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } + }, + "externalDocs": { + "description": "Find out more about Swagger", + "url": "http://swagger.io" + } +} \ No newline at end of file diff --git a/data/mockgen.js b/data/mockgen.js new file mode 100644 index 0000000..8cda414 --- /dev/null +++ b/data/mockgen.js @@ -0,0 +1,13 @@ +'use strict'; +var Swagmock = require('swagmock'); +var Path = require('path'); +var apiPath = Path.resolve(__dirname, '../config/swagger.json'); +var mockgen; + +module.exports = function () { + /** + * Cached mock generator + */ + mockgen = mockgen || Swagmock(apiPath); + return mockgen; +}; diff --git a/data/pet.js b/data/pet.js new file mode 100644 index 0000000..a2fe2d3 --- /dev/null +++ b/data/pet.js @@ -0,0 +1,71 @@ +'use strict'; +var Mockgen = require('./mockgen.js'); +/** + * Operations on /pet + */ +module.exports = { + /** + * summary: Add a new pet to the store + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 405 + * operationId: addPet + */ + post: { + 405: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet', + operation: 'post', + response: '405' + }, callback); + } + }, + /** + * summary: Update an existing pet + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 400, 404, 405 + * operationId: updatePet + */ + put: { + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet', + operation: 'put', + response: '400' + }, callback); + }, + 404: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet', + operation: 'put', + response: '404' + }, callback); + }, + 405: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet', + operation: 'put', + response: '405' + }, callback); + } + } +}; diff --git a/data/pet/findByStatus.js b/data/pet/findByStatus.js new file mode 100644 index 0000000..1ddcabd --- /dev/null +++ b/data/pet/findByStatus.js @@ -0,0 +1,39 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /pet/findByStatus + */ +module.exports = { + /** + * summary: Finds Pets by status + * description: Multiple status values can be provided with comma separated strings + * parameters: status + * produces: application/xml, application/json + * responses: 200, 400 + * operationId: findPetsByStatus + */ + get: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/findByStatus', + operation: 'get', + response: '200' + }, callback); + }, + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/findByStatus', + operation: 'get', + response: '400' + }, callback); + } + } +}; diff --git a/data/pet/findByTags.js b/data/pet/findByTags.js new file mode 100644 index 0000000..51a37ef --- /dev/null +++ b/data/pet/findByTags.js @@ -0,0 +1,39 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /pet/findByTags + */ +module.exports = { + /** + * summary: Finds Pets by tags + * description: Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * parameters: tags + * produces: application/xml, application/json + * responses: 200, 400 + * operationId: findPetsByTags + */ + get: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/findByTags', + operation: 'get', + response: '200' + }, callback); + }, + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/findByTags', + operation: 'get', + response: '400' + }, callback); + } + } +}; diff --git a/data/pet/{petId}.js b/data/pet/{petId}.js new file mode 100644 index 0000000..035200b --- /dev/null +++ b/data/pet/{petId}.js @@ -0,0 +1,103 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /pet/{petId} + */ +module.exports = { + /** + * summary: Find pet by ID + * description: Returns a single pet + * parameters: petId + * produces: application/xml, application/json + * responses: 200, 400, 404 + * operationId: getPetById + */ + get: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/{petId}', + operation: 'get', + response: '200' + }, callback); + }, + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/{petId}', + operation: 'get', + response: '400' + }, callback); + }, + 404: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/{petId}', + operation: 'get', + response: '404' + }, callback); + } + }, + /** + * summary: Updates a pet in the store with form data + * description: + * parameters: petId, name, status + * produces: application/xml, application/json + * responses: 405 + * operationId: updatePetWithForm + */ + post: { + 405: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/{petId}', + operation: 'post', + response: '405' + }, callback); + } + }, + /** + * summary: Deletes a pet + * description: + * parameters: api_key, petId + * produces: application/xml, application/json + * responses: 400, 404 + * operationId: deletePet + */ + delete: { + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/{petId}', + operation: 'delete', + response: '400' + }, callback); + }, + 404: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/{petId}', + operation: 'delete', + response: '404' + }, callback); + } + } +}; diff --git a/data/pet/{petId}/uploadImage.js b/data/pet/{petId}/uploadImage.js new file mode 100644 index 0000000..d99b7e2 --- /dev/null +++ b/data/pet/{petId}/uploadImage.js @@ -0,0 +1,28 @@ +'use strict'; +var Mockgen = require('../../mockgen.js'); +/** + * Operations on /pet/{petId}/uploadImage + */ +module.exports = { + /** + * summary: uploads an image + * description: + * parameters: petId, additionalMetadata, file + * produces: application/json + * responses: 200 + * operationId: uploadFile + */ + post: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/pet/{petId}/uploadImage', + operation: 'post', + response: '200' + }, callback); + } + } +}; diff --git a/data/store/inventory.js b/data/store/inventory.js new file mode 100644 index 0000000..5bfcc42 --- /dev/null +++ b/data/store/inventory.js @@ -0,0 +1,28 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /store/inventory + */ +module.exports = { + /** + * summary: Returns pet inventories by status + * description: Returns a map of status codes to quantities + * parameters: + * produces: application/json + * responses: 200 + * operationId: getInventory + */ + get: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/store/inventory', + operation: 'get', + response: '200' + }, callback); + } + } +}; diff --git a/data/store/order.js b/data/store/order.js new file mode 100644 index 0000000..9b5171c --- /dev/null +++ b/data/store/order.js @@ -0,0 +1,39 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /store/order + */ +module.exports = { + /** + * summary: Place an order for a pet + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 200, 400 + * operationId: placeOrder + */ + post: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/store/order', + operation: 'post', + response: '200' + }, callback); + }, + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/store/order', + operation: 'post', + response: '400' + }, callback); + } + } +}; diff --git a/data/store/order/{orderId}.js b/data/store/order/{orderId}.js new file mode 100644 index 0000000..8930cb0 --- /dev/null +++ b/data/store/order/{orderId}.js @@ -0,0 +1,82 @@ +'use strict'; +var Mockgen = require('../../mockgen.js'); +/** + * Operations on /store/order/{orderId} + */ +module.exports = { + /** + * summary: Find purchase order by ID + * description: For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions + * parameters: orderId + * produces: application/xml, application/json + * responses: 200, 400, 404 + * operationId: getOrderById + */ + get: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/store/order/{orderId}', + operation: 'get', + response: '200' + }, callback); + }, + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/store/order/{orderId}', + operation: 'get', + response: '400' + }, callback); + }, + 404: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/store/order/{orderId}', + operation: 'get', + response: '404' + }, callback); + } + }, + /** + * 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 + * parameters: orderId + * produces: application/xml, application/json + * responses: 400, 404 + * operationId: deleteOrder + */ + delete: { + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/store/order/{orderId}', + operation: 'delete', + response: '400' + }, callback); + }, + 404: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/store/order/{orderId}', + operation: 'delete', + response: '404' + }, callback); + } + } +}; diff --git a/data/user.js b/data/user.js new file mode 100644 index 0000000..b78b366 --- /dev/null +++ b/data/user.js @@ -0,0 +1,28 @@ +'use strict'; +var Mockgen = require('./mockgen.js'); +/** + * Operations on /user + */ +module.exports = { + /** + * summary: Create user + * description: This can only be done by the logged in user. + * parameters: body + * produces: application/xml, application/json + * responses: default + * operationId: createUser + */ + post: { + default: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user', + operation: 'post', + response: 'default' + }, callback); + } + } +}; diff --git a/data/user/createWithArray.js b/data/user/createWithArray.js new file mode 100644 index 0000000..581b4f1 --- /dev/null +++ b/data/user/createWithArray.js @@ -0,0 +1,28 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /user/createWithArray + */ +module.exports = { + /** + * summary: Creates list of users with given input array + * description: + * parameters: body + * produces: application/xml, application/json + * responses: default + * operationId: createUsersWithArrayInput + */ + post: { + default: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/createWithArray', + operation: 'post', + response: 'default' + }, callback); + } + } +}; diff --git a/data/user/createWithList.js b/data/user/createWithList.js new file mode 100644 index 0000000..819c386 --- /dev/null +++ b/data/user/createWithList.js @@ -0,0 +1,28 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /user/createWithList + */ +module.exports = { + /** + * summary: Creates list of users with given input array + * description: + * parameters: body + * produces: application/xml, application/json + * responses: default + * operationId: createUsersWithListInput + */ + post: { + default: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/createWithList', + operation: 'post', + response: 'default' + }, callback); + } + } +}; diff --git a/data/user/login.js b/data/user/login.js new file mode 100644 index 0000000..fdd95fe --- /dev/null +++ b/data/user/login.js @@ -0,0 +1,39 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /user/login + */ +module.exports = { + /** + * summary: Logs user into the system + * description: + * parameters: username, password + * produces: application/xml, application/json + * responses: 200, 400 + * operationId: loginUser + */ + get: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/login', + operation: 'get', + response: '200' + }, callback); + }, + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/login', + operation: 'get', + response: '400' + }, callback); + } + } +}; diff --git a/data/user/logout.js b/data/user/logout.js new file mode 100644 index 0000000..4f800f0 --- /dev/null +++ b/data/user/logout.js @@ -0,0 +1,28 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /user/logout + */ +module.exports = { + /** + * summary: Logs out current logged in user session + * description: + * parameters: + * produces: application/xml, application/json + * responses: default + * operationId: logoutUser + */ + get: { + default: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/logout', + operation: 'get', + response: 'default' + }, callback); + } + } +}; diff --git a/data/user/{username}.js b/data/user/{username}.js new file mode 100644 index 0000000..ff6afd5 --- /dev/null +++ b/data/user/{username}.js @@ -0,0 +1,114 @@ +'use strict'; +var Mockgen = require('../mockgen.js'); +/** + * Operations on /user/{username} + */ +module.exports = { + /** + * summary: Get user by user name + * description: + * parameters: username + * produces: application/xml, application/json + * responses: 200, 400, 404 + * operationId: getUserByName + */ + get: { + 200: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/{username}', + operation: 'get', + response: '200' + }, callback); + }, + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/{username}', + operation: 'get', + response: '400' + }, callback); + }, + 404: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/{username}', + operation: 'get', + response: '404' + }, callback); + } + }, + /** + * summary: Updated user + * description: This can only be done by the logged in user. + * parameters: username, body + * produces: application/xml, application/json + * responses: 400, 404 + * operationId: updateUser + */ + put: { + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/{username}', + operation: 'put', + response: '400' + }, callback); + }, + 404: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/{username}', + operation: 'put', + response: '404' + }, callback); + } + }, + /** + * summary: Delete user + * description: This can only be done by the logged in user. + * parameters: username + * produces: application/xml, application/json + * responses: 400, 404 + * operationId: deleteUser + */ + delete: { + 400: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/{username}', + operation: 'delete', + response: '400' + }, callback); + }, + 404: function (req, res, callback) { + /** + * Using mock data generator module. + * Replace this by actual data for the api. + */ + Mockgen().responses({ + path: '/user/{username}', + operation: 'delete', + response: '404' + }, callback); + } + } +}; diff --git a/handlers/pet.js b/handlers/pet.js new file mode 100644 index 0000000..d561be0 --- /dev/null +++ b/handlers/pet.js @@ -0,0 +1,51 @@ +'use strict'; +var dataProvider = require('../data/pet.js'); +/** + * Operations on /pet + */ +module.exports = { + /** + * summary: Add a new pet to the store + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 405 + */ + post: function addPet(req, res, next) { + /** + * Get the data for response 405 + * For response `default` status 200 is used. + */ + var status = 405; + var provider = dataProvider['post']['405']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + }, + /** + * summary: Update an existing pet + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 400, 404, 405 + */ + put: function updatePet(req, res, next) { + /** + * Get the data for response 400 + * For response `default` status 200 is used. + */ + var status = 400; + var provider = dataProvider['put']['400']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/pet/findByStatus.js b/handlers/pet/findByStatus.js new file mode 100644 index 0000000..4e9a834 --- /dev/null +++ b/handlers/pet/findByStatus.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../data/pet/findByStatus.js'); +/** + * Operations on /pet/findByStatus + */ +module.exports = { + /** + * summary: Finds Pets by status + * description: Multiple status values can be provided with comma separated strings + * parameters: status + * produces: application/xml, application/json + * responses: 200, 400 + */ + get: function findPetsByStatus(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['get']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/pet/findByTags.js b/handlers/pet/findByTags.js new file mode 100644 index 0000000..01c6099 --- /dev/null +++ b/handlers/pet/findByTags.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../data/pet/findByTags.js'); +/** + * Operations on /pet/findByTags + */ +module.exports = { + /** + * summary: Finds Pets by tags + * description: Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * parameters: tags + * produces: application/xml, application/json + * responses: 200, 400 + */ + get: function findPetsByTags(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['get']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/pet/{petId}.js b/handlers/pet/{petId}.js new file mode 100644 index 0000000..3455a81 --- /dev/null +++ b/handlers/pet/{petId}.js @@ -0,0 +1,73 @@ +'use strict'; +var dataProvider = require('../../data/pet/{petId}.js'); +/** + * Operations on /pet/{petId} + */ +module.exports = { + /** + * summary: Find pet by ID + * description: Returns a single pet + * parameters: petId + * produces: application/xml, application/json + * responses: 200, 400, 404 + */ + get: function getPetById(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['get']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + }, + /** + * summary: Updates a pet in the store with form data + * description: + * parameters: petId, name, status + * produces: application/xml, application/json + * responses: 405 + */ + post: function updatePetWithForm(req, res, next) { + /** + * Get the data for response 405 + * For response `default` status 200 is used. + */ + var status = 405; + var provider = dataProvider['post']['405']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + }, + /** + * summary: Deletes a pet + * description: + * parameters: api_key, petId + * produces: application/xml, application/json + * responses: 400, 404 + */ + delete: function deletePet(req, res, next) { + /** + * Get the data for response 400 + * For response `default` status 200 is used. + */ + var status = 400; + var provider = dataProvider['delete']['400']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/pet/{petId}/uploadImage.js b/handlers/pet/{petId}/uploadImage.js new file mode 100644 index 0000000..dbe6c22 --- /dev/null +++ b/handlers/pet/{petId}/uploadImage.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../../data/pet/{petId}/uploadImage.js'); +/** + * Operations on /pet/{petId}/uploadImage + */ +module.exports = { + /** + * summary: uploads an image + * description: + * parameters: petId, additionalMetadata, file + * produces: application/json + * responses: 200 + */ + post: function uploadFile(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['post']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/store/inventory.js b/handlers/store/inventory.js new file mode 100644 index 0000000..171ecc1 --- /dev/null +++ b/handlers/store/inventory.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../data/store/inventory.js'); +/** + * Operations on /store/inventory + */ +module.exports = { + /** + * summary: Returns pet inventories by status + * description: Returns a map of status codes to quantities + * parameters: + * produces: application/json + * responses: 200 + */ + get: function getInventory(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['get']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/store/order.js b/handlers/store/order.js new file mode 100644 index 0000000..a0513de --- /dev/null +++ b/handlers/store/order.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../data/store/order.js'); +/** + * Operations on /store/order + */ +module.exports = { + /** + * summary: Place an order for a pet + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 200, 400 + */ + post: function placeOrder(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['post']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/store/order/{orderId}.js b/handlers/store/order/{orderId}.js new file mode 100644 index 0000000..1bc9e93 --- /dev/null +++ b/handlers/store/order/{orderId}.js @@ -0,0 +1,51 @@ +'use strict'; +var dataProvider = require('../../../data/store/order/{orderId}.js'); +/** + * Operations on /store/order/{orderId} + */ +module.exports = { + /** + * summary: Find purchase order by ID + * description: For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions + * parameters: orderId + * produces: application/xml, application/json + * responses: 200, 400, 404 + */ + get: function getOrderById(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['get']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + }, + /** + * 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 + * parameters: orderId + * produces: application/xml, application/json + * responses: 400, 404 + */ + delete: function deleteOrder(req, res, next) { + /** + * Get the data for response 400 + * For response `default` status 200 is used. + */ + var status = 400; + var provider = dataProvider['delete']['400']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/user.js b/handlers/user.js new file mode 100644 index 0000000..22efc93 --- /dev/null +++ b/handlers/user.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../data/user.js'); +/** + * Operations on /user + */ +module.exports = { + /** + * summary: Create user + * description: This can only be done by the logged in user. + * parameters: body + * produces: application/xml, application/json + * responses: default + */ + post: function createUser(req, res, next) { + /** + * Get the data for response default + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['post']['default']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/user/createWithArray.js b/handlers/user/createWithArray.js new file mode 100644 index 0000000..b796698 --- /dev/null +++ b/handlers/user/createWithArray.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../data/user/createWithArray.js'); +/** + * Operations on /user/createWithArray + */ +module.exports = { + /** + * summary: Creates list of users with given input array + * description: + * parameters: body + * produces: application/xml, application/json + * responses: default + */ + post: function createUsersWithArrayInput(req, res, next) { + /** + * Get the data for response default + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['post']['default']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/user/createWithList.js b/handlers/user/createWithList.js new file mode 100644 index 0000000..4f8e4e6 --- /dev/null +++ b/handlers/user/createWithList.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../data/user/createWithList.js'); +/** + * Operations on /user/createWithList + */ +module.exports = { + /** + * summary: Creates list of users with given input array + * description: + * parameters: body + * produces: application/xml, application/json + * responses: default + */ + post: function createUsersWithListInput(req, res, next) { + /** + * Get the data for response default + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['post']['default']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/user/login.js b/handlers/user/login.js new file mode 100644 index 0000000..c63ed21 --- /dev/null +++ b/handlers/user/login.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../data/user/login.js'); +/** + * Operations on /user/login + */ +module.exports = { + /** + * summary: Logs user into the system + * description: + * parameters: username, password + * produces: application/xml, application/json + * responses: 200, 400 + */ + get: function loginUser(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['get']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/user/logout.js b/handlers/user/logout.js new file mode 100644 index 0000000..4fd3184 --- /dev/null +++ b/handlers/user/logout.js @@ -0,0 +1,29 @@ +'use strict'; +var dataProvider = require('../../data/user/logout.js'); +/** + * Operations on /user/logout + */ +module.exports = { + /** + * summary: Logs out current logged in user session + * description: + * parameters: + * produces: application/xml, application/json + * responses: default + */ + get: function logoutUser(req, res, next) { + /** + * Get the data for response default + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['get']['default']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/handlers/user/{username}.js b/handlers/user/{username}.js new file mode 100644 index 0000000..12ab361 --- /dev/null +++ b/handlers/user/{username}.js @@ -0,0 +1,73 @@ +'use strict'; +var dataProvider = require('../../data/user/{username}.js'); +/** + * Operations on /user/{username} + */ +module.exports = { + /** + * summary: Get user by user name + * description: + * parameters: username + * produces: application/xml, application/json + * responses: 200, 400, 404 + */ + get: function getUserByName(req, res, next) { + /** + * Get the data for response 200 + * For response `default` status 200 is used. + */ + var status = 200; + var provider = dataProvider['get']['200']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + }, + /** + * summary: Updated user + * description: This can only be done by the logged in user. + * parameters: username, body + * produces: application/xml, application/json + * responses: 400, 404 + */ + put: function updateUser(req, res, next) { + /** + * Get the data for response 400 + * For response `default` status 200 is used. + */ + var status = 400; + var provider = dataProvider['put']['400']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + }, + /** + * summary: Delete user + * description: This can only be done by the logged in user. + * parameters: username + * produces: application/xml, application/json + * responses: 400, 404 + */ + delete: function deleteUser(req, res, next) { + /** + * Get the data for response 400 + * For response `default` status 200 is used. + */ + var status = 400; + var provider = dataProvider['delete']['400']; + provider(req, res, function (err, data) { + if (err) { + next(err); + return; + } + res.status(status).send(data && data.responses); + }); + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..860731e --- /dev/null +++ b/package.json @@ -0,0 +1,37 @@ +{ + "name": "react-redux-swaggerize-express", + "description": "", + "version": "1.0.0", + "author": "subeesh chothendavida ", + "contributors": [], + "repository": { + "type": "git", + "url": "git://github.com/subeeshcbabu/react-redux-swaggerize-express.git" + }, + "bugs": "http://github.com/subeeshcbabu/react-redux-swaggerize-express/issues", + "publishConfig": { + "registry": "https://registry.npmjs.org" + }, + "dependencies": { + "express": "^4.0.0", + "body-parser": "^1.15.0", + "swaggerize-express": "^4.0.0", + "swagmock": "~0.0.2" + }, + "devDependencies": { + "eslint": "^2", + "istanbul": "~0.4.3", + "is-my-json-valid": "^2.13.1", + "js-yaml": "^3.2.6", + "supertest": "^1.2.0", + "swagger-parser": "^3.4.1", + "tape": "^4" + }, + "scripts": { + "test": "tape 'tests/**/*.js'", + "cover": "istanbul cover tape -- 'tests/**/*.js'", + "lint": "eslint .", + "regenerate": "yo swaggerize:test --framework express --apiPath './config/swagger.json'" + }, + "main": "./server" +} diff --git a/security/api_key.js b/security/api_key.js new file mode 100644 index 0000000..cbd07aa --- /dev/null +++ b/security/api_key.js @@ -0,0 +1,16 @@ +'use strict'; +/** + * Authorize function for securityDefinitions:api_key + * type : apiKey + * description: + */ +module.exports = function authorize(req, res, next) { + //The context('this') for authorize will be bound to the 'securityDefinition' + //this.name - The name of the header or query parameter to be used for securityDefinitions:api_key apiKey security scheme. + //this.in - The location of the API key ("query" or "header") for securityDefinitions:api_key apiKey security scheme. + + + //Perform auth here + + next(); +}; diff --git a/security/petstore_auth.js b/security/petstore_auth.js new file mode 100644 index 0000000..9fb110c --- /dev/null +++ b/security/petstore_auth.js @@ -0,0 +1,19 @@ +'use strict'; +/** + * Authorize function for securityDefinitions:petstore_auth + * type : oauth2 + * description: + */ +module.exports = function authorize(req, res, next) { + //The context('this') for authorize will be bound to the 'securityDefinition' + //this.authorizationUrl - The authorization URL for securityDefinitions:petstore_auth + //this.scopes - The available scopes for the securityDefinitions:petstore_auth security scheme + //this.flow - The flow used by the securityDefinitions:petstore_auth OAuth2 security scheme + + //req.requiredScopes - list of scope names required for the execution (defined as part of security requirement object). + + + //Perform auth here + + next(); +}; diff --git a/server.js b/server.js new file mode 100644 index 0000000..c6ee0fa --- /dev/null +++ b/server.js @@ -0,0 +1,29 @@ +'use strict'; + +var Http = require('http'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); + +var App = Express(); + +var Server = Http.createServer(App); + +App.use(BodyParser.json()); +App.use(BodyParser.urlencoded({ + extended: true +})); + +App.use(Swaggerize({ + api: Path.resolve('./config/swagger.json'), + handlers: Path.resolve('./handlers'), + security: Path.resolve('./security') +})); + +Server.listen(8000, function () { + App.swagger.api.host = this.address().address + ':' + this.address().port; + /* eslint-disable no-console */ + console.log('App running on %s:%d', this.address().address, this.address().port); + /* eslint-disable no-console */ +}); diff --git a/tests/pet.js b/tests/pet.js new file mode 100644 index 0000000..93c54be --- /dev/null +++ b/tests/pet.js @@ -0,0 +1,112 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /pet + */ +Test('/pet', function (t) { + var apiPath = Path.resolve(__dirname, '../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../handlers'), + security: Path.resolve(__dirname, '../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Add a new pet to the store + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 405 + */ + t.test('test addPet post operation', function (t) { + Mockgen().requests({ + path: '/pet', + operation: 'post' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .post('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 405, 'Ok response status'); + t.end(); + }); + }); + });/** + * summary: Update an existing pet + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 400, 404, 405 + */ + t.test('test updatePet put operation', function (t) { + Mockgen().requests({ + path: '/pet', + operation: 'put' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .put('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 400, 'Ok response status'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/pet/findByStatus.js b/tests/pet/findByStatus.js new file mode 100644 index 0000000..efbd0a7 --- /dev/null +++ b/tests/pet/findByStatus.js @@ -0,0 +1,79 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /pet/findByStatus + */ +Test('/pet/findByStatus', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Finds Pets by status + * description: Multiple status values can be provided with comma separated strings + * parameters: status + * produces: application/xml, application/json + * responses: 200, 400 + */ + t.test('test findPetsByStatus get operation', function (t) { + Mockgen().requests({ + path: '/pet/findByStatus', + operation: 'get' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .get('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/pet/findByStatus']['get']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/pet/findByTags.js b/tests/pet/findByTags.js new file mode 100644 index 0000000..b18ec71 --- /dev/null +++ b/tests/pet/findByTags.js @@ -0,0 +1,79 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /pet/findByTags + */ +Test('/pet/findByTags', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Finds Pets by tags + * description: Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * parameters: tags + * produces: application/xml, application/json + * responses: 200, 400 + */ + t.test('test findPetsByTags get operation', function (t) { + Mockgen().requests({ + path: '/pet/findByTags', + operation: 'get' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .get('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/pet/findByTags']['get']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/pet/{petId}.js b/tests/pet/{petId}.js new file mode 100644 index 0000000..bd33f29 --- /dev/null +++ b/tests/pet/{petId}.js @@ -0,0 +1,161 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /pet/{petId} + */ +Test('/pet/{petId}', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Find pet by ID + * description: Returns a single pet + * parameters: petId + * produces: application/xml, application/json + * responses: 200, 400, 404 + */ + t.test('test getPetById get operation', function (t) { + Mockgen().requests({ + path: '/pet/{petId}', + operation: 'get' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .get('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/pet/{petId}']['get']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + });/** + * summary: Updates a pet in the store with form data + * description: + * parameters: petId, name, status + * produces: application/xml, application/json + * responses: 405 + */ + t.test('test updatePetWithForm post operation', function (t) { + Mockgen().requests({ + path: '/pet/{petId}', + operation: 'post' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .post('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 405, 'Ok response status'); + t.end(); + }); + }); + });/** + * summary: Deletes a pet + * description: + * parameters: api_key, petId + * produces: application/xml, application/json + * responses: 400, 404 + */ + t.test('test deletePet delete operation', function (t) { + Mockgen().requests({ + path: '/pet/{petId}', + operation: 'delete' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .delete('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 400, 'Ok response status'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/pet/{petId}/uploadImage.js b/tests/pet/{petId}/uploadImage.js new file mode 100644 index 0000000..f4be379 --- /dev/null +++ b/tests/pet/{petId}/uploadImage.js @@ -0,0 +1,79 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /pet/{petId}/uploadImage + */ +Test('/pet/{petId}/uploadImage', function (t) { + var apiPath = Path.resolve(__dirname, '../../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../../handlers'), + security: Path.resolve(__dirname, '../../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: uploads an image + * description: + * parameters: petId, additionalMetadata, file + * produces: application/json + * responses: 200 + */ + t.test('test uploadFile post operation', function (t) { + Mockgen().requests({ + path: '/pet/{petId}/uploadImage', + operation: 'post' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .post('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/pet/{petId}/uploadImage']['post']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/store/inventory.js b/tests/store/inventory.js new file mode 100644 index 0000000..80821fd --- /dev/null +++ b/tests/store/inventory.js @@ -0,0 +1,79 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /store/inventory + */ +Test('/store/inventory', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Returns pet inventories by status + * description: Returns a map of status codes to quantities + * parameters: + * produces: application/json + * responses: 200 + */ + t.test('test getInventory get operation', function (t) { + Mockgen().requests({ + path: '/store/inventory', + operation: 'get' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .get('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/store/inventory']['get']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/store/order.js b/tests/store/order.js new file mode 100644 index 0000000..cf8a745 --- /dev/null +++ b/tests/store/order.js @@ -0,0 +1,79 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /store/order + */ +Test('/store/order', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Place an order for a pet + * description: + * parameters: body + * produces: application/xml, application/json + * responses: 200, 400 + */ + t.test('test placeOrder post operation', function (t) { + Mockgen().requests({ + path: '/store/order', + operation: 'post' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .post('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/store/order']['post']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/store/order/{orderId}.js b/tests/store/order/{orderId}.js new file mode 100644 index 0000000..61fa4d1 --- /dev/null +++ b/tests/store/order/{orderId}.js @@ -0,0 +1,120 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /store/order/{orderId} + */ +Test('/store/order/{orderId}', function (t) { + var apiPath = Path.resolve(__dirname, '../../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../../handlers'), + security: Path.resolve(__dirname, '../../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Find purchase order by ID + * description: For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions + * parameters: orderId + * produces: application/xml, application/json + * responses: 200, 400, 404 + */ + t.test('test getOrderById get operation', function (t) { + Mockgen().requests({ + path: '/store/order/{orderId}', + operation: 'get' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .get('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/store/order/{orderId}']['get']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + });/** + * 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 + * parameters: orderId + * produces: application/xml, application/json + * responses: 400, 404 + */ + t.test('test deleteOrder delete operation', function (t) { + Mockgen().requests({ + path: '/store/order/{orderId}', + operation: 'delete' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .delete('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 400, 'Ok response status'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/user.js b/tests/user.js new file mode 100644 index 0000000..89689e4 --- /dev/null +++ b/tests/user.js @@ -0,0 +1,71 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /user + */ +Test('/user', function (t) { + var apiPath = Path.resolve(__dirname, '../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../handlers'), + security: Path.resolve(__dirname, '../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Create user + * description: This can only be done by the logged in user. + * parameters: body + * produces: application/xml, application/json + * responses: default + */ + t.test('test createUser post operation', function (t) { + Mockgen().requests({ + path: '/user', + operation: 'post' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .post('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/user/createWithArray.js b/tests/user/createWithArray.js new file mode 100644 index 0000000..47db4a6 --- /dev/null +++ b/tests/user/createWithArray.js @@ -0,0 +1,71 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /user/createWithArray + */ +Test('/user/createWithArray', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Creates list of users with given input array + * description: + * parameters: body + * produces: application/xml, application/json + * responses: default + */ + t.test('test createUsersWithArrayInput post operation', function (t) { + Mockgen().requests({ + path: '/user/createWithArray', + operation: 'post' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .post('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/user/createWithList.js b/tests/user/createWithList.js new file mode 100644 index 0000000..9746f42 --- /dev/null +++ b/tests/user/createWithList.js @@ -0,0 +1,71 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /user/createWithList + */ +Test('/user/createWithList', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Creates list of users with given input array + * description: + * parameters: body + * produces: application/xml, application/json + * responses: default + */ + t.test('test createUsersWithListInput post operation', function (t) { + Mockgen().requests({ + path: '/user/createWithList', + operation: 'post' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .post('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/user/login.js b/tests/user/login.js new file mode 100644 index 0000000..85569e0 --- /dev/null +++ b/tests/user/login.js @@ -0,0 +1,79 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /user/login + */ +Test('/user/login', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Logs user into the system + * description: + * parameters: username, password + * produces: application/xml, application/json + * responses: 200, 400 + */ + t.test('test loginUser get operation', function (t) { + Mockgen().requests({ + path: '/user/login', + operation: 'get' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .get('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/user/login']['get']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/user/logout.js b/tests/user/logout.js new file mode 100644 index 0000000..279b45f --- /dev/null +++ b/tests/user/logout.js @@ -0,0 +1,71 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /user/logout + */ +Test('/user/logout', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Logs out current logged in user session + * description: + * parameters: + * produces: application/xml, application/json + * responses: default + */ + t.test('test logoutUser get operation', function (t) { + Mockgen().requests({ + path: '/user/logout', + operation: 'get' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .get('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + t.end(); + }); + }); + }); + }); +}); diff --git a/tests/user/{username}.js b/tests/user/{username}.js new file mode 100644 index 0000000..1a22a38 --- /dev/null +++ b/tests/user/{username}.js @@ -0,0 +1,161 @@ +'use strict'; +var Test = require('tape'); +var Express = require('express'); +var BodyParser = require('body-parser'); +var Swaggerize = require('swaggerize-express'); +var Path = require('path'); +var Request = require('supertest'); +var Mockgen = require('../../data/mockgen.js'); +var Parser = require('swagger-parser'); +/** + * Test for /user/{username} + */ +Test('/user/{username}', function (t) { + var apiPath = Path.resolve(__dirname, '../../config/swagger.json'); + var App = Express(); + App.use(BodyParser.json()); + App.use(BodyParser.urlencoded({ + extended: true + })); + App.use(Swaggerize({ + api: apiPath, + handlers: Path.resolve(__dirname, '../../handlers'), + security: Path.resolve(__dirname, '../../security') + })); + Parser.validate(apiPath, function (err, api) { + t.error(err, 'No parse error'); + t.ok(api, 'Valid swagger api'); + /** + * summary: Get user by user name + * description: + * parameters: username + * produces: application/xml, application/json + * responses: 200, 400, 404 + */ + t.test('test getUserByName get operation', function (t) { + Mockgen().requests({ + path: '/user/{username}', + operation: 'get' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .get('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 200, 'Ok response status'); + var Validator = require('is-my-json-valid'); + var validate = Validator(api.paths['/user/{username}']['get']['responses']['200']['schema']); + var response = res.body; + if (Object.keys(response).length <= 0) { + response = res.text; + } + t.ok(validate(response), 'Valid response'); + t.error(validate.errors, 'No validation errors'); + t.end(); + }); + }); + });/** + * summary: Updated user + * description: This can only be done by the logged in user. + * parameters: username, body + * produces: application/xml, application/json + * responses: 400, 404 + */ + t.test('test updateUser put operation', function (t) { + Mockgen().requests({ + path: '/user/{username}', + operation: 'put' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .put('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 400, 'Ok response status'); + t.end(); + }); + }); + });/** + * summary: Delete user + * description: This can only be done by the logged in user. + * parameters: username + * produces: application/xml, application/json + * responses: 400, 404 + */ + t.test('test deleteUser delete operation', function (t) { + Mockgen().requests({ + path: '/user/{username}', + operation: 'delete' + }, function (err, mock) { + var request; + t.error(err); + t.ok(mock); + t.ok(mock.request); + //Get the resolved path from mock request + //Mock request Path templates({}) are resolved using path parameters + request = Request(App) + .delete('/v2' + mock.request.path); + if (mock.request.body) { + //Send the request body + request = request.send(mock.request.body); + } else if (mock.request.formData){ + //Send the request form data + request = request.send(mock.request.formData); + //Set the Content-Type as application/x-www-form-urlencoded + request = request.set('Content-Type', 'application/x-www-form-urlencoded'); + } + // If headers are present, set the headers. + if (mock.request.headers && mock.request.headers.length > 0) { + Object.keys(mock.request.headers).forEach(function (headerName) { + request = request.set(headerName, mock.request.headers[headerName]); + }); + } + request.end(function (err, res) { + t.error(err, 'No error'); + t.ok(res.statusCode === 400, 'Ok response status'); + t.end(); + }); + }); + }); + }); +});