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

@namcaodev/postman-codegen

v2.3.2

Published

Auto generate all file typescript, query options, mutation options of tanstack query from postman json

Readme

Postman Codegen

GitHub license Version Build Status

Postman Codegen is a tool that helps you automatically generate typescript files, tanstack queries easily from postman json

✨ Features

  • 📌 Support full feature codegen typescript, tanstack query for people
  • ⚡ Optimized performance and easy to use
  • 🔧 Easily integrates with TypeScript projects

📦 Installation

Install via npm or yarn:

npm install @namcaodev/postman-codegen
# or
yarn add @namcaodev/postman-codegen

🚀 Usage

1. Create codegen.config.cjs

To configure the library, create a codegen.config.cjs file in your root project with the following examples options:

/**
 * @namcaodev/postman-codegen configuration.
 *
 * @type {import("@namcaodev/postman-codegen").CodegenConfig}
 */

module.exports = {
  generateType: 'seperate', // 'seperate' | 'combine',
  generateMode: 'json_file', // 'fetch' | 'json_file'
  postmanFetchConfigs: {
    collectionId: '<YOUR_COLLECTION_ID>',
    collectionAccessKey: '<YOUR_COLLECTION_ACCESS_KEY>'
  }, // Config for fetch Postman document (Require when generate mode is fetch)
  postmanJsonPath: "examples/postman-collection.json", // Postman Json Path (Require when generate mode is json_file)
  generateOutputPath: "examples/generated", // Generated Folder path
  propertyApiGetList: "items", // API response field containing list data
  enableZodGeneration: true, // Enable zod schema generation
  typeConfigs: {
    allPropertiesOptional: true, // Mark all properties as optional
    inferEnums: true, // inferEnums to string
    inferDateTimes: true, // inferDateTimes to string
  }, // Type configs for generate (Optional)
  fetcher: "../../../helpers/fetcher", // Link to your custom fetcher
  generateFileNames: {
    requestType: "apiRequests.ts",
    queryType: "apiQueries.ts",
    responseType: "apiResponses.ts",
    queryOptions: "query.ts",
    mutationOptions: "mutation.ts",
  }, // Customize generated file names (Optional)
};

2. Run the command

After adding the configuration file, run the following command to generate the code:

npx postman-codegen

The generated files will be saved in the folder specified in generateOutputPath (e.g., generated).

3. Usage in React Component

Next, easy usage in your React Component with full type safe power demo.tsx

import React from "react";
import { useQuery } from "@tanstack/react-query";
import {
  newmanGetRequestQueryOptions,
  newmanGetRequestQueryKeys,
} from "./generated/newman-get-request/query";

const DemoCodegen = () => {
  const query = useQuery({
    ...newmanGetRequestQueryOptions({
      source: "test",
    }),
  });
  const queryKeys = newmanGetRequestQueryKeys({ source: "test" });
  console.log("Data response", query);
  console.log("Query keys", queryKeys);
  return <div>DemoCodegen</div>;
};

export default DemoCodegen;

⚠️ Warning

With your custom fetcher you must follow the standard interface and function creation here:

export interface CustomFetchParams<TBody> {
  url: string;
  method: string;
  options?: RequestInit;
  body?: TBody;
}

export const customFetch = async <TResponseData = undefined, TBody = undefined>(
  params: CustomFetchParams<TBody>
): Promise<TResponseData> => {
  // You will handle your fetch here
};

export default customFetch; // You must be export default it

You can see an example in the source code here: fetcher.ts and how it is handled here: queryWithParams.hbs.

🔧 Configuration Options

| Option | Type | Required | Description | |--------|------|----------|-------------| | generateType | 'seperate' \| 'combine' | ❌ No (Default: seperate) | 'separate': Generates separate folders/files for each API path. 'combine': Merges all types and queries into a single file. | | generateMode | 'fetch' \| 'json_file' | ✅ Yes | Determines how data is retrieved from Postman. 'fetch' fetches the collection via API, while 'json_file' uses an exported JSON file. | | postmanFetchConfigs.collectionId | string | 🔹 If generateMode = 'fetch' | The Postman Collection ID to fetch. | | postmanFetchConfigs.collectionAccessKey | string | 🔹 If generateMode = 'fetch' | The API Key required to access the collection from Postman API. | | postmanJsonPath | string | 🔹 If generateMode = 'json_file' | Path to the exported Postman JSON file. | | generateOutputPath | string | ✅ Yes | Directory where the generated files will be stored. | | propertyApiGetList | string | ✅ Yes | The key containing the list of data in the API response. | | enableZodGeneration | boolean | ❌ No (Default: false) | If true, automatically generates Zod schemas. | | typeConfigs.allPropertiesOptional | boolean | ❌ No (Default: false) | If true, all properties will be optional. | | typeConfigs.inferEnums | boolean | ❌ No (Default: false) | If true, automatically infers enums from API responses. | | typeConfigs.inferDateTimes | boolean | ❌ No (Default: false) | If true, automatically detects datetime fields in responses. | | fetcher | string | ✅ Yes | Path to a custom fetcher function. | | generateFileNames.requestType | string | ❌ No (Default: apiRequests.ts) | Filename for API request definitions. | | generateFileNames.queryType | string | ❌ No (Default: apiQueries.ts) | Filename for API queries. | | generateFileNames.responseType | string | ❌ No (Default: apiResponses.ts) | Filename for API response types. | | generateFileNames.queryOptions | string | ❌ No (Default: query.ts) | Filename for query options. | | generateFileNames.mutationOptions | string | ❌ No (Default: mutation.ts) | Filename for mutation options. |

📌 Notes:

  • If generateMode = 'fetch', both postmanFetchConfigs.collectionId and postmanFetchConfigs.collectionAccessKey are required.

  • If generateMode = 'json_file', postmanJsonPath is required.

  • Using generateMode = 'fetch' allows you to sync updates from your backend in Postman documents instantly.

🛠 Contributing

If you want to contribute, please fork the repository and submit a pull request!

git clone https://github.com/NamCaoDev/postman-codegen.git
cd postman-codegen
npm install
npx postman-codegen

📜 License

Distributed under the MIT License. See the LICENSE file for more details.

🌍 Contact

Thank you for using Postman Codegen Library! 🚀