update nodejs petstore samples

This commit is contained in:
wing328 2017-03-30 22:39:53 +08:00
parent 0baa6cf0e8
commit a15af0828c
3 changed files with 12 additions and 8 deletions

View File

@ -108,11 +108,11 @@ paths:
type: "array" type: "array"
items: items:
type: "string" type: "string"
default: "available"
enum: enum:
- "available" - "available"
- "pending" - "pending"
- "sold" - "sold"
default: "available"
collectionFormat: "csv" collectionFormat: "csv"
responses: responses:
200: 200:

View File

@ -108,11 +108,11 @@ paths:
type: "array" type: "array"
items: items:
type: "string" type: "string"
default: "available"
enum: enum:
- "available" - "available"
- "pending" - "pending"
- "sold" - "sold"
default: "available"
collectionFormat: "csv" collectionFormat: "csv"
responses: responses:
200: 200:

View File

@ -1,25 +1,28 @@
'use strict'; 'use strict';
var fs = require('fs'),
path = require('path'),
http = require('http');
var app = require('connect')(); var app = require('connect')();
var http = require('http');
var swaggerTools = require('swagger-tools'); var swaggerTools = require('swagger-tools');
var jsyaml = require('js-yaml'); var jsyaml = require('js-yaml');
var fs = require('fs');
var serverPort = 8080; var serverPort = 8080;
// swaggerRouter configuration // swaggerRouter configuration
var options = { var options = {
swaggerUi: '/swagger.json', swaggerUi: path.join(__dirname, '/swagger.json'),
controllers: './controllers', controllers: path.join(__dirname, './controllers'),
useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode) useStubs: process.env.NODE_ENV === 'development' // Conditionally turn on stubs (mock mode)
}; };
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...) // The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
var spec = fs.readFileSync('./api/swagger.yaml', 'utf8'); var spec = fs.readFileSync(path.join(__dirname,'api/swagger.yaml'), 'utf8');
var swaggerDoc = jsyaml.safeLoad(spec); var swaggerDoc = jsyaml.safeLoad(spec);
// Initialize the Swagger middleware // Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) { swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain // Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
app.use(middleware.swaggerMetadata()); app.use(middleware.swaggerMetadata());
@ -37,4 +40,5 @@ swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort); 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); console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
}); });
}); });