Skip to main content

API Versioning

Since OpenAPI specification already supports the version field in the info object, it's easy to do URI versioning utilising multiple OpenAPIBackend instances with different apiRoot values.

Simple example:

const apiV1 = new OpenAPIBackend({
definition: "./openapi-v1.json",
apiRoot: "/v1",
});

const apiV2 = new OpenAPIBackend({
definition: "./openapi-v2.json",
apiRoot: "/v2",
});

const v1Handlers = {
notFound,
getPet,
listPets,
createPet,
};
apiV1.register(v1Handlers);

const v2Handlers = {
...v1Handlers,
deletePet, // add new operation
createPet: createPetV2, // override old handler
};
apiV2.register(v2Handlers);

For a real world API versioning implementation with openapi-backend, see ether/etherpad