Upgrading from v4 to v5

If you're upgrading from v4 of api, welcome ๐Ÿ‘‹ a lot's changed! With the introduction of v5, api now offers a complete code generation offering, complete with:

  • Full TypeScript types (generated off your OpenAPI definition) ๐Ÿ“–
  • Ability to export to TypeScript, CJS, and ESM compiled files ๐Ÿ“ฆ
  • Ability to run your SDK within a browser ๐ŸŒ

It's neat, and you should check it out. ๐Ÿฅบ

If you'd like to continue using the dynamic syntax you will need to update how you're handling promises that are returned from API requests, but it shouldn't be too bad.

Here's what your api implementation may have looked like before under v4:

const petstore = require('api')('https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore.json');

petstore.listPets().then(res => {
  console.log(`My pets name is ${res[0].name}!`);
});

And here's what it should look like now:

const petstore = require('api')('https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore.json');

petstore.listPets().then(({ data }) => {
  console.log(`My pets name is ${data[0].name}!`);
});

If you were using the .config({ parseResponse: false }) option, that option has been removed in favor of this new resolved data shape where we return data, status, headers, and res to you. You can see documentation on those here.

Additionally if you have any instances where you're using HTTP method accessors like petstore.get('/pets'), api@5 longer supports these and you will need to instead to use the operation ID for the operation you're accessing instead (i.e. petstore.getPets()). Consult Making Requests for more details.

And if you have any trouble or need help we're more than happy to give you an assist. https://github.com/readmeio/api/issues