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

@tiny-codes/swagger-api-hub

v1.2.11

Published

Generate front-end access code for swagger backend services in one click

Readme

@tiny-codes/swagger-api-hub

npm version npm downloads GitHub License

cover image

Produce front-end interface code for OpenAPI-based backend services with a single click. This tool is designed to generate TypeScript code for API clients and request methods from OpenAPI specifications. It can be used as a command line tool or as a Node.js module that is integrated into your build process. It supports both OpenAPI 2.0 and 3.0 specifications.

This tool is a wrapper of the swagger-typescript-api

Installation

Install as a global command:

npm install -g @tiny-codes/swagger-api-hub

Install as a project-wide dependency:

npm install -D @tiny-codes/swagger-api-hub

Usage

Use as a global command

It reads the default configuration file ./swagger-api-hub.config.ts, you can also specify a custom configuration file.

$ swagger-api-hub  # read default config file
$ swagger-api-hub ./configs/custom-config.ts  # specify a custom config file

The configuration file should export an array of ServiceConfig objects. If you export only one object, it will generate the code directly without prompting.

The config file can be either local path or npm module path, and the file extension can be .ts, .js, .json, or any other module types supported by Node.js.

The file should look like this:

swagger-api-hub.config.ts

import type { ServiceConfig } from '@tiny-codes/swagger-api-hub';

const services: ServiceConfig[] = [
  {
    id: 'iam',
    name: 'User Management Service',
    url: 'https://api.example.com/iam/swagger/v3',
    authorizationToken: 'Basic XXXXXXXXXXXXXXXXXX',
    output: './src/api/iam',
  },
  {
    id: 'asset',
    name: 'Asset Management Service',
    url: 'https://api.example.com/public-api/asset/swagger/v3',
    authorizationToken: 'Basic XXXXXXXXXXXXXXXXXX',
    apiBase: '/public-api',
    output: './src/api/asset',
  },
];
export default services;

The ServiceConfig object has the following fields:

  • id: [required] A unique identifier for the service.
  • name: A human-readable name for the service.
  • url: [required] The URL of the OpenAPI specification file. If you have a local file, you can use input instead of url to specify the file path. Or you can even use spec to provide the OpenAPI specification object directly. Either url, input, or spec is required.
  • apiBase: The base path of all API endpoints. The service may be hosted on a subpath of the main domain, e.g., /public-api/iam/v3, then the apiBase is /public-api in this case. If the original api path from the OpenAPI specification is acceptable, you don't need this field.
  • crossOrigin: Whether to use the absolute api path when calling the service. This is useful when the service is hosted on a different domain and you need to set the Access-Control-Allow-Origin header. Default is false.
  • dataTypeMappings: A map of some special data types to TypeScript types. Default is { int64: 'BigInt', object: 'Record<string, any>' }.
  • output: The output directory for the generated code. Default is ./src/api/{id}.
  • httpClientFile: Change the default path of http-client.ts file, so you can use your own http client. Default is ./http-client of each service directory.
  • createApiInstance: Whether to create an instance of each API class. The instance can only be created with an empty constructor, if you want to set different options for some api classes, you can set this to false and create the instance manually. Default is true.
  • intTotalElements: Whether to force convert totalElements in dataContracts to number(int32) type. Default is false.

For more options, please refer to the swagger-typescript-api#options documentation.

Use as a npm dependency

import { generate, promptToGenerate } from '@tiny-codes/swagger-api-hub';
import type { ServiceConfig } from '@tiny-codes/swagger-api-hub';
import serviceConfigs from './swagger-api-hub.config';

// Usage1: generate multiple services with prompts
promptToGenerate(serviceConfigs);

// Usage2: generate a single service directly
generate(serviceConfigs[0]);