Closed dschenkelman closed 10 years ago
@mac- any thoughts on this one?
Can you give me an example of what one of these swagger hooks look like? Why would we want to modify the swagger output? Is there a use case that ratify isn't configured to handle that it maybe should?
We have an authorization format, based on JWTs and need to be able to tell ratify
how to generate the swagger for it. When using swagger-ui we customize the rendering to display the scopes that give you access to a particular endpoint, but we need to have those available in swagger first:
swaggerHooks: {
operation: function(operation, route, resourceType, path){
if (route.settings && route.settings.auth && route.settings.auth.scope){
var scopes = route.settings.auth.scope;
operation.authorizations = {
jwt: {
scopes: scopes
}
};
}
}
}
It still has to be valid swagger (otherwise when processing with swagger-ui you get errors), but allows you to customize some things that might be app specific.
ahh ok, so you are running a customized version of the swagger ui?
Yes, which I think is fairly common since their templates can be modified. Still, even if we weren't having those hooks available provide an additional extension point that allows users to adjust ratify to their scenarios without the need to perform changes to the lib. If enough people then want a particular mapping based on standards or something it can be implemented in ratify itself...
I'll publish a new version tonight
Great! No rush on my part, I'm pulling the package from my fork right now
Useful hooks to customize how some swagger elements are generated. They are optional and do not prevent default behavior if provided.