Closed tanzim closed 7 years ago
Update
I think I've got a workable approach that's probably as good as it gets.
Given that it's easy to inject a swagger property in the spec by prefixing the key name with x-
, I used a similar technique used in Volos to introduce operation/path level configuration and then reading it off request.swagger.operation
property of the context object passed into the fitting function. This issue can be closed unless there's a nicer way of doing things @theganyo?
@tanzim I agree, you've found a good solution. Possibly it could be slightly more elegant if we supported conditionals in the pipeline... but that's a slippery slope I'm not ready to take right now. :)
Yup and also middleware chaining like Volos, but again that's something I can solve using async or bagpipes in my fitting currently without sweating too much :)
Hmm. I'm not sure exactly what you'd be looking for with "middleware chaining like Volos" that you don't have already. Could you elaborate?
As far as I can tell, to workaround the fact that in swagger config one can only specify swagger_controllers (middleware) in sequence, the trick Volos used was to have one single operation key (x-volos-apply) and nest multiple fittings (cache, quota etc.) under that key and the fitting handling x-volos-apply would be responsible for running the nested fittings.
This in contrast to writing multiple fittings each mapping to entries in swagger_controllers and the swagger file (x-cache-apply, x-quota-apply).
I suppose it's a matter of taste and the use case involved. The advantage of the Volos approach is you could potentially run the sub-fittings (if I can call them that) in parallel if it matters. It also keeps the swagger file a bit cleaner. if that makes sense? :)
Makes sense. Thanks for the explanation.
Hi, Just wondering if there's a way to specify a fitting (or middleware) to be executed for a specific path or even an operation for a specific path without writing an extension as seen in Volos[1]? Much like as you'd specify a middleware for a connect/express route.
For the time being the only option I can think of is a generic fitting that execute as part of
swagger_controllers
, but the downside of that is I need to check for the path I'm interested and invoke the middleware on a match. Not very elegant sadly.[1] https://github.com/apigee-127/volos/tree/master/swagger