From 64b01f7800040fe5c3c699f2a49f3e0efcb2ae59 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 29 Mar 2016 22:53:42 +0800 Subject: [PATCH 1/3] update nodejs server sample --- .gitignore | 1 + .../server/petstore/nodejs-server/README.md | 24 + .../petstore/nodejs-server/api/swagger.yaml | 597 ++++++++++++++++++ .../petstore/nodejs-server/controllers/Pet.js | 35 + .../nodejs-server/controllers/PetService.js | 151 +++++ .../nodejs-server/controllers/Store.js | 19 + .../nodejs-server/controllers/StoreService.js | 69 ++ .../nodejs-server/controllers/User.js | 39 ++ .../nodejs-server/controllers/UserService.js | 120 ++++ .../server/petstore/nodejs-server/index.js | 40 ++ .../petstore/nodejs-server/package.json | 16 + 11 files changed, 1111 insertions(+) create mode 100644 samples/server/petstore/nodejs-server/README.md create mode 100644 samples/server/petstore/nodejs-server/api/swagger.yaml create mode 100644 samples/server/petstore/nodejs-server/controllers/Pet.js create mode 100644 samples/server/petstore/nodejs-server/controllers/PetService.js create mode 100644 samples/server/petstore/nodejs-server/controllers/Store.js create mode 100644 samples/server/petstore/nodejs-server/controllers/StoreService.js create mode 100644 samples/server/petstore/nodejs-server/controllers/User.js create mode 100644 samples/server/petstore/nodejs-server/controllers/UserService.js create mode 100644 samples/server/petstore/nodejs-server/index.js create mode 100644 samples/server/petstore/nodejs-server/package.json diff --git a/.gitignore b/.gitignore index 20b9a13e93f..094080c3e83 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ samples/server-generator/scalatra/output/.history # nodejs samples/server-generator/node/output/node_modules samples/server/petstore/nodejs/node_modules +samples/server/petstore/nodejs-server/node_modules # qt5 cpp samples/client/petstore/qt5cpp/PetStore/moc_* diff --git a/samples/server/petstore/nodejs-server/README.md b/samples/server/petstore/nodejs-server/README.md new file mode 100644 index 00000000000..d94aa385ec0 --- /dev/null +++ b/samples/server/petstore/nodejs-server/README.md @@ -0,0 +1,24 @@ +# Swagger generated server + +## Overview +This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. This is an example of building a node.js server. + +This example uses the [expressjs](http://expressjs.com/) framework. To see how to make this your own, look here: + +[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) + +### Running the server +To run the server, follow these simple steps: + +``` +npm install +node . +``` + +To view the Swagger UI interface: + +``` +open http://localhost:8080/docs +``` + +This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work. diff --git a/samples/server/petstore/nodejs-server/api/swagger.yaml b/samples/server/petstore/nodejs-server/api/swagger.yaml new file mode 100644 index 00000000000..d1395c001d4 --- /dev/null +++ b/samples/server/petstore/nodejs-server/api/swagger.yaml @@ -0,0 +1,597 @@ +--- +swagger: "2.0" +info: + description: "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io)\ + \ or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample,\ + \ you can use the api key `special-key` to test the authorization filters\n" + version: "1.0.0" + title: "Swagger Petstore" + termsOfService: "http://helloreverb.com/terms/" + contact: + name: "apiteam@swagger.io" + license: + name: "Apache 2.0" + url: "http://www.apache.org/licenses/LICENSE-2.0.html" +host: "petstore.swagger.io" +basePath: "/v2" +schemes: +- "http" +paths: + /pets: + post: + tags: + - "pet" + summary: "Add a new pet to the store" + description: "" + operationId: "addPet" + consumes: + - "application/json" + - "application/xml" + produces: + - "application/json" + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "Pet object that needs to be added to the store" + required: false + schema: + $ref: "#/definitions/Pet" + responses: + 405: + description: "Invalid input" + security: + - petstore_auth: + - "write_pets" + - "read_pets" + x-swagger-router-controller: "Pet" + put: + tags: + - "pet" + summary: "Update an existing pet" + description: "" + operationId: "updatePet" + consumes: + - "application/json" + - "application/xml" + produces: + - "application/json" + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "Pet object that needs to be added to the store" + required: false + schema: + $ref: "#/definitions/Pet" + responses: + 400: + description: "Invalid ID supplied" + 404: + description: "Pet not found" + 405: + description: "Validation exception" + security: + - petstore_auth: + - "write_pets" + - "read_pets" + x-swagger-router-controller: "Pet" + /pets/findByStatus: + get: + tags: + - "pet" + summary: "Finds Pets by status" + description: "Multiple status values can be provided with comma seperated strings" + operationId: "findPetsByStatus" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "status" + in: "query" + description: "Status values that need to be considered for filter" + required: false + type: "array" + items: + type: "string" + collectionFormat: "multi" + responses: + 200: + description: "successful operation" + schema: + type: "array" + items: + $ref: "#/definitions/Pet" + 400: + description: "Invalid status value" + security: + - petstore_auth: + - "write_pets" + - "read_pets" + x-swagger-router-controller: "Pet" + /pets/findByTags: + get: + tags: + - "pet" + summary: "Finds Pets by tags" + description: "Muliple tags can be provided with comma seperated strings. Use\ + \ tag1, tag2, tag3 for testing." + operationId: "findPetsByTags" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "tags" + in: "query" + description: "Tags to filter by" + required: false + type: "array" + items: + type: "string" + collectionFormat: "multi" + responses: + 200: + description: "successful operation" + schema: + type: "array" + items: + $ref: "#/definitions/Pet" + 400: + description: "Invalid tag value" + security: + - petstore_auth: + - "write_pets" + - "read_pets" + x-swagger-router-controller: "Pet" + /pets/{petId}: + get: + tags: + - "pet" + summary: "Find pet by ID" + description: "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate\ + \ API error conditions" + operationId: "getPetById" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "petId" + in: "path" + description: "ID of pet that needs to be fetched" + required: true + type: "integer" + format: "int64" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/Pet" + 400: + description: "Invalid ID supplied" + 404: + description: "Pet not found" + security: + - api_key: [] + - petstore_auth: + - "write_pets" + - "read_pets" + x-swagger-router-controller: "Pet" + post: + tags: + - "pet" + summary: "Updates a pet in the store with form data" + description: "" + operationId: "updatePetWithForm" + consumes: + - "application/x-www-form-urlencoded" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "petId" + in: "path" + description: "ID of pet that needs to be updated" + required: true + type: "string" + - name: "name" + in: "formData" + description: "Updated name of the pet" + required: true + type: "string" + - name: "status" + in: "formData" + description: "Updated status of the pet" + required: true + type: "string" + responses: + 405: + description: "Invalid input" + security: + - petstore_auth: + - "write_pets" + - "read_pets" + x-swagger-router-controller: "Pet" + delete: + tags: + - "pet" + summary: "Deletes a pet" + description: "" + operationId: "deletePet" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "api_key" + in: "header" + description: "" + required: true + type: "string" + - name: "petId" + in: "path" + description: "Pet id to delete" + required: true + type: "integer" + format: "int64" + responses: + 400: + description: "Invalid pet value" + security: + - petstore_auth: + - "write_pets" + - "read_pets" + x-swagger-router-controller: "Pet" + /stores/order: + post: + tags: + - "store" + summary: "Place an order for a pet" + description: "" + operationId: "placeOrder" + produces: + - "application/json" + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "order placed for purchasing the pet" + required: false + schema: + $ref: "#/definitions/Order" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/Order" + 400: + description: "Invalid Order" + x-swagger-router-controller: "Store" + /stores/order/{orderId}: + get: + tags: + - "store" + summary: "Find purchase order by ID" + description: "For valid response try integer IDs with value <= 5 or > 10. Other\ + \ values will generated exceptions" + operationId: "getOrderById" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "orderId" + in: "path" + description: "ID of pet that needs to be fetched" + required: true + type: "string" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/Order" + 400: + description: "Invalid ID supplied" + 404: + description: "Order not found" + x-swagger-router-controller: "Store" + delete: + tags: + - "store" + summary: "Delete purchase order by ID" + description: "For valid response try integer IDs with value < 1000. Anything\ + \ above 1000 or nonintegers will generate API errors" + operationId: "deleteOrder" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "orderId" + in: "path" + description: "ID of the order that needs to be deleted" + required: true + type: "string" + responses: + 400: + description: "Invalid ID supplied" + 404: + description: "Order not found" + x-swagger-router-controller: "Store" + /users: + post: + tags: + - "user" + summary: "Create user" + description: "This can only be done by the logged in user." + operationId: "createUser" + produces: + - "application/json" + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "Created user object" + required: false + schema: + $ref: "#/definitions/User" + responses: + default: + description: "successful operation" + x-swagger-router-controller: "User" + /users/createWithArray: + post: + tags: + - "user" + summary: "Creates list of users with given input array" + description: "" + operationId: "createUsersWithArrayInput" + produces: + - "application/json" + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "List of user object" + required: false + schema: + type: "array" + items: + $ref: "#/definitions/User" + responses: + default: + description: "successful operation" + x-swagger-router-controller: "User" + /users/createWithList: + post: + tags: + - "user" + summary: "Creates list of users with given input array" + description: "" + operationId: "createUsersWithListInput" + produces: + - "application/json" + - "application/xml" + parameters: + - in: "body" + name: "body" + description: "List of user object" + required: false + schema: + type: "array" + items: + $ref: "#/definitions/User" + responses: + default: + description: "successful operation" + x-swagger-router-controller: "User" + /users/login: + get: + tags: + - "user" + summary: "Logs user into the system" + description: "" + operationId: "loginUser" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "username" + in: "query" + description: "The user name for login" + required: false + type: "string" + - name: "password" + in: "query" + description: "The password for login in clear text" + required: false + type: "string" + responses: + 200: + description: "successful operation" + schema: + type: "string" + 400: + description: "Invalid username/password supplied" + x-swagger-router-controller: "User" + /users/logout: + get: + tags: + - "user" + summary: "Logs out current logged in user session" + description: "" + operationId: "logoutUser" + produces: + - "application/json" + - "application/xml" + parameters: [] + responses: + default: + description: "successful operation" + x-swagger-router-controller: "User" + /users/{username}: + get: + tags: + - "user" + summary: "Get user by user name" + description: "" + operationId: "getUserByName" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "username" + in: "path" + description: "The name that needs to be fetched. Use user1 for testing." + required: true + type: "string" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/User" + 400: + description: "Invalid username supplied" + 404: + description: "User not found" + x-swagger-router-controller: "User" + put: + tags: + - "user" + summary: "Updated user" + description: "This can only be done by the logged in user." + operationId: "updateUser" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "username" + in: "path" + description: "name that need to be deleted" + required: true + type: "string" + - in: "body" + name: "body" + description: "Updated user object" + required: false + schema: + $ref: "#/definitions/User" + responses: + 400: + description: "Invalid user supplied" + 404: + description: "User not found" + x-swagger-router-controller: "User" + delete: + tags: + - "user" + summary: "Delete user" + description: "This can only be done by the logged in user." + operationId: "deleteUser" + produces: + - "application/json" + - "application/xml" + parameters: + - name: "username" + in: "path" + description: "The name that needs to be deleted" + required: true + type: "string" + responses: + 400: + description: "Invalid username supplied" + 404: + description: "User not found" + x-swagger-router-controller: "User" +securityDefinitions: + api_key: + type: "apiKey" + name: "api_key" + in: "header" + petstore_auth: + type: "oauth2" + authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog" + flow: "implicit" + scopes: + write_pets: "modify pets in your account" + read_pets: "read your pets" +definitions: + User: + type: "object" + properties: + id: + type: "integer" + format: "int64" + username: + type: "string" + firstName: + type: "string" + lastName: + type: "string" + email: + type: "string" + password: + type: "string" + phone: + type: "string" + userStatus: + type: "integer" + format: "int32" + description: "User Status" + Category: + type: "object" + properties: + id: + type: "integer" + format: "int64" + name: + type: "string" + Pet: + type: "object" + required: + - "name" + - "photoUrls" + properties: + id: + type: "integer" + format: "int64" + category: + $ref: "#/definitions/Category" + name: + type: "string" + example: "doggie" + photoUrls: + type: "array" + items: + type: "string" + tags: + type: "array" + items: + $ref: "#/definitions/Tag" + status: + type: "string" + description: "pet status in the store" + Tag: + type: "object" + properties: + id: + type: "integer" + format: "int64" + name: + type: "string" + Order: + type: "object" + properties: + id: + type: "integer" + format: "int64" + petId: + type: "integer" + format: "int64" + quantity: + type: "integer" + format: "int32" + shipDate: + type: "string" + format: "date-time" + status: + type: "string" + description: "Order Status" + complete: + type: "boolean" diff --git a/samples/server/petstore/nodejs-server/controllers/Pet.js b/samples/server/petstore/nodejs-server/controllers/Pet.js new file mode 100644 index 00000000000..a7d196faa7c --- /dev/null +++ b/samples/server/petstore/nodejs-server/controllers/Pet.js @@ -0,0 +1,35 @@ +'use strict'; + +var url = require('url'); + + +var Pet = require('./PetService'); + + +module.exports.addPet = function addPet (req, res, next) { + Pet.addPet(req.swagger.params, res, next); +}; + +module.exports.deletePet = function deletePet (req, res, next) { + Pet.deletePet(req.swagger.params, res, next); +}; + +module.exports.findPetsByStatus = function findPetsByStatus (req, res, next) { + Pet.findPetsByStatus(req.swagger.params, res, next); +}; + +module.exports.findPetsByTags = function findPetsByTags (req, res, next) { + Pet.findPetsByTags(req.swagger.params, res, next); +}; + +module.exports.getPetById = function getPetById (req, res, next) { + Pet.getPetById(req.swagger.params, res, next); +}; + +module.exports.updatePet = function updatePet (req, res, next) { + Pet.updatePet(req.swagger.params, res, next); +}; + +module.exports.updatePetWithForm = function updatePetWithForm (req, res, next) { + Pet.updatePetWithForm(req.swagger.params, res, next); +}; diff --git a/samples/server/petstore/nodejs-server/controllers/PetService.js b/samples/server/petstore/nodejs-server/controllers/PetService.js new file mode 100644 index 00000000000..0cc11635e62 --- /dev/null +++ b/samples/server/petstore/nodejs-server/controllers/PetService.js @@ -0,0 +1,151 @@ +'use strict'; + +exports.addPet = function(args, res, next) { + /** + * parameters expected in the args: + * body (Pet) + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.deletePet = function(args, res, next) { + /** + * parameters expected in the args: + * apiKey (String) + * petId (Long) + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.findPetsByStatus = function(args, res, next) { + /** + * parameters expected in the args: + * status (List) + **/ + + + var examples = {}; + examples['application/json'] = [ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], + "id" : 123456789, + "category" : { + "id" : 123456789, + "name" : "aeiou" + }, + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ]; + + if(Object.keys(examples).length > 0) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); + } + else { + res.end(); + } + + +} + +exports.findPetsByTags = function(args, res, next) { + /** + * parameters expected in the args: + * tags (List) + **/ + + + var examples = {}; + examples['application/json'] = [ { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], + "id" : 123456789, + "category" : { + "id" : 123456789, + "name" : "aeiou" + }, + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +} ]; + + if(Object.keys(examples).length > 0) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); + } + else { + res.end(); + } + + +} + +exports.getPetById = function(args, res, next) { + /** + * parameters expected in the args: + * petId (Long) + **/ + + + var examples = {}; + examples['application/json'] = { + "tags" : [ { + "id" : 123456789, + "name" : "aeiou" + } ], + "id" : 123456789, + "category" : { + "id" : 123456789, + "name" : "aeiou" + }, + "status" : "aeiou", + "name" : "doggie", + "photoUrls" : [ "aeiou" ] +}; + + if(Object.keys(examples).length > 0) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); + } + else { + res.end(); + } + + +} + +exports.updatePet = function(args, res, next) { + /** + * parameters expected in the args: + * body (Pet) + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.updatePetWithForm = function(args, res, next) { + /** + * parameters expected in the args: + * petId (String) + * name (String) + * status (String) + **/ + // no response value expected for this operation + + + res.end(); +} + diff --git a/samples/server/petstore/nodejs-server/controllers/Store.js b/samples/server/petstore/nodejs-server/controllers/Store.js new file mode 100644 index 00000000000..95fcb02711e --- /dev/null +++ b/samples/server/petstore/nodejs-server/controllers/Store.js @@ -0,0 +1,19 @@ +'use strict'; + +var url = require('url'); + + +var Store = require('./StoreService'); + + +module.exports.deleteOrder = function deleteOrder (req, res, next) { + Store.deleteOrder(req.swagger.params, res, next); +}; + +module.exports.getOrderById = function getOrderById (req, res, next) { + Store.getOrderById(req.swagger.params, res, next); +}; + +module.exports.placeOrder = function placeOrder (req, res, next) { + Store.placeOrder(req.swagger.params, res, next); +}; diff --git a/samples/server/petstore/nodejs-server/controllers/StoreService.js b/samples/server/petstore/nodejs-server/controllers/StoreService.js new file mode 100644 index 00000000000..e10897a2443 --- /dev/null +++ b/samples/server/petstore/nodejs-server/controllers/StoreService.js @@ -0,0 +1,69 @@ +'use strict'; + +exports.deleteOrder = function(args, res, next) { + /** + * parameters expected in the args: + * orderId (String) + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.getOrderById = function(args, res, next) { + /** + * parameters expected in the args: + * orderId (String) + **/ + + + var examples = {}; + examples['application/json'] = { + "id" : 123456789, + "petId" : 123456789, + "complete" : true, + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2000-01-23T04:56:07.000+0000" +}; + + if(Object.keys(examples).length > 0) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); + } + else { + res.end(); + } + + +} + +exports.placeOrder = function(args, res, next) { + /** + * parameters expected in the args: + * body (Order) + **/ + + + var examples = {}; + examples['application/json'] = { + "id" : 123456789, + "petId" : 123456789, + "complete" : true, + "status" : "aeiou", + "quantity" : 123, + "shipDate" : "2000-01-23T04:56:07.000+0000" +}; + + if(Object.keys(examples).length > 0) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); + } + else { + res.end(); + } + + +} + diff --git a/samples/server/petstore/nodejs-server/controllers/User.js b/samples/server/petstore/nodejs-server/controllers/User.js new file mode 100644 index 00000000000..bac1d7f6a88 --- /dev/null +++ b/samples/server/petstore/nodejs-server/controllers/User.js @@ -0,0 +1,39 @@ +'use strict'; + +var url = require('url'); + + +var User = require('./UserService'); + + +module.exports.createUser = function createUser (req, res, next) { + User.createUser(req.swagger.params, res, next); +}; + +module.exports.createUsersWithArrayInput = function createUsersWithArrayInput (req, res, next) { + User.createUsersWithArrayInput(req.swagger.params, res, next); +}; + +module.exports.createUsersWithListInput = function createUsersWithListInput (req, res, next) { + User.createUsersWithListInput(req.swagger.params, res, next); +}; + +module.exports.deleteUser = function deleteUser (req, res, next) { + User.deleteUser(req.swagger.params, res, next); +}; + +module.exports.getUserByName = function getUserByName (req, res, next) { + User.getUserByName(req.swagger.params, res, next); +}; + +module.exports.loginUser = function loginUser (req, res, next) { + User.loginUser(req.swagger.params, res, next); +}; + +module.exports.logoutUser = function logoutUser (req, res, next) { + User.logoutUser(req.swagger.params, res, next); +}; + +module.exports.updateUser = function updateUser (req, res, next) { + User.updateUser(req.swagger.params, res, next); +}; diff --git a/samples/server/petstore/nodejs-server/controllers/UserService.js b/samples/server/petstore/nodejs-server/controllers/UserService.js new file mode 100644 index 00000000000..13ddbee03fc --- /dev/null +++ b/samples/server/petstore/nodejs-server/controllers/UserService.js @@ -0,0 +1,120 @@ +'use strict'; + +exports.createUser = function(args, res, next) { + /** + * parameters expected in the args: + * body (User) + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.createUsersWithArrayInput = function(args, res, next) { + /** + * parameters expected in the args: + * body (List) + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.createUsersWithListInput = function(args, res, next) { + /** + * parameters expected in the args: + * body (List) + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.deleteUser = function(args, res, next) { + /** + * parameters expected in the args: + * username (String) + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.getUserByName = function(args, res, next) { + /** + * parameters expected in the args: + * username (String) + **/ + + + var examples = {}; + examples['application/json'] = { + "id" : 123456789, + "lastName" : "aeiou", + "phone" : "aeiou", + "username" : "aeiou", + "email" : "aeiou", + "userStatus" : 123, + "firstName" : "aeiou", + "password" : "aeiou" +}; + + if(Object.keys(examples).length > 0) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); + } + else { + res.end(); + } + + +} + +exports.loginUser = function(args, res, next) { + /** + * parameters expected in the args: + * username (String) + * password (String) + **/ + + + var examples = {}; + examples['application/json'] = "aeiou"; + + if(Object.keys(examples).length > 0) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); + } + else { + res.end(); + } + + +} + +exports.logoutUser = function(args, res, next) { + /** + * parameters expected in the args: + **/ + // no response value expected for this operation + + + res.end(); +} + +exports.updateUser = function(args, res, next) { + /** + * parameters expected in the args: + * username (String) + * body (User) + **/ + // no response value expected for this operation + + + res.end(); +} + diff --git a/samples/server/petstore/nodejs-server/index.js b/samples/server/petstore/nodejs-server/index.js new file mode 100644 index 00000000000..aaa873a128a --- /dev/null +++ b/samples/server/petstore/nodejs-server/index.js @@ -0,0 +1,40 @@ +'use strict'; + +var app = require('connect')(); +var http = require('http'); +var swaggerTools = require('swagger-tools'); +var jsyaml = require('js-yaml'); +var fs = require('fs'); +var serverPort = 8080; + +// swaggerRouter configuration +var options = { + swaggerUi: '/swagger.json', + controllers: './controllers', + useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode) +}; + +// The Swagger document (require it, build it programmatically, fetch it from a URL, ...) +var spec = fs.readFileSync('./api/swagger.yaml', 'utf8'); +var swaggerDoc = jsyaml.safeLoad(spec); + +// Initialize the Swagger middleware +swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) { + // Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain + app.use(middleware.swaggerMetadata()); + + // Validate Swagger requests + app.use(middleware.swaggerValidator()); + + // Route validated requests to appropriate controller + app.use(middleware.swaggerRouter(options)); + + // Serve the Swagger documents and Swagger UI + app.use(middleware.swaggerUi()); + + // Start the server + http.createServer(app).listen(serverPort, function () { + console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort); + console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort); + }); +}); diff --git a/samples/server/petstore/nodejs-server/package.json b/samples/server/petstore/nodejs-server/package.json new file mode 100644 index 00000000000..5f706710b99 --- /dev/null +++ b/samples/server/petstore/nodejs-server/package.json @@ -0,0 +1,16 @@ +{ + "name": "swagger-petstore", + "version": "1.0.0", + "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters", + "main": "index.js", + "keywords": [ + "swagger" + ], + "license": "MIT", + "private": true, + "dependencies": { + "connect": "^3.2.0", + "js-yaml": "^3.3.0", + "swagger-tools": "0.9.*" + } +} From 35edb00e9b3098b909485b5d1bca2ea84557d2fd Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 9 Apr 2016 18:12:46 +0800 Subject: [PATCH 2/3] update nodejs server sample --- .../server/petstore/nodejs-server/README.md | 24 - .../petstore/nodejs-server/api/swagger.yaml | 597 ------------------ .../petstore/nodejs-server/controllers/Pet.js | 35 - .../nodejs-server/controllers/PetService.js | 151 ----- .../nodejs-server/controllers/Store.js | 19 - .../nodejs-server/controllers/StoreService.js | 69 -- .../nodejs-server/controllers/User.js | 39 -- .../nodejs-server/controllers/UserService.js | 120 ---- .../server/petstore/nodejs-server/index.js | 40 -- .../petstore/nodejs-server/package.json | 16 - .../server/petstore/nodejs/api/swagger.yaml | 350 ++++------ .../server/petstore/nodejs/controllers/Pet.js | 4 - .../petstore/nodejs/controllers/PetService.js | 57 +- .../petstore/nodejs/controllers/Store.js | 4 - .../nodejs/controllers/StoreService.js | 40 +- .../nodejs/controllers/UserService.js | 24 +- samples/server/petstore/nodejs/package.json | 2 +- 17 files changed, 127 insertions(+), 1464 deletions(-) delete mode 100644 samples/server/petstore/nodejs-server/README.md delete mode 100644 samples/server/petstore/nodejs-server/api/swagger.yaml delete mode 100644 samples/server/petstore/nodejs-server/controllers/Pet.js delete mode 100644 samples/server/petstore/nodejs-server/controllers/PetService.js delete mode 100644 samples/server/petstore/nodejs-server/controllers/Store.js delete mode 100644 samples/server/petstore/nodejs-server/controllers/StoreService.js delete mode 100644 samples/server/petstore/nodejs-server/controllers/User.js delete mode 100644 samples/server/petstore/nodejs-server/controllers/UserService.js delete mode 100644 samples/server/petstore/nodejs-server/index.js delete mode 100644 samples/server/petstore/nodejs-server/package.json diff --git a/samples/server/petstore/nodejs-server/README.md b/samples/server/petstore/nodejs-server/README.md deleted file mode 100644 index d94aa385ec0..00000000000 --- a/samples/server/petstore/nodejs-server/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Swagger generated server - -## Overview -This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. This is an example of building a node.js server. - -This example uses the [expressjs](http://expressjs.com/) framework. To see how to make this your own, look here: - -[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - -### Running the server -To run the server, follow these simple steps: - -``` -npm install -node . -``` - -To view the Swagger UI interface: - -``` -open http://localhost:8080/docs -``` - -This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work. diff --git a/samples/server/petstore/nodejs-server/api/swagger.yaml b/samples/server/petstore/nodejs-server/api/swagger.yaml deleted file mode 100644 index d1395c001d4..00000000000 --- a/samples/server/petstore/nodejs-server/api/swagger.yaml +++ /dev/null @@ -1,597 +0,0 @@ ---- -swagger: "2.0" -info: - description: "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io)\ - \ or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample,\ - \ you can use the api key `special-key` to test the authorization filters\n" - version: "1.0.0" - title: "Swagger Petstore" - termsOfService: "http://helloreverb.com/terms/" - contact: - name: "apiteam@swagger.io" - license: - name: "Apache 2.0" - url: "http://www.apache.org/licenses/LICENSE-2.0.html" -host: "petstore.swagger.io" -basePath: "/v2" -schemes: -- "http" -paths: - /pets: - post: - tags: - - "pet" - summary: "Add a new pet to the store" - description: "" - operationId: "addPet" - consumes: - - "application/json" - - "application/xml" - produces: - - "application/json" - - "application/xml" - parameters: - - in: "body" - name: "body" - description: "Pet object that needs to be added to the store" - required: false - schema: - $ref: "#/definitions/Pet" - responses: - 405: - description: "Invalid input" - security: - - petstore_auth: - - "write_pets" - - "read_pets" - x-swagger-router-controller: "Pet" - put: - tags: - - "pet" - summary: "Update an existing pet" - description: "" - operationId: "updatePet" - consumes: - - "application/json" - - "application/xml" - produces: - - "application/json" - - "application/xml" - parameters: - - in: "body" - name: "body" - description: "Pet object that needs to be added to the store" - required: false - schema: - $ref: "#/definitions/Pet" - responses: - 400: - description: "Invalid ID supplied" - 404: - description: "Pet not found" - 405: - description: "Validation exception" - security: - - petstore_auth: - - "write_pets" - - "read_pets" - x-swagger-router-controller: "Pet" - /pets/findByStatus: - get: - tags: - - "pet" - summary: "Finds Pets by status" - description: "Multiple status values can be provided with comma seperated strings" - operationId: "findPetsByStatus" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "status" - in: "query" - description: "Status values that need to be considered for filter" - required: false - type: "array" - items: - type: "string" - collectionFormat: "multi" - responses: - 200: - description: "successful operation" - schema: - type: "array" - items: - $ref: "#/definitions/Pet" - 400: - description: "Invalid status value" - security: - - petstore_auth: - - "write_pets" - - "read_pets" - x-swagger-router-controller: "Pet" - /pets/findByTags: - get: - tags: - - "pet" - summary: "Finds Pets by tags" - description: "Muliple tags can be provided with comma seperated strings. Use\ - \ tag1, tag2, tag3 for testing." - operationId: "findPetsByTags" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "tags" - in: "query" - description: "Tags to filter by" - required: false - type: "array" - items: - type: "string" - collectionFormat: "multi" - responses: - 200: - description: "successful operation" - schema: - type: "array" - items: - $ref: "#/definitions/Pet" - 400: - description: "Invalid tag value" - security: - - petstore_auth: - - "write_pets" - - "read_pets" - x-swagger-router-controller: "Pet" - /pets/{petId}: - get: - tags: - - "pet" - summary: "Find pet by ID" - description: "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate\ - \ API error conditions" - operationId: "getPetById" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "petId" - in: "path" - description: "ID of pet that needs to be fetched" - required: true - type: "integer" - format: "int64" - responses: - 200: - description: "successful operation" - schema: - $ref: "#/definitions/Pet" - 400: - description: "Invalid ID supplied" - 404: - description: "Pet not found" - security: - - api_key: [] - - petstore_auth: - - "write_pets" - - "read_pets" - x-swagger-router-controller: "Pet" - post: - tags: - - "pet" - summary: "Updates a pet in the store with form data" - description: "" - operationId: "updatePetWithForm" - consumes: - - "application/x-www-form-urlencoded" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "petId" - in: "path" - description: "ID of pet that needs to be updated" - required: true - type: "string" - - name: "name" - in: "formData" - description: "Updated name of the pet" - required: true - type: "string" - - name: "status" - in: "formData" - description: "Updated status of the pet" - required: true - type: "string" - responses: - 405: - description: "Invalid input" - security: - - petstore_auth: - - "write_pets" - - "read_pets" - x-swagger-router-controller: "Pet" - delete: - tags: - - "pet" - summary: "Deletes a pet" - description: "" - operationId: "deletePet" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "api_key" - in: "header" - description: "" - required: true - type: "string" - - name: "petId" - in: "path" - description: "Pet id to delete" - required: true - type: "integer" - format: "int64" - responses: - 400: - description: "Invalid pet value" - security: - - petstore_auth: - - "write_pets" - - "read_pets" - x-swagger-router-controller: "Pet" - /stores/order: - post: - tags: - - "store" - summary: "Place an order for a pet" - description: "" - operationId: "placeOrder" - produces: - - "application/json" - - "application/xml" - parameters: - - in: "body" - name: "body" - description: "order placed for purchasing the pet" - required: false - schema: - $ref: "#/definitions/Order" - responses: - 200: - description: "successful operation" - schema: - $ref: "#/definitions/Order" - 400: - description: "Invalid Order" - x-swagger-router-controller: "Store" - /stores/order/{orderId}: - get: - tags: - - "store" - summary: "Find purchase order by ID" - description: "For valid response try integer IDs with value <= 5 or > 10. Other\ - \ values will generated exceptions" - operationId: "getOrderById" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "orderId" - in: "path" - description: "ID of pet that needs to be fetched" - required: true - type: "string" - responses: - 200: - description: "successful operation" - schema: - $ref: "#/definitions/Order" - 400: - description: "Invalid ID supplied" - 404: - description: "Order not found" - x-swagger-router-controller: "Store" - delete: - tags: - - "store" - summary: "Delete purchase order by ID" - description: "For valid response try integer IDs with value < 1000. Anything\ - \ above 1000 or nonintegers will generate API errors" - operationId: "deleteOrder" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "orderId" - in: "path" - description: "ID of the order that needs to be deleted" - required: true - type: "string" - responses: - 400: - description: "Invalid ID supplied" - 404: - description: "Order not found" - x-swagger-router-controller: "Store" - /users: - post: - tags: - - "user" - summary: "Create user" - description: "This can only be done by the logged in user." - operationId: "createUser" - produces: - - "application/json" - - "application/xml" - parameters: - - in: "body" - name: "body" - description: "Created user object" - required: false - schema: - $ref: "#/definitions/User" - responses: - default: - description: "successful operation" - x-swagger-router-controller: "User" - /users/createWithArray: - post: - tags: - - "user" - summary: "Creates list of users with given input array" - description: "" - operationId: "createUsersWithArrayInput" - produces: - - "application/json" - - "application/xml" - parameters: - - in: "body" - name: "body" - description: "List of user object" - required: false - schema: - type: "array" - items: - $ref: "#/definitions/User" - responses: - default: - description: "successful operation" - x-swagger-router-controller: "User" - /users/createWithList: - post: - tags: - - "user" - summary: "Creates list of users with given input array" - description: "" - operationId: "createUsersWithListInput" - produces: - - "application/json" - - "application/xml" - parameters: - - in: "body" - name: "body" - description: "List of user object" - required: false - schema: - type: "array" - items: - $ref: "#/definitions/User" - responses: - default: - description: "successful operation" - x-swagger-router-controller: "User" - /users/login: - get: - tags: - - "user" - summary: "Logs user into the system" - description: "" - operationId: "loginUser" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "username" - in: "query" - description: "The user name for login" - required: false - type: "string" - - name: "password" - in: "query" - description: "The password for login in clear text" - required: false - type: "string" - responses: - 200: - description: "successful operation" - schema: - type: "string" - 400: - description: "Invalid username/password supplied" - x-swagger-router-controller: "User" - /users/logout: - get: - tags: - - "user" - summary: "Logs out current logged in user session" - description: "" - operationId: "logoutUser" - produces: - - "application/json" - - "application/xml" - parameters: [] - responses: - default: - description: "successful operation" - x-swagger-router-controller: "User" - /users/{username}: - get: - tags: - - "user" - summary: "Get user by user name" - description: "" - operationId: "getUserByName" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "username" - in: "path" - description: "The name that needs to be fetched. Use user1 for testing." - required: true - type: "string" - responses: - 200: - description: "successful operation" - schema: - $ref: "#/definitions/User" - 400: - description: "Invalid username supplied" - 404: - description: "User not found" - x-swagger-router-controller: "User" - put: - tags: - - "user" - summary: "Updated user" - description: "This can only be done by the logged in user." - operationId: "updateUser" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "username" - in: "path" - description: "name that need to be deleted" - required: true - type: "string" - - in: "body" - name: "body" - description: "Updated user object" - required: false - schema: - $ref: "#/definitions/User" - responses: - 400: - description: "Invalid user supplied" - 404: - description: "User not found" - x-swagger-router-controller: "User" - delete: - tags: - - "user" - summary: "Delete user" - description: "This can only be done by the logged in user." - operationId: "deleteUser" - produces: - - "application/json" - - "application/xml" - parameters: - - name: "username" - in: "path" - description: "The name that needs to be deleted" - required: true - type: "string" - responses: - 400: - description: "Invalid username supplied" - 404: - description: "User not found" - x-swagger-router-controller: "User" -securityDefinitions: - api_key: - type: "apiKey" - name: "api_key" - in: "header" - petstore_auth: - type: "oauth2" - authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog" - flow: "implicit" - scopes: - write_pets: "modify pets in your account" - read_pets: "read your pets" -definitions: - User: - type: "object" - properties: - id: - type: "integer" - format: "int64" - username: - type: "string" - firstName: - type: "string" - lastName: - type: "string" - email: - type: "string" - password: - type: "string" - phone: - type: "string" - userStatus: - type: "integer" - format: "int32" - description: "User Status" - Category: - type: "object" - properties: - id: - type: "integer" - format: "int64" - name: - type: "string" - Pet: - type: "object" - required: - - "name" - - "photoUrls" - properties: - id: - type: "integer" - format: "int64" - category: - $ref: "#/definitions/Category" - name: - type: "string" - example: "doggie" - photoUrls: - type: "array" - items: - type: "string" - tags: - type: "array" - items: - $ref: "#/definitions/Tag" - status: - type: "string" - description: "pet status in the store" - Tag: - type: "object" - properties: - id: - type: "integer" - format: "int64" - name: - type: "string" - Order: - type: "object" - properties: - id: - type: "integer" - format: "int64" - petId: - type: "integer" - format: "int64" - quantity: - type: "integer" - format: "int32" - shipDate: - type: "string" - format: "date-time" - status: - type: "string" - description: "Order Status" - complete: - type: "boolean" diff --git a/samples/server/petstore/nodejs-server/controllers/Pet.js b/samples/server/petstore/nodejs-server/controllers/Pet.js deleted file mode 100644 index a7d196faa7c..00000000000 --- a/samples/server/petstore/nodejs-server/controllers/Pet.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -var url = require('url'); - - -var Pet = require('./PetService'); - - -module.exports.addPet = function addPet (req, res, next) { - Pet.addPet(req.swagger.params, res, next); -}; - -module.exports.deletePet = function deletePet (req, res, next) { - Pet.deletePet(req.swagger.params, res, next); -}; - -module.exports.findPetsByStatus = function findPetsByStatus (req, res, next) { - Pet.findPetsByStatus(req.swagger.params, res, next); -}; - -module.exports.findPetsByTags = function findPetsByTags (req, res, next) { - Pet.findPetsByTags(req.swagger.params, res, next); -}; - -module.exports.getPetById = function getPetById (req, res, next) { - Pet.getPetById(req.swagger.params, res, next); -}; - -module.exports.updatePet = function updatePet (req, res, next) { - Pet.updatePet(req.swagger.params, res, next); -}; - -module.exports.updatePetWithForm = function updatePetWithForm (req, res, next) { - Pet.updatePetWithForm(req.swagger.params, res, next); -}; diff --git a/samples/server/petstore/nodejs-server/controllers/PetService.js b/samples/server/petstore/nodejs-server/controllers/PetService.js deleted file mode 100644 index 0cc11635e62..00000000000 --- a/samples/server/petstore/nodejs-server/controllers/PetService.js +++ /dev/null @@ -1,151 +0,0 @@ -'use strict'; - -exports.addPet = function(args, res, next) { - /** - * parameters expected in the args: - * body (Pet) - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.deletePet = function(args, res, next) { - /** - * parameters expected in the args: - * apiKey (String) - * petId (Long) - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.findPetsByStatus = function(args, res, next) { - /** - * parameters expected in the args: - * status (List) - **/ - - - var examples = {}; - examples['application/json'] = [ { - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], - "id" : 123456789, - "category" : { - "id" : 123456789, - "name" : "aeiou" - }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -} ]; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - -exports.findPetsByTags = function(args, res, next) { - /** - * parameters expected in the args: - * tags (List) - **/ - - - var examples = {}; - examples['application/json'] = [ { - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], - "id" : 123456789, - "category" : { - "id" : 123456789, - "name" : "aeiou" - }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -} ]; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - -exports.getPetById = function(args, res, next) { - /** - * parameters expected in the args: - * petId (Long) - **/ - - - var examples = {}; - examples['application/json'] = { - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], - "id" : 123456789, - "category" : { - "id" : 123456789, - "name" : "aeiou" - }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -}; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - -exports.updatePet = function(args, res, next) { - /** - * parameters expected in the args: - * body (Pet) - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.updatePetWithForm = function(args, res, next) { - /** - * parameters expected in the args: - * petId (String) - * name (String) - * status (String) - **/ - // no response value expected for this operation - - - res.end(); -} - diff --git a/samples/server/petstore/nodejs-server/controllers/Store.js b/samples/server/petstore/nodejs-server/controllers/Store.js deleted file mode 100644 index 95fcb02711e..00000000000 --- a/samples/server/petstore/nodejs-server/controllers/Store.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -var url = require('url'); - - -var Store = require('./StoreService'); - - -module.exports.deleteOrder = function deleteOrder (req, res, next) { - Store.deleteOrder(req.swagger.params, res, next); -}; - -module.exports.getOrderById = function getOrderById (req, res, next) { - Store.getOrderById(req.swagger.params, res, next); -}; - -module.exports.placeOrder = function placeOrder (req, res, next) { - Store.placeOrder(req.swagger.params, res, next); -}; diff --git a/samples/server/petstore/nodejs-server/controllers/StoreService.js b/samples/server/petstore/nodejs-server/controllers/StoreService.js deleted file mode 100644 index e10897a2443..00000000000 --- a/samples/server/petstore/nodejs-server/controllers/StoreService.js +++ /dev/null @@ -1,69 +0,0 @@ -'use strict'; - -exports.deleteOrder = function(args, res, next) { - /** - * parameters expected in the args: - * orderId (String) - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.getOrderById = function(args, res, next) { - /** - * parameters expected in the args: - * orderId (String) - **/ - - - var examples = {}; - examples['application/json'] = { - "id" : 123456789, - "petId" : 123456789, - "complete" : true, - "status" : "aeiou", - "quantity" : 123, - "shipDate" : "2000-01-23T04:56:07.000+0000" -}; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - -exports.placeOrder = function(args, res, next) { - /** - * parameters expected in the args: - * body (Order) - **/ - - - var examples = {}; - examples['application/json'] = { - "id" : 123456789, - "petId" : 123456789, - "complete" : true, - "status" : "aeiou", - "quantity" : 123, - "shipDate" : "2000-01-23T04:56:07.000+0000" -}; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - diff --git a/samples/server/petstore/nodejs-server/controllers/User.js b/samples/server/petstore/nodejs-server/controllers/User.js deleted file mode 100644 index bac1d7f6a88..00000000000 --- a/samples/server/petstore/nodejs-server/controllers/User.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -var url = require('url'); - - -var User = require('./UserService'); - - -module.exports.createUser = function createUser (req, res, next) { - User.createUser(req.swagger.params, res, next); -}; - -module.exports.createUsersWithArrayInput = function createUsersWithArrayInput (req, res, next) { - User.createUsersWithArrayInput(req.swagger.params, res, next); -}; - -module.exports.createUsersWithListInput = function createUsersWithListInput (req, res, next) { - User.createUsersWithListInput(req.swagger.params, res, next); -}; - -module.exports.deleteUser = function deleteUser (req, res, next) { - User.deleteUser(req.swagger.params, res, next); -}; - -module.exports.getUserByName = function getUserByName (req, res, next) { - User.getUserByName(req.swagger.params, res, next); -}; - -module.exports.loginUser = function loginUser (req, res, next) { - User.loginUser(req.swagger.params, res, next); -}; - -module.exports.logoutUser = function logoutUser (req, res, next) { - User.logoutUser(req.swagger.params, res, next); -}; - -module.exports.updateUser = function updateUser (req, res, next) { - User.updateUser(req.swagger.params, res, next); -}; diff --git a/samples/server/petstore/nodejs-server/controllers/UserService.js b/samples/server/petstore/nodejs-server/controllers/UserService.js deleted file mode 100644 index 13ddbee03fc..00000000000 --- a/samples/server/petstore/nodejs-server/controllers/UserService.js +++ /dev/null @@ -1,120 +0,0 @@ -'use strict'; - -exports.createUser = function(args, res, next) { - /** - * parameters expected in the args: - * body (User) - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.createUsersWithArrayInput = function(args, res, next) { - /** - * parameters expected in the args: - * body (List) - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.createUsersWithListInput = function(args, res, next) { - /** - * parameters expected in the args: - * body (List) - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.deleteUser = function(args, res, next) { - /** - * parameters expected in the args: - * username (String) - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.getUserByName = function(args, res, next) { - /** - * parameters expected in the args: - * username (String) - **/ - - - var examples = {}; - examples['application/json'] = { - "id" : 123456789, - "lastName" : "aeiou", - "phone" : "aeiou", - "username" : "aeiou", - "email" : "aeiou", - "userStatus" : 123, - "firstName" : "aeiou", - "password" : "aeiou" -}; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - -exports.loginUser = function(args, res, next) { - /** - * parameters expected in the args: - * username (String) - * password (String) - **/ - - - var examples = {}; - examples['application/json'] = "aeiou"; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - -exports.logoutUser = function(args, res, next) { - /** - * parameters expected in the args: - **/ - // no response value expected for this operation - - - res.end(); -} - -exports.updateUser = function(args, res, next) { - /** - * parameters expected in the args: - * username (String) - * body (User) - **/ - // no response value expected for this operation - - - res.end(); -} - diff --git a/samples/server/petstore/nodejs-server/index.js b/samples/server/petstore/nodejs-server/index.js deleted file mode 100644 index aaa873a128a..00000000000 --- a/samples/server/petstore/nodejs-server/index.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -var app = require('connect')(); -var http = require('http'); -var swaggerTools = require('swagger-tools'); -var jsyaml = require('js-yaml'); -var fs = require('fs'); -var serverPort = 8080; - -// swaggerRouter configuration -var options = { - swaggerUi: '/swagger.json', - controllers: './controllers', - useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode) -}; - -// The Swagger document (require it, build it programmatically, fetch it from a URL, ...) -var spec = fs.readFileSync('./api/swagger.yaml', 'utf8'); -var swaggerDoc = jsyaml.safeLoad(spec); - -// Initialize the Swagger middleware -swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) { - // Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain - app.use(middleware.swaggerMetadata()); - - // Validate Swagger requests - app.use(middleware.swaggerValidator()); - - // Route validated requests to appropriate controller - app.use(middleware.swaggerRouter(options)); - - // Serve the Swagger documents and Swagger UI - app.use(middleware.swaggerUi()); - - // Start the server - http.createServer(app).listen(serverPort, function () { - console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort); - console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort); - }); -}); diff --git a/samples/server/petstore/nodejs-server/package.json b/samples/server/petstore/nodejs-server/package.json deleted file mode 100644 index 5f706710b99..00000000000 --- a/samples/server/petstore/nodejs-server/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "swagger-petstore", - "version": "1.0.0", - "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters", - "main": "index.js", - "keywords": [ - "swagger" - ], - "license": "MIT", - "private": true, - "dependencies": { - "connect": "^3.2.0", - "js-yaml": "^3.3.0", - "swagger-tools": "0.9.*" - } -} diff --git a/samples/server/petstore/nodejs/api/swagger.yaml b/samples/server/petstore/nodejs/api/swagger.yaml index 3cbdf63c594..d1395c001d4 100644 --- a/samples/server/petstore/nodejs/api/swagger.yaml +++ b/samples/server/petstore/nodejs/api/swagger.yaml @@ -1,53 +1,40 @@ --- swagger: "2.0" info: - description: "This is a sample server Petstore server. You can find out more about\n\ - Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\n\ - For this sample, you can use the api key `special-key` to test the authorization\ - \ filters.\n" + description: "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io)\ + \ or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample,\ + \ you can use the api key `special-key` to test the authorization filters\n" version: "1.0.0" title: "Swagger Petstore" - termsOfService: "http://swagger.io/terms/" + termsOfService: "http://helloreverb.com/terms/" contact: - email: "apiteam@swagger.io" + name: "apiteam@swagger.io" license: name: "Apache 2.0" url: "http://www.apache.org/licenses/LICENSE-2.0.html" host: "petstore.swagger.io" basePath: "/v2" -tags: -- name: "pet" - description: "Everything about your Pets" - externalDocs: - description: "Find out more" - url: "http://swagger.io" -- name: "store" - description: "Access to Petstore orders" -- name: "user" - description: "Operations about user" - externalDocs: - description: "Find out more about our store" - url: "http://swagger.io" schemes: - "http" paths: - /pet: + /pets: post: tags: - "pet" summary: "Add a new pet to the store" + description: "" operationId: "addPet" consumes: - "application/json" - "application/xml" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - in: "body" name: "body" description: "Pet object that needs to be added to the store" - required: true + required: false schema: $ref: "#/definitions/Pet" responses: @@ -55,25 +42,26 @@ paths: description: "Invalid input" security: - petstore_auth: - - "write:pets" - - "read:pets" + - "write_pets" + - "read_pets" x-swagger-router-controller: "Pet" put: tags: - "pet" summary: "Update an existing pet" + description: "" operationId: "updatePet" consumes: - "application/json" - "application/xml" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - in: "body" name: "body" description: "Pet object that needs to be added to the store" - required: true + required: false schema: $ref: "#/definitions/Pet" responses: @@ -85,32 +73,27 @@ paths: description: "Validation exception" security: - petstore_auth: - - "write:pets" - - "read:pets" + - "write_pets" + - "read_pets" x-swagger-router-controller: "Pet" - /pet/findByStatus: + /pets/findByStatus: get: tags: - "pet" summary: "Finds Pets by status" - description: "Multiple status values can be provided with comma separated strings" + description: "Multiple status values can be provided with comma seperated strings" operationId: "findPetsByStatus" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "status" in: "query" description: "Status values that need to be considered for filter" - required: true + required: false type: "array" items: type: "string" - default: "available" - enum: - - "available" - - "pending" - - "sold" collectionFormat: "multi" responses: 200: @@ -123,25 +106,25 @@ paths: description: "Invalid status value" security: - petstore_auth: - - "write:pets" - - "read:pets" + - "write_pets" + - "read_pets" x-swagger-router-controller: "Pet" - /pet/findByTags: + /pets/findByTags: get: tags: - "pet" summary: "Finds Pets by tags" - description: "Muliple tags can be provided with comma separated strings. Use\n\ - tag1, tag2, tag3 for testing.\n" + description: "Muliple tags can be provided with comma seperated strings. Use\ + \ tag1, tag2, tag3 for testing." operationId: "findPetsByTags" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "tags" in: "query" description: "Tags to filter by" - required: true + required: false type: "array" items: type: "string" @@ -157,24 +140,24 @@ paths: description: "Invalid tag value" security: - petstore_auth: - - "write:pets" - - "read:pets" - deprecated: true + - "write_pets" + - "read_pets" x-swagger-router-controller: "Pet" - /pet/{petId}: + /pets/{petId}: get: tags: - "pet" summary: "Find pet by ID" - description: "Returns a single pet" + description: "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate\ + \ API error conditions" operationId: "getPetById" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "petId" in: "path" - description: "ID of pet to return" + description: "ID of pet that needs to be fetched" required: true type: "integer" format: "int64" @@ -189,55 +172,59 @@ paths: description: "Pet not found" security: - api_key: [] + - petstore_auth: + - "write_pets" + - "read_pets" x-swagger-router-controller: "Pet" post: tags: - "pet" summary: "Updates a pet in the store with form data" - description: "null" + description: "" operationId: "updatePetWithForm" consumes: - "application/x-www-form-urlencoded" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "petId" in: "path" description: "ID of pet that needs to be updated" required: true - type: "integer" - format: "int64" + type: "string" - name: "name" in: "formData" description: "Updated name of the pet" - required: false + required: true type: "string" - name: "status" in: "formData" description: "Updated status of the pet" - required: false + required: true type: "string" responses: 405: description: "Invalid input" security: - petstore_auth: - - "write:pets" - - "read:pets" + - "write_pets" + - "read_pets" x-swagger-router-controller: "Pet" delete: tags: - "pet" summary: "Deletes a pet" + description: "" operationId: "deletePet" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "api_key" in: "header" - required: false + description: "" + required: true type: "string" - name: "petId" in: "path" @@ -247,86 +234,27 @@ paths: format: "int64" responses: 400: - description: "Invalid ID supplied" - 404: - description: "Pet not found" + description: "Invalid pet value" security: - petstore_auth: - - "write:pets" - - "read:pets" + - "write_pets" + - "read_pets" x-swagger-router-controller: "Pet" - /pet/{petId}/uploadImage: - post: - tags: - - "pet" - summary: "uploads an image" - operationId: "uploadFile" - consumes: - - "multipart/form-data" - produces: - - "application/json" - parameters: - - name: "petId" - in: "path" - description: "ID of pet to update" - required: true - type: "integer" - format: "int64" - - name: "additionalMetadata" - in: "formData" - description: "Additional data to pass to server" - required: false - type: "string" - - name: "file" - in: "formData" - description: "file to upload" - required: false - type: "file" - responses: - 200: - description: "successful operation" - schema: - $ref: "#/definitions/ApiResponse" - security: - - petstore_auth: - - "write:pets" - - "read:pets" - x-swagger-router-controller: "Pet" - /store/inventory: - get: - tags: - - "store" - summary: "Returns pet inventories by status" - description: "Returns a map of status codes to quantities" - operationId: "getInventory" - produces: - - "application/json" - parameters: [] - responses: - 200: - description: "successful operation" - schema: - type: "object" - additionalProperties: - type: "integer" - format: "int32" - security: - - api_key: [] - x-swagger-router-controller: "Store" - /store/order: + /stores/order: post: tags: - "store" summary: "Place an order for a pet" + description: "" operationId: "placeOrder" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - in: "body" name: "body" description: "order placed for purchasing the pet" - required: true + required: false schema: $ref: "#/definitions/Order" responses: @@ -337,26 +265,23 @@ paths: 400: description: "Invalid Order" x-swagger-router-controller: "Store" - /store/order/{orderId}: + /stores/order/{orderId}: get: tags: - "store" summary: "Find purchase order by ID" - description: "For valid response try integer IDs with value >= 1 and <= 10.\n\ - Other values will generated exceptions\n" + description: "For valid response try integer IDs with value <= 5 or > 10. Other\ + \ values will generated exceptions" operationId: "getOrderById" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "orderId" in: "path" description: "ID of pet that needs to be fetched" required: true - type: "integer" - maximum: 10 - minimum: 1 - format: "int64" + type: "string" responses: 200: description: "successful operation" @@ -371,27 +296,25 @@ paths: tags: - "store" summary: "Delete purchase order by ID" - description: "For valid response try integer IDs with positive integer value.\\\ - \ \\ Negative or non-integer values will generate API errors" + description: "For valid response try integer IDs with value < 1000. Anything\ + \ above 1000 or nonintegers will generate API errors" operationId: "deleteOrder" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "orderId" in: "path" description: "ID of the order that needs to be deleted" required: true - type: "integer" - minimum: 1 - format: "int64" + type: "string" responses: 400: description: "Invalid ID supplied" 404: description: "Order not found" x-swagger-router-controller: "Store" - /user: + /users: post: tags: - "user" @@ -399,33 +322,34 @@ paths: description: "This can only be done by the logged in user." operationId: "createUser" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - in: "body" name: "body" description: "Created user object" - required: true + required: false schema: $ref: "#/definitions/User" responses: default: description: "successful operation" x-swagger-router-controller: "User" - /user/createWithArray: + /users/createWithArray: post: tags: - "user" summary: "Creates list of users with given input array" + description: "" operationId: "createUsersWithArrayInput" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - in: "body" name: "body" description: "List of user object" - required: true + required: false schema: type: "array" items: @@ -434,20 +358,21 @@ paths: default: description: "successful operation" x-swagger-router-controller: "User" - /user/createWithList: + /users/createWithList: post: tags: - "user" summary: "Creates list of users with given input array" + description: "" operationId: "createUsersWithListInput" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - in: "body" name: "body" description: "List of user object" - required: true + required: false schema: type: "array" items: @@ -456,67 +381,60 @@ paths: default: description: "successful operation" x-swagger-router-controller: "User" - /user/login: + /users/login: get: tags: - "user" summary: "Logs user into the system" + description: "" operationId: "loginUser" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "username" in: "query" description: "The user name for login" - required: true + required: false type: "string" - name: "password" in: "query" description: "The password for login in clear text" - required: true + required: false type: "string" responses: 200: description: "successful operation" schema: type: "string" - headers: - X-Rate-Limit: - type: "integer" - format: "int32" - description: "calls per hour allowed by the user" - X-Expires-After: - type: "string" - format: "date-time" - description: "date in UTC when token expires" 400: description: "Invalid username/password supplied" x-swagger-router-controller: "User" - /user/logout: + /users/logout: get: tags: - "user" summary: "Logs out current logged in user session" - description: "null" + description: "" operationId: "logoutUser" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: [] responses: default: description: "successful operation" x-swagger-router-controller: "User" - /user/{username}: + /users/{username}: get: tags: - "user" summary: "Get user by user name" + description: "" operationId: "getUserByName" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "username" in: "path" @@ -540,18 +458,18 @@ paths: description: "This can only be done by the logged in user." operationId: "updateUser" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "username" in: "path" - description: "name that need to be updated" + description: "name that need to be deleted" required: true type: "string" - in: "body" name: "body" description: "Updated user object" - required: true + required: false schema: $ref: "#/definitions/User" responses: @@ -567,8 +485,8 @@ paths: description: "This can only be done by the logged in user." operationId: "deleteUser" produces: - - "application/xml" - "application/json" + - "application/xml" parameters: - name: "username" in: "path" @@ -588,39 +506,12 @@ securityDefinitions: in: "header" petstore_auth: type: "oauth2" - authorizationUrl: "http://petstore.swagger.io/oauth/dialog" + authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog" flow: "implicit" scopes: - write:pets: "modify pets in your account" - read:pets: "read your pets" + write_pets: "modify pets in your account" + read_pets: "read your pets" definitions: - Order: - type: "object" - properties: - id: - type: "integer" - format: "int64" - petId: - type: "integer" - format: "int64" - quantity: - type: "integer" - format: "int32" - shipDate: - type: "string" - format: "date-time" - status: - type: "string" - description: "Order Status" - enum: - - "placed" - - "approved" - - "delivered" - complete: - type: "boolean" - default: false - xml: - name: "Order" User: type: "object" properties: @@ -643,8 +534,6 @@ definitions: type: "integer" format: "int32" description: "User Status" - xml: - name: "User" Category: type: "object" properties: @@ -653,18 +542,6 @@ definitions: format: "int64" name: type: "string" - xml: - name: "Category" - Tag: - type: "object" - properties: - id: - type: "integer" - format: "int64" - name: - type: "string" - xml: - name: "Tag" Pet: type: "object" required: @@ -681,37 +558,40 @@ definitions: example: "doggie" photoUrls: type: "array" - xml: - name: "photoUrl" - wrapped: true items: type: "string" tags: type: "array" - xml: - name: "tag" - wrapped: true items: $ref: "#/definitions/Tag" status: type: "string" description: "pet status in the store" - enum: - - "available" - - "pending" - - "sold" - xml: - name: "Pet" - ApiResponse: + Tag: type: "object" properties: - code: + id: + type: "integer" + format: "int64" + name: + type: "string" + Order: + type: "object" + properties: + id: + type: "integer" + format: "int64" + petId: + type: "integer" + format: "int64" + quantity: type: "integer" format: "int32" - type: + shipDate: type: "string" - message: + format: "date-time" + status: type: "string" -externalDocs: - description: "Find out more about Swagger" - url: "http://swagger.io" + description: "Order Status" + complete: + type: "boolean" diff --git a/samples/server/petstore/nodejs/controllers/Pet.js b/samples/server/petstore/nodejs/controllers/Pet.js index 3748305bfbe..a7d196faa7c 100644 --- a/samples/server/petstore/nodejs/controllers/Pet.js +++ b/samples/server/petstore/nodejs/controllers/Pet.js @@ -33,7 +33,3 @@ module.exports.updatePet = function updatePet (req, res, next) { module.exports.updatePetWithForm = function updatePetWithForm (req, res, next) { Pet.updatePetWithForm(req.swagger.params, res, next); }; - -module.exports.uploadFile = function uploadFile (req, res, next) { - Pet.uploadFile(req.swagger.params, res, next); -}; diff --git a/samples/server/petstore/nodejs/controllers/PetService.js b/samples/server/petstore/nodejs/controllers/PetService.js index 212f5f41313..29a51e31a2b 100644 --- a/samples/server/petstore/nodejs/controllers/PetService.js +++ b/samples/server/petstore/nodejs/controllers/PetService.js @@ -6,20 +6,16 @@ exports.addPet = function(args, res, next) { * body (Pet) **/ // no response value expected for this operation - - res.end(); } exports.deletePet = function(args, res, next) { /** * parameters expected in the args: - * petId (Long) * apiKey (String) + * petId (Long) **/ // no response value expected for this operation - - res.end(); } @@ -28,9 +24,7 @@ exports.findPetsByStatus = function(args, res, next) { * parameters expected in the args: * status (List) **/ - - - var examples = {}; + var examples = {}; examples['application/json'] = [ { "tags" : [ { "id" : 123456789, @@ -45,7 +39,6 @@ exports.findPetsByStatus = function(args, res, next) { "name" : "doggie", "photoUrls" : [ "aeiou" ] } ]; - if(Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); @@ -54,7 +47,6 @@ exports.findPetsByStatus = function(args, res, next) { res.end(); } - } exports.findPetsByTags = function(args, res, next) { @@ -62,9 +54,7 @@ exports.findPetsByTags = function(args, res, next) { * parameters expected in the args: * tags (List) **/ - - - var examples = {}; + var examples = {}; examples['application/json'] = [ { "tags" : [ { "id" : 123456789, @@ -79,7 +69,6 @@ exports.findPetsByTags = function(args, res, next) { "name" : "doggie", "photoUrls" : [ "aeiou" ] } ]; - if(Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); @@ -88,7 +77,6 @@ exports.findPetsByTags = function(args, res, next) { res.end(); } - } exports.getPetById = function(args, res, next) { @@ -96,9 +84,7 @@ exports.getPetById = function(args, res, next) { * parameters expected in the args: * petId (Long) **/ - - - var examples = {}; + var examples = {}; examples['application/json'] = { "tags" : [ { "id" : 123456789, @@ -113,7 +99,6 @@ exports.getPetById = function(args, res, next) { "name" : "doggie", "photoUrls" : [ "aeiou" ] }; - if(Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); @@ -122,7 +107,6 @@ exports.getPetById = function(args, res, next) { res.end(); } - } exports.updatePet = function(args, res, next) { @@ -131,48 +115,17 @@ exports.updatePet = function(args, res, next) { * body (Pet) **/ // no response value expected for this operation - - res.end(); } exports.updatePetWithForm = function(args, res, next) { /** * parameters expected in the args: - * petId (Long) + * petId (String) * name (String) * status (String) **/ // no response value expected for this operation - - res.end(); } -exports.uploadFile = function(args, res, next) { - /** - * parameters expected in the args: - * petId (Long) - * additionalMetadata (String) - * file (file) - **/ - - - var examples = {}; - examples['application/json'] = { - "message" : "aeiou", - "code" : 123, - "type" : "aeiou" -}; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - diff --git a/samples/server/petstore/nodejs/controllers/Store.js b/samples/server/petstore/nodejs/controllers/Store.js index ac67c740d29..95fcb02711e 100644 --- a/samples/server/petstore/nodejs/controllers/Store.js +++ b/samples/server/petstore/nodejs/controllers/Store.js @@ -10,10 +10,6 @@ module.exports.deleteOrder = function deleteOrder (req, res, next) { Store.deleteOrder(req.swagger.params, res, next); }; -module.exports.getInventory = function getInventory (req, res, next) { - Store.getInventory(req.swagger.params, res, next); -}; - module.exports.getOrderById = function getOrderById (req, res, next) { Store.getOrderById(req.swagger.params, res, next); }; diff --git a/samples/server/petstore/nodejs/controllers/StoreService.js b/samples/server/petstore/nodejs/controllers/StoreService.js index de42d786581..6ee8ff36f94 100644 --- a/samples/server/petstore/nodejs/controllers/StoreService.js +++ b/samples/server/petstore/nodejs/controllers/StoreService.js @@ -3,44 +3,18 @@ exports.deleteOrder = function(args, res, next) { /** * parameters expected in the args: - * orderId (Long) + * orderId (String) **/ // no response value expected for this operation - - res.end(); } -exports.getInventory = function(args, res, next) { - /** - * parameters expected in the args: - **/ - - - var examples = {}; - examples['application/json'] = { - "key" : 123 -}; - - if(Object.keys(examples).length > 0) { - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); - } - else { - res.end(); - } - - -} - exports.getOrderById = function(args, res, next) { /** * parameters expected in the args: - * orderId (Long) + * orderId (String) **/ - - - var examples = {}; + var examples = {}; examples['application/json'] = { "id" : 123456789, "petId" : 123456789, @@ -49,7 +23,6 @@ exports.getOrderById = function(args, res, next) { "quantity" : 123, "shipDate" : "2000-01-23T04:56:07.000+0000" }; - if(Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); @@ -58,7 +31,6 @@ exports.getOrderById = function(args, res, next) { res.end(); } - } exports.placeOrder = function(args, res, next) { @@ -66,9 +38,7 @@ exports.placeOrder = function(args, res, next) { * parameters expected in the args: * body (Order) **/ - - - var examples = {}; + var examples = {}; examples['application/json'] = { "id" : 123456789, "petId" : 123456789, @@ -77,7 +47,6 @@ exports.placeOrder = function(args, res, next) { "quantity" : 123, "shipDate" : "2000-01-23T04:56:07.000+0000" }; - if(Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); @@ -86,6 +55,5 @@ exports.placeOrder = function(args, res, next) { res.end(); } - } diff --git a/samples/server/petstore/nodejs/controllers/UserService.js b/samples/server/petstore/nodejs/controllers/UserService.js index 13ddbee03fc..69fc1a81391 100644 --- a/samples/server/petstore/nodejs/controllers/UserService.js +++ b/samples/server/petstore/nodejs/controllers/UserService.js @@ -6,8 +6,6 @@ exports.createUser = function(args, res, next) { * body (User) **/ // no response value expected for this operation - - res.end(); } @@ -17,8 +15,6 @@ exports.createUsersWithArrayInput = function(args, res, next) { * body (List) **/ // no response value expected for this operation - - res.end(); } @@ -28,8 +24,6 @@ exports.createUsersWithListInput = function(args, res, next) { * body (List) **/ // no response value expected for this operation - - res.end(); } @@ -39,8 +33,6 @@ exports.deleteUser = function(args, res, next) { * username (String) **/ // no response value expected for this operation - - res.end(); } @@ -49,9 +41,7 @@ exports.getUserByName = function(args, res, next) { * parameters expected in the args: * username (String) **/ - - - var examples = {}; + var examples = {}; examples['application/json'] = { "id" : 123456789, "lastName" : "aeiou", @@ -62,7 +52,6 @@ exports.getUserByName = function(args, res, next) { "firstName" : "aeiou", "password" : "aeiou" }; - if(Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); @@ -71,7 +60,6 @@ exports.getUserByName = function(args, res, next) { res.end(); } - } exports.loginUser = function(args, res, next) { @@ -80,11 +68,8 @@ exports.loginUser = function(args, res, next) { * username (String) * password (String) **/ - - - var examples = {}; + var examples = {}; examples['application/json'] = "aeiou"; - if(Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2)); @@ -93,7 +78,6 @@ exports.loginUser = function(args, res, next) { res.end(); } - } exports.logoutUser = function(args, res, next) { @@ -101,8 +85,6 @@ exports.logoutUser = function(args, res, next) { * parameters expected in the args: **/ // no response value expected for this operation - - res.end(); } @@ -113,8 +95,6 @@ exports.updateUser = function(args, res, next) { * body (User) **/ // no response value expected for this operation - - res.end(); } diff --git a/samples/server/petstore/nodejs/package.json b/samples/server/petstore/nodejs/package.json index fbc49f2a725..2ebddec5e2e 100644 --- a/samples/server/petstore/nodejs/package.json +++ b/samples/server/petstore/nodejs/package.json @@ -1,7 +1,7 @@ { "name": "swagger-petstore", "version": "1.0.0", - "description": "This is a sample server Petstore server. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\nFor this sample, you can use the api key `special-key` to test the authorization filters.\n", + "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", "main": "index.js", "keywords": [ "swagger" From 0be18399b661d31c8382fcb2b75ccc854bae88e0 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 9 Apr 2016 18:15:22 +0800 Subject: [PATCH 3/3] fix tos in swagger spec --- modules/swagger-codegen/src/test/resources/2_0/petstore.yaml | 4 ++-- samples/server/petstore/nodejs/api/swagger.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml index cbfae8e4c45..cb34cd3b51d 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml @@ -8,7 +8,7 @@ info: For this sample, you can use the api key `special-key` to test the authorization filters version: "1.0.0" title: Swagger Petstore - termsOfService: http://helloreverb.com/terms/ + termsOfService: http://swagger.io/terms/ contact: name: apiteam@swagger.io license: @@ -573,4 +573,4 @@ definitions: type: string description: Order Status complete: - type: boolean \ No newline at end of file + type: boolean diff --git a/samples/server/petstore/nodejs/api/swagger.yaml b/samples/server/petstore/nodejs/api/swagger.yaml index d1395c001d4..7f6eada7d8c 100644 --- a/samples/server/petstore/nodejs/api/swagger.yaml +++ b/samples/server/petstore/nodejs/api/swagger.yaml @@ -6,7 +6,7 @@ info: \ you can use the api key `special-key` to test the authorization filters\n" version: "1.0.0" title: "Swagger Petstore" - termsOfService: "http://helloreverb.com/terms/" + termsOfService: "http://swagger.io/terms/" contact: name: "apiteam@swagger.io" license: