Is it possible to link a Swagger operationId to a SailsJS blueprint action ?
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:
- Change the chain of middleware from 'after' to 'before' Inside swagger-sails/lib/index.js
- Commented out the swagger-tools router middleware in the middlewares array inside file swagger-node-runner/lib/connect_middleware.js
- 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!
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?
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.
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!
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.
@ftortega Did you found a solution to this problem?