Registry / http-networking / api
library6.1.3jsnpmunverified

The `@readme/api` package provides a robust command-line interface and programmatic API for generating SDKs from OpenAPI (formerly Swagger) definitions. It takes an OpenAPI specification file and outputs a fully-typed JavaScript SDK, designed to be consistent across CommonJS, ES Modules, and TypeScript environments. The current stable version is `6.1.3`, with active development towards `v7.0.0`, which introduces significant overhauls to the SDK generation strategy, notably streamlining the process by removing complex configuration questions and enhancing type and module resolution. This package differentiates itself by offering a complete SDK generation pipeline that handles schema imports and type safety, aiming to provide a 'just works' experience for developers integrating with OpenAPI-driven APIs. Its release cadence is active, with minor and patch updates regularly addressing fixes and quality-of-life improvements, while major versions introduce breaking changes and significant architectural shifts.

npm install api
INSTALL
IMPORT
SIG · API
A
api
http-networkingjavascriptv6.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generate
import { generate } from '@readme/api';
const { generate } = require('@readme/api');
Since v7, the package offers consistent module resolution for both ESM and CJS. For v6, CommonJS `require` was standard.
APIOptions
import type { APIOptions } from '@readme/api';
Type import for configuration options when programmatically generating an SDK. The actual export name is 'options'.
*
import * as api from '@readme/api';
const api = require('@readme/api');
Imports all named exports into a namespace object. Useful for accessing multiple utilities or when specific named imports are not desired.

Demonstrates how to programmatically generate a TypeScript-ready SDK from a dummy OpenAPI specification using the `generate` function, then cleans up the temporary files. This is runnable in a modern Node.js environment supporting ESM.

import { generate } from '@readme/api'; import path from 'node:path'; import fs from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); async function createDummyOpenApiSpec(specPath: string) { const dummyOpenApiSpec = { openapi: '3.0.0', info: { title: 'My API', version: '1.0.0' }, paths: { '/users': { get: { summary: 'Get all users', responses: { '200': { description: 'A list of users', content: { 'application/json': { schema: { type: 'array', items: { $ref: '#/components/schemas/User' } } } } } } } } }, components: { schemas: { User: { type: 'object', properties: { id: { type: 'string', format: 'uuid' }, name: { type: 'string' } } } } } }; await fs.writeFile(specPath, JSON.stringify(dummyOpenApiSpec, null, 2)); } async function runSdkGeneration() { const outputBaseDir = path.resolve(__dirname, 'temp-sdk-output'); await fs.mkdir(outputBaseDir, { recursive: true }); const openApiPath = path.join(outputBaseDir, 'openapi.json'); await createDummyOpenApiSpec(openApiPath); const sdkOutputDir = path.join(outputBaseDir, 'generated-sdk'); await fs.mkdir(sdkOutputDir, { recursive: true }); console.log(`Starting SDK generation...`); console.log(` OpenAPI Spec: ${openApiPath}`); console.log(` Output Dir: ${sdkOutputDir}`); // The '@readme/api' package provides a `generate` function to create SDKs // from an OpenAPI definition. It expects the path to the OpenAPI // file and the desired output directory for the generated SDK. // In v7, the generation strategy is overhauled for consistent module // resolution and types across CJS, ESM, and TypeScript. await generate(openApiPath, sdkOutputDir); console.log('SDK generation complete!'); console.log(`You can now find the generated SDK in: ${sdkOutputDir}`); console.log(`Example: const { default: sdk } = await import('${sdkOutputDir}');`); // Clean up temporary files await fs.rm(outputBaseDir, { recursive: true, force: true }); console.log(`Cleaned up temporary directory: ${outputBaseDir}`); } runSdkGeneration().catch(console.error);
api --version
Debug
Known issues
breakingThe minimum required Node.js version for `v7.x` has been bumped to `v20.10.0`.
fix
Upgrade your Node.js environment to version `20.10.0` or newer, or stick to a `v6.x` release for older Node.js versions.
affects: >=7.0.0-beta.13
breakingVersion `6.0.0` dropped support for Node.js 14.
fix
Ensure your Node.js environment is version 16 or higher when using `v6.x` of the package.
affects: >=6.0.0
breakingThe SDK generation strategy has been overhauled in `v7.x`. This release streamlines the process by removing previous configuration questions and aiming for a 'just works' experience with consistent types and module resolution.
fix
Review the `v7.x` changelog and update your programmatic SDK generation calls, as previous configuration options may no longer be supported or necessary.
affects: >=7.0.0-beta.4
gotchaA security vulnerability related to the `oas` dependency was resolved in `v6.1.3`.
fix
Upgrade to `@readme/api@6.1.3` or newer to ensure you have the latest security patches.
affects: <6.1.3
Errors
Common errors & fixes
Error: The '@readme/api' package requires Node.js version X or higher.
Attempting to use the package with an incompatible or outdated Node.js version.
fix
Upgrade your Node.js environment to the minimum required version (Node.js 16+ for v6.x, Node.js 20.10.0+ for v7.x).
SyntaxError: Cannot use import statement outside a module
Trying to use ESM `import` syntax in a CommonJS context (e.g., in a `.js` file without `"type": "module"` in `package.json` or older Node.js versions) with `v6.x`.
fix
For `v6.x`, use `const { symbol } = require('@readme/api');` for CommonJS environments. For modern setups or `v7.x` aiming for ESM consistency, ensure your `package.json` specifies `"type": "module"` or use a `.mjs` file extension.
Upgrade
Version history
6.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
34
OpenAI (training)
1
Resources
api — npm install api · libregistry