swagger-node
swagger-node copied to clipboard
Is there anyway to integrate swagger with restify?
Hi! I have a simple server built with restify, but I'd like to integrate swagger with it to keep it better documented and maintainable. I've seen that there are a few projects that claim doing this. Is it doable? If it is, how can I do that? I've read your specs some time ago and I know that things must be really different. I'd really appreciate if someone can point me the right direction. Thanks!
You've probably figured this out by now @damibarbieri , but this is completely possible. I am doing it currently with an API I am working on. If you use the CLI project starter, it gives you an option to generate an app using the swagger restify middleware.
$ npm install -g swagger
$ swagger project create demo
# Select restify when prompted
You can also accomplish this yourself by adding the middleware
npm install -S swagger-restify-mw
Then, you can set it up like this (this is exactly the app.js
currently generated by project creator):
'use strict';
var SwaggerRestify = require('swagger-restify-mw');
var restify = require('restify');
var app = restify.createServer();
module.exports = app; // for testing
var config = {
appRoot: __dirname // required config
};
SwaggerRestify.create(config, function(err, swaggerRestify) {
if (err) { throw err; }
swaggerRestify.register(app);
var port = process.env.PORT || 10010;
app.listen(port);
if (swaggerRestify.runner.swagger.paths['/hello']) {
console.log('try this:\ncurl http://127.0.0.1:' + port + '/hello?name=Scott');
}
});
Thanks Kevin, I tried with prebuild Restify api's and Joi validation. But I am not able to get it working when the field is required and of different type(String, number and Boolean). Is it possible to have a sample example which can help us? Thanks in advance...
Hi, @kburdett I tried but not be able to show swagger documentation and the browser shows only a string. Please help me how to integrate swagger with node application.
same thing here