npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

genoc

v0.4.1

Published

Generate typed HTTP clients from OpenAPI 3.0 / 3.1 specifications

Downloads

389

Readme

genoc

Generate TypeScript HTTP clients from OpenAPI 3.0 or 3.1 specifications. Generated code depends only on the tiny genoc/runtime module. Full type safety. Bring your own HTTP client.

npm version Node.js TypeScript License: MIT

Features

  • Full OpenAPI 3.0 and 3.1 specification support with automatic version detection
  • End-to-end type safety: requests, responses, and errors are fully typed
  • Works with any HTTP client: plug in fetch, axios, or anything else
  • Shared runtime contract: genoc/runtime exports the Requester type and response and error classes, so one requester implementation works with every generated client
  • Error types with per-status-code narrowing and type guards
  • File and binary uploads and downloads with stream handling
  • Flexible method naming strategies (path-based, operationId, operationId-with-fallback)

Quick Start

Install:

npm install genoc

Generated code imports from genoc/runtime, so genoc is a runtime dependency (not just devDependencies).

Generate:

genoc ./path/to/spec.yaml --output-dir ./src/api

This creates three files in ./src/api:

  • contracts.ts: type definitions, error classes, and helper types
  • client.ts: typed client with the createClient(requester) factory
  • index.ts: barrel that re-exports both files, so you can import directly from the output directory

The barrel means import { createClient } from './index.js' works too.

Usage

The generated client requires a Requester implementation: a function that performs the HTTP call and returns the result. The type lives in genoc/runtime, so you can write and compile a requester before generating anything:

import type { Requester } from 'genoc/runtime';

For the full Requester type signature and binary and stream handling, see Usage.

import { createClient } from './client.js';
import type { Requester } from 'genoc/runtime';
import { RequesterFailError, ErrorResponse } from 'genoc/runtime';

const baseUrl = 'https://api.example.com';

const requester: Requester = async (method, path, options) => {
  const url = new URL(path, baseUrl);
  if (options.query) {
    Object.entries(options.query).forEach(([key, value]) => {
      url.searchParams.set(key, String(value));
    });
  }

  const response = await fetch(url, {
    method,
    headers: {
      'Content-Type': 'application/json',
      ...options.headers,
    },
    body: options.body ? JSON.stringify(options.body) : undefined,
  });

  if (!response.ok) {
    return new ErrorResponse(
      response.status,
      await response.json(),
      Object.fromEntries(response.headers.entries()),
      response.statusText
    );
  }

  return response.json();
};

const client = createClient(requester);

// Typed call: response type is inferred from the spec
const pets = await client.getPets({ limit: 10 });

For handling expectStream: true, see Binary and file responses.

Error handling

The generated client throws typed errors. Each method carries its own error union, and isDefinedError narrows a caught error to that union:

  • ApiError<TStatus, TData>: error for a specific status code defined in the spec
  • UnspecifiedApiError: error for a status code not defined in the spec
  • RequesterFailError: wraps unexpected failures in your Requester
  • isDefinedError(err, client.method): type guard that narrows to the method's defined error union

For the full example of catching and narrowing errors, see Error handling.

Documentation

  • Configuration: CLI flags, .genocrc config files, method naming strategies, and proxy support
  • Usage: the Requester contract, shared runtime, binary and file responses, and JSDoc output
  • Error handling: typed errors, isDefinedError, and the catching example
  • OpenAPI 3.0 support: data types, schema keywords, parameters, bodies, uploads, responses, errors, $ref, components, security, servers, and operations
  • OpenAPI 3.1 support: all 3.0 features plus webhooks and JSON Schema 2020-12 alignment, with a diff against 3.0

Requirements

  • Node.js 20.18.1 or later
  • OpenAPI 3.0.x or 3.1.x specification (JSON or YAML, file path or URL)

License

MIT. Copyright © Andrey Kiselev