I would recommend that you use a library that handles everything for you such as tsoa which can easily generate Swagger/OpenAPI documents from your TypeScript types. It also does the runtime validation for you so that you know the request actually is the type that TypeScript says it should be. The readme contains all of the setup information that you would need to start using it. It's compatible with express, hapi, koa, and more:

https://github.com/lukeautry/tsoa


(Full Transparency: I am one of the maintainers of tsoa. But I was first a consumer of tsoa and I find it to be a great product... that's why I asked to help maintain it! :) )

Answer from GreeneCreations on Stack Overflow
🌐
GitHub
github.com › acacode › swagger-typescript-api
GitHub - acacode/swagger-typescript-api: Generate the API Client for Fetch or Axios from an OpenAPI Specification · GitHub
import * as path from "node:path"; import * as process from "node:process"; import { generateApi } from "swagger-typescript-api"; await generateApi({ input: path.resolve(process.cwd(), "./swagger.json") });
Starred by 4.1K users
Forked by 427 users
Languages   TypeScript 87.2% | EJS 9.7% | JavaScript 3.1%
🌐
npm
npmjs.com › package › swagger-typescript-api
swagger-typescript-api - npm
2 weeks ago - import * as path from "node:path"; import * as process from "node:process"; import { generateApi } from "swagger-typescript-api"; await generateApi({ input: path.resolve(process.cwd(), "./swagger.json") });
      » npm install swagger-typescript-api
    
Published   Apr 16, 2026
Version   13.6.10
Discussions

node.js - How to generate swagger API doc from TypeScript based Express app? - Stack Overflow
I am able to configure swagger url using the Express API with autogenerated OpenAPI doc through Swagger article. I am using TypeScript and it generates .js files under dist which does not have any ... More on stackoverflow.com
🌐 stackoverflow.com
How to generate basic TypeScript interfaces from Swagger schema? - Stack Overflow
I'm looking for a way to generate simplistic TypeScript interfaces from a Swagger schema. Most solutions I find are needlessly complicated. I would like to generate interfaces like this: export More on stackoverflow.com
🌐 stackoverflow.com
Any examples of how to use the output from swagger-typescript-api?
One question. Does your swagger json file contains possible exception codes for a given api? If not, then generated sdk will not handle it. More on reddit.com
🌐 r/typescript
3
5
October 2, 2024
API Testing Schema Validation?
Use openapi-zod-client . It generates Zod schemas and a type-safe API client from your OpenAPI specs that validates endpoint responses automatically at runtime using the generated schemas. So, inside your tests, all you need to do is to send requests. The library will validate the responses for you. In other words, if the request is successful, the response is valid. Since the library also generates Zod schemas, you can use them to validate the responses manually if really you want to. More on reddit.com
🌐 r/typescript
7
5
September 16, 2024
🌐
DEV Community
dev.to › po5i › how-to-generate-a-typescript-client-from-a-swagger-documented-api-14d8
How to generate a TypeScript client from a Swagger documented API - DEV Community
March 20, 2022 - In my previous tutorial, I built a simple REST API with Swagger documentation. Check it out: ... In this tutorial, I will generate a TypeScript client code based on the Swagger documentation and use it on a simple React application (it can be any front-end application).
🌐
Fig
fig.io › manual › swagger-typescript-api
swagger-typescript-api | Fig
swagger-typescript-api · swagger-typescript-api generate-templates · Generate api via swagger scheme · On this page · Subcommands ·
🌐
Medium
medium.com › @youry.stancatte › generating-typescript-interfaces-from-swagger-1910cc7a726a
Generating Typescript interfaces from Swagger | by Youry Stancato | Medium
January 23, 2023 - Generating Typescript interfaces from Swagger When developing a REST API, the Swagger specification (or OpenAPI specification) is a popular way to describe the endpoints and data types used by the …
🌐
DEV Community
dev.to › wkrueger › integrating-apis-to-a-typescript-frontend-with-openapi-swagger-3521
Integrating APIs to a TypeScript frontend with OpenAPI/Swagger - DEV Community
November 7, 2019 - Given some REST API and its OpenAPI ... from my TypeScript front-end codebase in a type-safe way, just as functions, abstracting away details from the (http) protocol. We will be using SendGrid's REST API as an example here. The link includes an OpenAPI representation as both json or yaml. While they have a custom render for this API on their website, you could also paste the .yaml into the swagger ...
Find elsewhere
🌐
GitHub
github.com › hosseinmd › swagger-typescript › blob › master › readme.md
swagger-typescript/readme.md at master · hosseinmd/swagger-typescript
For Example: Get method of '/Account' ... · Before running, add your config to swagger.config.json · { "url": "http://example.com/api/swagger.json", "dir": "./services", "prefix": "/api" } yarn swag-ts ·...
Author   hosseinmd
🌐
GitHub
github.com › john-zulhelmi › swagger-typescript-api
GitHub - john-zulhelmi/swagger-typescript-api · GitHub
Usage: sta [options] Usage: swagger-typescript-api [options] Usage: swagger-typescript-api generate-templates [options] Options: -v, --version output the current version -p, --path <string> path/url to swagger scheme -o, --output <string> output path of typescript api file (default: "./") -n, --name <string> name of output typescript api file (default: "Api.ts") -t, --templates <string> path to folder containing templates -d, --default-as-success use "default" response status code as success response too.
Author   john-zulhelmi
🌐
Stackademic
stackademic.com › blog › how-to-create-api-documentation-fast-swagger-with-typescript-a5926acbed30
How To Create API Documentation (FAST): Swagger With TypeScript | Stackademic
August 20, 2023 - { info: { version: 'v1.0.0', title: 'Swagger Demo Project', description: 'Implementation of Swagger with TypeScript' }, servers: [ { url: 'http://localhost:8080', description: '' }, ], components: { securitySchemes: { bearerAuth: { type: 'http', ...
🌐
Medium
medium.com › @david.barrineau_14226 › swagger-to-typescript-ad663a9cf57e
Swagger to TypeScript. Read free here. | by David Barrineau | Medium
February 5, 2026 - JSON: http://localhost:<port>/v3/api-docs HTML: http://localhost:<port>/swagger-ui/index.html#/ The next thing to tackle was how to generate TypeScript from the Swagger JSON file.
🌐
Medium
medium.com › bb-tutorials-and-thoughts › how-to-add-swagger-to-nodejs-rest-api-typescript-version-5a63953c993b
How To Add Swagger To NodeJS REST API — Typescript Version | by Bhargav Bachina | Bachina Labs | Medium
September 9, 2020 - Here is the complete demo where you can execute all the calls through the swagger docs. You can access the swagger page with this URL http://localhost:3080/api-docs/
🌐
Codepruner
codepruner.com › how-to-use-apiclient-generated-by-swagger-typescript-api
How to use apiClient generated by swagger-typescript-api
What should be intput and output for passing function type ApiClientOptions<ResponseType> = ( apiClientParameters: ApiClientParameters ) => Promise<AxiosResponse<ResponseType>>; // if you want to add more paramaters to the ApiClient, I think they should be defined here type ApiClientParameters = { api: GeneratedApiClient<unknown>; }; //it is the internal method method const createApiClient = (): GeneratedApiClient<unknown> => { const baseUrl = getBaseUrl(); // we need to configure it a bit on start.
🌐
iO tech_hub
techhub.iodigital.com › articles › generate-types-with-swagger
Quick Tip: Generate Types Based on OpenAPI (Swagger)
May 12, 2025 - It is a command-line tool that generates TypeScript types and API clients from OpenAPI (Swagger) specifications. The package can be installed locally or used directly in your CLI, for this example, we will install start with the CLI option. ... Here we simply run the generate command from the package and pass the URL of the Swagger file.
🌐
Medium
medium.com › @sina.alizadeh120 › unlocking-rapid-development-typescript-model-generation-with-swagger-5c184a3c89f4
Unlocking Rapid Development: TypeScript Model Generation with Swagger | by Sina Alizadeh | Medium
January 15, 2024 - In this configuration, adding the `pathModification` section to the first input URL is essential when API calls and services generated by Swagger-Typescript-API require a specific API prepend segment.
🌐
Reddit
reddit.com › r/typescript › any examples of how to use the output from swagger-typescript-api?
r/typescript on Reddit: Any examples of how to use the output from swagger-typescript-api?
October 2, 2024 -

Lots of examples of how to run the tool to generate a client based on an OpenAPI spec.... but damn'd if I can't find an example of how to use it.

Here's where I'm at (this is in a ReactJS app):

import { Api } from "../../../swaggergen/Api";
import { loginRequest } from "../authConfig";
import { msalInstance } from "../index";

export async function getApiClient() {

    var client = new Api({
        baseUrl: "",
        securityWorker: () => {
            const account = msalInstance.getActiveAccount();
            if (!account) {
                throw Error("No active account! Verify a user has been signed in and setActiveAccount has been called.");
            }
        
            const response = await msalInstance.acquireTokenSilent({
                ...loginRequest,
                account: account
            });
                    
            return {
                headers: {
                    Authorization: `Bearer ${response.accessToken}`
                },
            };
        },
    });
        
    // Halp... how to use client?
    //?     var d = await client.v1.MyFunkyList();
    //?     var r = await d.json();
}

How do I get typed results out of the API? MyFunkyList() on success should returns and instance of MyFunkyData. But danged if I see how?

Also, how do I handle error conditions? For example some POST calls will return 400 bad request with standard JSON message that contains the error details. How do I detect 400; how do I get the JSON data?

The tool's site: https://www.npmjs.com/package/swagger-typescript-api

Thanks a ton!

🌐
CodeSandbox
codesandbox.io › examples › package › swagger-typescript-api
swagger-typescript-api examples - CodeSandbox
AboutGenerate the API client for Fetch or Axios from an OpenAPI Specification347,663Weekly Downloads · Latest version13.2.14 · LicenseMIT · External Links · github.com/acacode/swagger-typescript-api ·