swagger-node icon indicating copy to clipboard operation
swagger-node copied to clipboard

Is it possible to link a Swagger operationId to a SailsJS blueprint action ?

Open ftortega opened this issue 11 years ago • 5 comments

Let's say I have a model called Surfboard and its corresponding controller SurfboardController. And I have some blueprint actions created automatically by sailsjs (find, create, update, etc..). I also have all automatic blueprint routes disabled. Is it possible to tell swagger to link a path in the swagger definition to any of these blueprint actions and use the swagger-tools router middleware. like for example:

/surfboard:
  x-swagger-router-controller: SurfboardController
  get:
    description: find all the surfboards
    operationId: find

One way I was able to sort-of get what I wanted was:

  1. Change the chain of middleware from 'after' to 'before' Inside swagger-sails/lib/index.js
  2. Commented out the swagger-tools router middleware in the middlewares array inside file swagger-node-runner/lib/connect_middleware.js
  3. defined an explicit route in my config/routes.js as follows:
  module.exports.routes = {
    "GET  /surfboard": {controller: "SurfboardController", action: "find"}
  };

The downside is that I have to define routes in two different files (swagger.yaml and config/routes.js).

I just would like to know if there is a better/proper way of doing this? Thanks in advance!

ftortega avatar Jul 01 '15 19:07 ftortega

I don't have a better way to handle this at the moment, as you can tell the current integration with Sails is somewhat superficial due to my lack of experience with the platform. That said, we want to improve and I'm very hopeful that with experienced Sails folks in the community, we will find ways that to have deeper/better integration with Sails.

When you say you "have some blueprint actions created automatically by sailsjs" - do you mean they are created at runtime?

theganyo avatar Jul 06 '15 15:07 theganyo

Yes, Sail.js has this nice feature that automatically creates blueprint actions when you startup your app. To set it up you only need to create a Model file with its corresponding Controller file (e.g. api/models/Surfboard.js and api/controllers/SurfboardController.js) It also binds the corresponding REST routes to these actions (e.g. POST /surboard -> surboardController.create()) and even some shortcut routes (e.g. GET /surfboard/create -> surfboadController.create()). And all these automatic actions, routes and shortcut-routes can be overridden or disabled. It is a very nice feature.

ftortega avatar Jul 06 '15 19:07 ftortega

Thank you very much for your response! I closed this issue as it wasn't really an issue. It was just a question but I didn't know where else to ask it. I'm not quite sure what would be the best way of integrating swagger with sails as I am also very new to Sails and Swagger. However, if I get some good ideas while working a bit more with these two projects, I will keep in touch.

Having said that, as a user I think I would be nice if the routes generated by swagger would be visible somewhere in the sails config folder. That way it would probably be easier to integrate it with other sails features, like policies, etc... Thanks!

ftortega avatar Jul 06 '15 19:07 ftortega

I think I would be nice if the routes generated by swagger would be visible somewhere in the sails config folder

Hmm. That would actually be a very different model than what swagger-node has taken. As you might have noticed, swagger-node doesn't generate any code or configuration from the swagger... everything is dynamic. Since generating a config table would go against that philosophy, it would have to be overwhelmingly compelling over more dynamic solutions.

theganyo avatar Jul 06 '15 19:07 theganyo

@ftortega Did you found a solution to this problem?

iolufemi avatar Jan 11 '16 10:01 iolufemi