node-express-crud icon indicating copy to clipboard operation
node-express-crud copied to clipboard

Swagger Documentation

Open gabhi opened this issue 11 years ago • 13 comments

I wonder if you can plug in swagger documentation as well?

gabhi avatar Jun 17 '14 06:06 gabhi

@gabhi funny you should mention that as I was thinking the exact same thing!

Incidentally, why all caps? :smile:

jsdevel avatar Jun 17 '14 07:06 jsdevel

sorry it was unintentional :-)

gabhi avatar Jun 17 '14 07:06 gabhi

one problem that i noticed with swagger was too much coupling with routes, i wonder if u have some different approach

gabhi avatar Jun 17 '14 07:06 gabhi

@gabhi no worries :)

jsdevel avatar Jun 17 '14 07:06 jsdevel

Are you using swagger-node-express?

jsdevel avatar Jun 17 '14 07:06 jsdevel

yes along with swagger-ui i think

gabhi avatar Jun 17 '14 07:06 gabhi

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.

jsdevel avatar Jun 17 '14 07:06 jsdevel

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.

gabhi avatar Jun 17 '14 07:06 gabhi

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.

jsdevel avatar Jun 17 '14 07:06 jsdevel

interesting...this is going to make documentation more coupled with actions/routes.

gabhi avatar Jun 17 '14 07:06 gabhi

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.

jsdevel avatar Jun 17 '14 07:06 jsdevel

+1. i like this approach.

gabhi avatar Jun 17 '14 07:06 gabhi

@gabhi if you have a chance, checkout https://github.com/kogosoftwarellc/express-openapi. It's super easy to develop express apis with it.

jsdevel avatar Jan 07 '16 09:01 jsdevel