Skip to content

Instantly share code, notes, and snippets.

@nevill
Last active August 29, 2015 13:56
Show Gist options
  • Save nevill/9317631 to your computer and use it in GitHub Desktop.
Save nevill/9317631 to your computer and use it in GitHub Desktop.
An example of usage on swagger-jack, to validate against uploaded files
// To test with it, run with `curl`
// curl -F "photo=@/path/to/your/photo" localhost:3000/api/uploads
var express = require('express');
var swagger = require('swagger-jack');
var app = express();
app.use(express.logger('dev'))
.use(express.bodyParser())
.use(express.methodOverride())
.use(swagger.generator(app, {
"apiVersion": "2.0",
"swaggerVersion": "1.3",
basePath: 'http://localhost:3000/api',
}, [{
api: {
"resourcePath": "/uploads",
"apis": [{
"path": "/uploads",
"operations": [{
"httpMethod": "POST",
"nickname": "returnBody",
"summary": "Upload a file",
"responseClass": "void",
"parameters": [
{
"name": "photo",
"description": "A photo to upload",
"dataType": "file",
"required": true,
"allowMultiple": false,
"paramType": "body"
}
]
}, {
"httpMethod": "GET",
"nickname": "passed",
"summary": "simple test",
"responseClass": "void"
}]
}, ]
},
controller: {
passed: function(req, res) {
res.json({
status: 'passed'
});
},
returnParams: function(req, res) {
res.json(req.input);
},
returnBody: function(req, res) {
res.json({
body: req.body
});
},
}
}]))
.use(swagger.validator(app))
.use(swagger.errorHandler());
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log('Listening on port', port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment