bardzusny / swaggerize-restify

Design-driven apis with swagger 2.0 and restify.
14 stars 5 forks source link

Restify Versioning #1

Open chintan1287 opened 9 years ago

chintan1287 commented 9 years ago

Is there a way to use restify versioning support?

bardzusny commented 9 years ago

As of now - nope. I understand that you're referring to multiple API versions available under same paths, then specifying by the client which one to access by setting proper request header (Accept-Version).

But as far as I can see, it wouldn't be a problem to implement this. Each registered route would be assigned version of API specified in swagger spec (its "info" object). To register multiple API versions would mean multiple swaggerize() calls, on the same restify server.

One thing I'm worried about, though, is compatibility of restify way to version APIs (Accept-Version header) with swagger-ui. It's not a problem to have api-docs for different versions available under different paths, but how to make swagger-ui specify proper API version by setting custom header on all its requests? I'm not sure there's any supported way to go about this.

I'll look into this some more, even with this caveat this feature would make sense, I think. I'll also go through swaggerize-express issues regarding API versioning (though I'm pretty sure the express way to go about this were path prefixes). Keeping the issue open, will go back to this.

chintan1287 commented 9 years ago

Thanks for replying. Do you think adding a property in options makes sence?

swaggerize(server, {
    objName: name,
    api: swaggerJson,
    handlers: swaggerHandler,
    docspath: '/api-docs'
});

// Restify

function mount(server, options) {
    Object.defineProperty(server, options.objName, {
        value: {
            api: options.api,
            routes: options.routes
        }
    });

    restifyroutes(server, options);
}

I can't call swaggerize() multiple times because of server.swagger