Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Typescript open-api cilent generation and usage of `fetch`

I am trying to generate a typescript client for my rest server. This typescript client is expected to work for both browser and in Node.js environment (server side).

I used

openapi-generator-cli generate \ 
-i openapi-pets.yml \
-o output \
--generator-name typescript-fetch \
--additional-properties=typescriptThreePlus=true

after this I get this genrated

── apis
│   ├── PetsApi.ts
│   └── index.ts
├── index.ts
├── models
│   ├── ModelError.ts
│   ├── Pet.ts
│   └── index.ts
└── runtime.ts

When I run

ts-node index.ts

I get tons of errors like

error TS2304: Cannot find name 'Response'.

In attempt to fix this I added tsconfig.json at the root with this content

{
  "compilerOptions": {
    "module": "commonjs",
    "sourceMap": true,
    "lib": [
      "es2015",
      "dom"
    ]
  }
}

All errors are gone now I try to use the API (modified index.ts with following content)

/* tslint:disable */
/* eslint-disable */
export * from './runtime';
export * from './apis';
export * from './models';

import {
    PetsApi,
} from './apis';

import {
    Configuration,
    ConfigurationParameters,
} from "./runtime";

const configParams: ConfigurationParameters = {
    basePath: 'https://petstore.swagger.io/v2/',
    middleware: [],
};

const apiConfig = new Configuration(configParams);

export const apiClient = {
    petsAPI: new PetsApi(apiConfig),
};

export type ApiClient = typeof apiClient;

apiClient.petsAPI.listPets().then(value => console.log(value));

and I try to run it

ts-node index.ts

and results into

ReferenceError: fetch is not defined

How can I make this project a "Node" project and define the dependency of fetch?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!