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

@kartore/openapi-client-ts-generator

v0.1.0

Published

A starter for creating a TypeScript package.

Downloads

580

Readme

openapi-client-ts-generator

Generate TypeScript types and API client (and TanStack Query helpers) from OpenAPI 3.0/3.1 specifications.

CLI

Basic

npx openapi-gen <input> -o <output-dir>

<input> can be a local file path or a URL.

# local file
npx openapi-gen ./openapi.yaml -o ./src/api

# URL
npx openapi-gen https://example.com/openapi.json -o ./src/api

This generates the following files in the output directory:

  • types.ts — TypeScript types from components.schemas
  • client.ts — Typed apiClient factory function from paths
  • index.ts — Barrel re-export

TanStack Query helpers

# React Query
npx openapi-gen ./openapi.yaml -o ./src/api --tanstack-query react

# Svelte Query
npx openapi-gen ./openapi.yaml -o ./src/api --tanstack-query svelte

Adds a query.ts file with queryClient helpers wrapping the API client.

All options

| Option | Default | Description | | --------------------------- | ------- | ---------------------------------------------------------------------- | | -o, --output <dir> | . | Output directory | | --tanstack-query <name> | — | TanStack Query framework: react or svelte | | --no-throw-on-http-error | — | Do not throw HTTPError on non-2xx responses | | --allow-x-typescript-type | — | Enable x-typescript-type extension (trusted sources only, see below) | | -h, --help | — | Show help |

Node.js API

Load from a file or URL

import { generateFrom } from '@kartore/openapi-client-ts-generator/node';

const { types, client, query, index } = await generateFrom('./openapi.yaml');
// or
const { types, client, query, index } = await generateFrom(
  'https://example.com/openapi.json'
);

External $refs are resolved automatically.

From an object

import { generateFrom } from '@kartore/openapi-client-ts-generator/node';

const { types, client } = await generateFrom({
  openapi: '3.1.0',
  info: { title: 'My API', version: '1.0.0' },
  paths: { ... },
});

Generate and write files to disk

import { generateAndWrite } from '@kartore/openapi-client-ts-generator/node';

await generateAndWrite('./openapi.yaml', {
  outDir: './src/api',
  tanstackQuery: 'react',
});

With TanStack Query

import { generateFrom } from '@kartore/openapi-client-ts-generator/node';

const { types, client, query } = await generateFrom('./openapi.yaml', {
  tanstackQuery: 'react', // or 'svelte'
});

Options

| Option | Type | Default | Description | | ---------------------- | --------- | ----------- | ---------------------------------------------------------------------- | | tanstackQuery | string | — | TanStack Query framework: 'react' or 'svelte' | | typesImportPath | string | './types' | Import path used in client.ts to reference types.ts | | throwOnHttpError | boolean | true | Throw HTTPError when response.ok is false | | allowXTypescriptType | boolean | false | Enable x-typescript-type extension (trusted sources only, see below) |

x-typescript-type extension (opt-in)

When the OpenAPI spec comes from a trusted source, you can use the x-typescript-type custom extension to override the generated type with an arbitrary TypeScript type expression:

components:
  schemas:
    MaplibreStyleSpecification:
      type: object
      x-typescript-type: "import('maplibre-gl').StyleSpecification & { metadata: MaplibreMetadata }"
      properties:
        version:
          type: integer
export type MaplibreStyleSpecification =
  import('maplibre-gl').StyleSpecification & { metadata: MaplibreMetadata };

This also works on inline property schemas.

Security note: The value of x-typescript-type is injected verbatim into the generated TypeScript file. Only enable this option when the spec comes from a source you control.

Enable via CLI:

npx openapi-gen ./openapi.yaml -o ./src/api --allow-x-typescript-type

Enable via API:

await generateFrom('./openapi.yaml', { allowXTypescriptType: true });

Generated output

types.ts

/* eslint-disable */
export type User = {
  id: string;
  name: string;
};

client.ts

import type { User } from './types.js';

export function apiClient(baseUrl: string, clientOptions?: { ... }) {
  return {
    users: {
      id: (id: string) => ({
        key: ['users', id] as const,
        path: `/users/${id}`,
        get: (params?) => Promise<User>,
      }),
    },
  };
}

query.ts (with --tanstack-query react)

export function queryClient(client: ReturnType<typeof apiClient>) {
  return {
    users: {
      id: (id: string) => ({
        get: (params?, options?) => UseQueryOptions<User>,
      }),
    },
  };
}