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 querystring
, url
and also the assign
imports.
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!
To get started, refer to the swagger-codegen GitHub. Install Apache Maven. Download the swagger-codegen source code from the GitHub repository. From a command prompt at the root directory of the Swagger source code, run the command mvn package .
The Swagger Codegen is an open source code-generator to build server stubs and client SDKs directly from a Swagger defined RESTful API. The source code for the Swagger Codegen can be found in GitHub.
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: https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/typescript-fetch/builds/es6-target#installation explains 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With