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 428 users
Languages   TypeScript 87.2% | EJS 9.7% | JavaScript 3.1%
🌐
npm
npmjs.com › package › swagger-typescript-api
swagger-typescript-api - npm
1 week ago - Generate the API client for Fetch or Axios from an OpenAPI Specification. Latest version: 13.6.10, last published: 42 minutes ago. Start using swagger-typescript-api in your project by running `npm i swagger-typescript-api`. There are 144 other ...
      » npm install swagger-typescript-api
    
Published   Apr 16, 2026
Version   13.6.10
🌐
Medium
medium.com › @youry.stancatte › generating-typescript-interfaces-from-swagger-1910cc7a726a
Generating Typescript interfaces from Swagger | by Youry Stancato | Medium
January 23, 2023 - You can do it via command line. At this moment the latest openapi-typescript lib only accepts the swagger specification v3 or higher, but you can use the openapi-typescript@5.4.1 to generate interfaces from the version 2
🌐
Reddit
reddit.com › r/typescript › how do you generate and manage your api types?
r/typescript on Reddit: How do you generate and manage your API types?
February 13, 2024 -

At work we have a pretty simple set up: Next.js frontend hosted on Vercel and a Java/Dropwizrd backend hosted on AWS. Our backend uses Swagger/Open API, and we generate our types based on the swagger.json.

Frankly, this sucks to manage across deployments and branches. Our backend is in a separate repository, so we frequently block preview deployments because our hosted staging or dev instance is either ahead or behind our frontend.

Our types are generated either via script locally or right before our build on vercel. We do not commit them, and we’d prefer to never commit them

We are considering a monorepo, which for other reasons as well, might be the most sane solution. I have considered hosting our types, creating packages in a private NPM repository, trying some kind of gRPC solution, but none of them really seem that straight forward, nor do they really “fix” our problem.

How have you or how have you seen synchronizing backend and frontend types? Any solution or architecture ideas for this would be very helpful!

🌐
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 - Also, an automated job can generate the a new TS client triggered by some event. But still it's up to us to update the consumers. Hopefully the unit tests can detect breaking changes. Check out a full working code in my repo. Sorry that I didn't follow all the best practices as I only wanted to show how to use this TS client. This project was bootstrapped with Create React App. npx create-react-app react-mini-swagger-client --template typescript · And API client was generated with swagger-typescript-api.
Find elsewhere
🌐
iO tech_hub
techhub.iodigital.com › articles › generate-types-with-swagger
Quick Tip: Generate Types Based on OpenAPI (Swagger)
May 12, 2025 - You can find the Swagger UI here and the Swagger file here. The package we will use is called swagger-typescript-api. It is a command-line tool that generates TypeScript types and API clients from OpenAPI (Swagger) specifications.
🌐
GitHub
github.com › john-zulhelmi › swagger-typescript-api
GitHub - john-zulhelmi/swagger-typescript-api · GitHub
This option will group your API ... internal structs using for generating output with using generateApi options codeGenConstructs and primitiveTypeConstructs....
Author   john-zulhelmi
🌐
GitHub
github.com › rmkasendwa › swagger-to-ts
GitHub - rmkasendwa/swagger-to-ts: swagger-to-ts is a powerful library that allows you to generate TypeScript code from Swagger documentation or OpenAPI specifications. It simplifies the process of integrating API definitions into your TypeScript projects, saving you time and effort.
Generate TypeScript interfaces and types from Swagger or OpenAPI specifications. Supports both Swagger 2.0 and OpenAPI 3.0 specifications. Provides strong type safety by inferring data types, request bodies, response schemas, and more.
Author   rmkasendwa
🌐
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 - One of the primary tools utilized ... With this tool, you can easily generate your payload models and response models and also generate all services with Axios or fetch automatically....
🌐
Andrew Zakordonets
biercoff.com › my-small-investigation-about-swagger-codegen-generation-in-typescript
Generating typescript API client from Swagger
June 15, 2021 - It was relatively simple to set up a process where we would generate API clients using swagger-codegen, push them to our Nexus repository and use this library as a dependency in our Test Framework. It works well for us, but recently we concluded that we need to build something similar in Typescript.
🌐
Swagger
swagger.io › tools › swagger-codegen
API Code & Client Generator | Swagger Codegen
Codegen simplifies your build process by generating server stubs and client SDKs for any API defined with the OpenAPI specification. Download Codegen today.
🌐
Fig
fig.io › manual › swagger-typescript-api
swagger-typescript-api | Fig
swagger-typescript-api generate-templates · Generate api via swagger scheme · On this page · Subcommands ·
🌐
GitHub
github.com › hosseinmd › swagger-typescript
GitHub - hosseinmd/swagger-typescript: An auto typescript/javascript code generator from swagger. · GitHub
Support OpenApi v3, swagger v2 and postman collection · An auto typescript/javascript/kotlin code generator from APIs doc. Each endpoint will be created as a function, full type base.
Starred by 84 users
Forked by 25 users
Languages   TypeScript 83.8% | JavaScript 16.1% | Shell 0.1%
🌐
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 - import express from 'express'; import { employeeRouter } from './employee-route'; export const routes = express.Router(); routes.use('/api/employee', employeeRouter); If import *** from *** gives an error, there could be an error in your tsconfig.json file. It is important to give “esModuleInterop” field true and if you already defined this, you can restart your IDE. Next, we define swagger.ts file. ... import swaggerAutogen from 'swagger-autogen'; const doc = { info: { version: 'v1.0.0', title: 'Swagger Demo Project', description: 'Implementation of Swagger with TypeScript' }, servers: [
🌐
GitHub
github.com › jpb06 › swagger-typescript-types
GitHub - jpb06/swagger-typescript-types: Generating typescript typings from swagger · GitHub
This function extracts models from the swagger json and generates typings from them. Typical use: const outPath = './src/api/types'; const schema: ValidatedOpenaApiSchema = { ...
Starred by 4 users
Forked by 3 users
Languages   TypeScript 97.2% | JavaScript 2.8%
🌐
Medium
medium.com › @david.barrineau_14226 › swagger-to-typescript-ad663a9cf57e
Swagger to TypeScript. Read free here. | by David Barrineau | Medium
February 5, 2026 - The server then makes a request to the Swagger endpoint to grab the JSON, makes a system call to “npx swagger-typescript-api” to generate the TypeScript file, then zips up the JSON and TypeScript that gets returned to the browser to download.
🌐
Codepruner
codepruner.com › how-to-use-apiclient-generated-by-swagger-typescript-api
How to use apiClient generated by swagger-typescript-api
I mean we need to pass a `baseUrl` for example. const httpClient = new HttpClient({ baseURL: baseUrl, headers: { "X-api-version": "1.0", "content-type": "application/json;charset=UTF-8", }, securityWorker, }); return new GeneratedApiClient(httpClient); }; const getBaseUrl = () => { // you should replace it with getting an addres from your conifg return "httos://localhost:4444"; } // It is a specific part of the generated client.