Swagger Documentation
I wonder if you can plug in swagger documentation as well?
@gabhi funny you should mention that as I was thinking the exact same thing!
Incidentally, why all caps? :smile:
sorry it was unintentional :-)
one problem that i noticed with swagger was too much coupling with routes, i wonder if u have some different approach
@gabhi no worries :)
Are you using swagger-node-express?
yes along with swagger-ui i think
Nice. I like those a lot.
I think you should be able to do something with swagger by adding .spec to the resource methods. Not sure though.
I'd love to see any examples you may be thinking of.
yes. with that in 'action' of spec i am mentioning the action like auth.login.
previously i would have routes/index.js where i would mention something like
app.get(<some path>, auth.login)
but with swagger this becomes redundant. which i dont like.
I hear you on redundancy. There's a PR right now for swagger that would turn action into a pipeline. I like that cause now you can have middleware on an action basis. It still doesn't feel quite right though.
interesting...this is going to make documentation more coupled with actions/routes.
It may be possible to do something like this in express-crud:
//User.js
var User = module.exports = {
read: function(query, cb){}
};
//controller.js
var swagger = require('../my/swagger');
var User = require('.../resources/User');
app.crud('users/:userId', User).swag();
swagger.addResource(User);
With that the .swag() method could generate .spec properties on all the resource's CRUD methods.
Swagger would need to be updated first though to see if the routes had already been registered.
+1. i like this approach.
@gabhi if you have a chance, checkout https://github.com/kogosoftwarellc/express-openapi. It's super easy to develop express apis with it.