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

@fohoov/zod-openapi-client

v1.1.2

Published

command line tools for creating ts with zod clients from openapi sepc files

Readme

TypeScript Client Generator CLI

A powerful command-line tool for generating TypeScript API clients and Zod schemas directly from your OpenAPI specifications. This CLI leverages the OpenApiTools engine to create robust clients in both object-oriented (OOP) and functional styles, and it also produces Zod schemas for runtime type validation using openapi-zod-client (credit to astahmer).

Features

  • Generate TypeScript Clients:
    Automatically create clients that match your OpenAPI specs in two modes:

    • OOP Mode (default): Generates object-oriented clients.
    • Functional Mode: Generates functional clients using customized templates from /public/templates.
  • Zod Schema Generation:
    In addition to client generation, this CLI also creates Zod schemas from your API types for runtime type validation. This feature uses the openapi-zod-client (credit to astahmer).

  • HTTP Client Options:
    Choose between:

    • fetch (default)
    • axios (with configurable axios version)
  • Endpoint Customization:
    Remove prefixes from endpoints and apply regex-based replacements to clean up your API paths.

  • Operation ID Customization:
    Modify and format operation IDs based on your requirements using customizable formatters.

  • Flexible Configuration:
    Set output directories, skip spec validations, and more with simple CLI options.

Prerequisites

  • Java:
    OpenApiTools requires Java. Ensure you have it installed. Download Java

  • Node.js & PNPM:
    Make sure Node.js is installed. We recommend using pnpm as your package manager.

  • Install the @openapitools/openapi-generator-cli npm package

Installation

Install the CLI via pnpm:

pnpm i @fohoov/zod-openapi-client

Or run it without installing using:

pnpm dlx @fohoov/zod-openapi-client --help

Usage

To generate a client and corresponding Zod schemas, you must provide the URL of your OpenAPI JSON spec along with optional configuration options.

Basic Command

pnpm exec client-generator --uri <your-openapi-spec-url>

By default, this command will generate an OOP client using the fetch library, create corresponding Zod schemas, and output the generated files to src/generated-clients.

CLI Options

Here’s a breakdown of the available options:

  • --uri <uri>
    The URL to the OpenAPI JSON specification.
    Required. You can also set this via the OPENAPI_URL environment variable.

  • --mode <string>
    Choose the client generation mode:

    • oop (default) – Generates an object-oriented client.
    • functional – Generates a functional client using templates from /public/templates.

      if mode is set to functional the /[generated-path]/base.ts file exports a functional called updateGlobalConfiguration to set your configurations globally

  • --client <string>
    Select the HTTP client library:

    • fetch (default)
    • axios
  • --axios-version <string>
    Specify the axios version to use (applicable only if --client is set to axios).
    Default: "1.7.0"

  • --out <string>
    The output directory for the generated client and schema files.
    Default: "src/generated-clients"

  • --remove-endpoint-prefix <string>
    Remove a specified prefix from endpoints (e.g., convert /x/path to /path).

  • --replace-endpoint-regex <pair...>
    Apply a regex replacement on endpoints before prefix removal.
    Example: --replace-endpoint-regex /api/,/account-report-service/

  • --skip-spec-validations <boolean>
    Skip OpenAPI specification validations. Refer to OpenAPI Generator Configuration for details on skip-validate-spec.

  • --customize-operation-id <boolean>
    Customize operation IDs using specific formatters. For instance, for a POST endpoint like /api/Account/inquiry-account-balance/{account}, you can use a formatter (e.g., m_ls_m:camelcase) to generate a new operation ID (like postInquiryAccountBalancePost).
    Note: Existing operation IDs are ignored unless you also use --overwrite-existing-operation-ids.
    Current available formatters: ${JSON.stringify(CUSTOM_OPERATION_COMMANDS)}

  • --overwrite-existing-operation-ids
    Use in combination with --customize-operation-id to overwrite any existing operation IDs.

Additional Note:
These options might be outdated, to see current available options and their defaults use --help

Examples

1. Generate an OOP Client with Fetch and Zod Schemas

pnpm exec client-generator --uri "https://api.example.com/openapi.json" --mode oop --client fetch --out "./generated-client"

2. Generate a Functional Client with Axios, Custom Operation IDs, and Zod Schemas

pnpm exec client-generator --uri "https://api.example.com/openapi.json" --mode functional --client axios --axios-version "1.7.0"

3. Remove an Endpoint Prefix and Apply Regex Replacement

pnpm exec client-generator --uri "https://api.example.com/openapi.json" --remove-endpoint-prefix "/v1" --replace-endpoint-regex "/api/,/account-report-service/"

Contributing

Contributions are very welcome! If you have suggestions, issues, or improvements, please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.