Skip to content

Instantly share code, notes, and snippets.

@silas
Created February 22, 2014 19:43
Show Gist options
  • Select an option

  • Save silas/9161013 to your computer and use it in GitHub Desktop.

Select an option

Save silas/9161013 to your computer and use it in GitHub Desktop.
var swagger = require('swagger-framework');
var api = swagger.Api({
path: '/pet',
description: 'Manage pets',
consumes: [
'application/json',
],
produces: [
'application/json',
],
});
var resource = api.resource({ path: '/pet/{petId}' });
resource.operation(
{
method: 'GET',
summary: 'Find pet by ID',
notes: 'Returns a pet based on ID',
type: 'Pet',
nickname: 'getPetById',
parameters: [
{
name: 'petId',
description: 'ID of pet that needs to be fetched',
required: true,
type: 'integer',
format: 'int64',
paramType: 'path',
minimum: '1',
maximum: '100000',
},
],
responseMessages: [
{
code: 400,
message: 'Invalid ID supplied',
},
{
code: 404,
message: 'Pet not found',
},
],
},
function(req, res) {
res.swagger.reply(200, {
message: 'pet id ' + req.swagger.path.petId,
});
}
);
//
// main
//
var express = require('express');
var host = '127.0.0.1';
var port = 8000;
var url = 'http://' + host + ':' + port;
var app = express();
var framework = swagger.Framework({ basePath: url });
framework.api(api);
app.use('/api-docs', framework.docs.dispatcher());
app.use(framework.dispatcher());
app.listen(port, host, function(err) {
if (err) throw err;
console.log('Server started ' + url + '/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment