Sean Sean - 6 months ago 126
TypeScript Question

How to use Swagger Codegen TypeScript Fetch Client

Has anyone successfully used the Swagger Code Generator to create a TypeScript Fetch client that can be used within the browser? I'm trying to use the generated API client within a React application that uses TypeScript.

Although I've successfully generated a client (i.e. the api.ts file), I'm getting hung up on the fact that it begins with the following imports:

import * as querystring from "querystring";
import * as url from "url";

import * as isomorphicFetch from "isomorphic-fetch";
import * as assign from "core-js/library/fn/object/assign";

interface Dictionary<T> { [index: string]: T; }
export interface FetchAPI { (url: string, init?: any): Promise<any>; }


While I can successfully find the TypeScript typings (i.e. @types) for isomorphic-fetch and core-js, I can't find typings for querystring and url. As a result, I'm getting
[ts] Cannot find module...
for the
and also the

Is this client not actually intended to be used within the browser? Otherwise, can anyone provide any suggestions for what I might be doing wrong here?

Thanks in advance for any help!


Thanks for the link, wing328, that ended up taking me down the path that lead to the 'TypeScript Fetch'-specific readme. In particular, this section here: expalins that the Swagger Code Generator does not directly create JavaScript - you must run npm install or `npm publish'. You'll then be able to find the JavaScript-based API and associated typings in the dist folder.