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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gasbuddy/small-openapi-codegen

v0.4.3

Published

Parse an OpenAPI spec and generate fetch-based clients for Javascript environments (React Native and Node 12+)

Readme

small-openapi-codegen

main CI

A lightweight OpenAPI client generator that creates fetch-based TypeScript clients for JavaScript environments (both Node.js and browsers including React Native).

Features

  • Generates TypeScript clients from OpenAPI 3.0 specifications
  • Supports JSON, form-urlencoded, and multipart/form-data content types
  • Strongly typed request and response objects matching your API spec
  • Handles path, query, header parameters
  • Type-safe file uploads with multipart/form-data
  • Simple fetch-based implementation (no heavy dependencies)
  • Works in Node.js 18+ and modern browsers

Installation

# Global installation
npm install -g @gasbuddy/small-openapi-codegen

# Local installation
npm install --save-dev @gasbuddy/small-openapi-codegen

Or with Yarn:

# Global installation
yarn global add @gasbuddy/small-openapi-codegen

# Local installation
yarn add --dev @gasbuddy/small-openapi-codegen

Usage

Command Line

The simplest way to use small-openapi-codegen is via the command line:

small-openapi-codegen <path-to-spec-file> --output <output-directory> [options]

Command Line Arguments

| Argument | Description | |----------|-------------| | <path-to-spec-file> | Path to the OpenAPI specification file (required) | | --output <dir> | Directory where generated client code will be saved (required) | | --language/--lang/-l <lang> | Language template to use (default: 'ts') | | --name <name> | Package name for the generated client (default: derived from spec filename) | | --className <name> | Class name for the generated client (default: derived from package name) | | --namespace <namespace> | NPM namespace for the package (e.g. "@myorg") | | --snake | Use snake_case for property names instead of camelCase | | --prettierConfig <path> | Path to a Prettier configuration file to format generated TypeScript code |

Example

Let's say you have an OpenAPI spec called pet-store.yaml:

# Generate a TypeScript client for the pet-store API
small-openapi-codegen pet-store.yaml --output ./pet-client

# Generate with custom package name and class name
small-openapi-codegen pet-store.yaml --output ./pet-client --name "pet-api" --className "PetStoreClient"

# Generate with npm namespace
small-openapi-codegen pet-store.yaml --output ./pet-client --namespace "@my-org"

# Generate with snake_case property names (instead of camelCase)
small-openapi-codegen pet-store.yaml --output ./pet-client --snake

# Generate with a custom Prettier configuration
small-openapi-codegen pet-store.yaml --output ./pet-client --prettierConfig ./.prettierrc

Generated Client Usage

The generated client can be used like this:

// Import the generated client
import { PetStoreClient } from './pet-client';

// Initialize the client with configuration
const client = new PetStoreClient({
  baseUrl: 'https://api.example.com',
  // Required implementation classes
  fetch: globalThis.fetch,
  FormData: globalThis.FormData,
  AbortController: globalThis.AbortController
});

// Use typed methods matching your API spec
async function fetchPets() {
  try {
    // All responses are typed according to your OpenAPI spec
    const response = await client.listPets();
    
    if (response.status === 200) {
      // The response.body is typed as the schema from your spec
      const pets = response.body;
      return pets;
    } else {
      throw new Error(`Error fetching pets: ${response.status}`);
    }
  } catch (error) {
    console.error('API call failed:', error);
    throw error;
  }
}

// Working with form data
async function uploadPetPhoto(petId: number, photoFile: Buffer | Blob) {
  const response = await client.uploadPetPhoto({
    body: {
      petId,
      photo: photoFile
    },
    // Optionally provide filename and content type
    options: {
      photo: { 
        filename: 'pet.jpg',
        contentType: 'image/jpeg'
      }
    }
  });
  
  if (response.status === 200) {
    return 'Upload successful';
  } else {
    throw new Error(`Upload failed: ${response.status}`);
  }
}

Development

Building the project

# Install dependencies
yarn install

# Build the project
yarn build

Testing

# Run tests
yarn test

# Generate a test client from the sample spec
yarn build-and-test-client