背景
使用Swagger Editor,我为我的API创建了一个规范。我发现Swagger还提供了一个“生成客户端”的选项(可能使用Swagger Codegen)。
目标
我想生成一个客户端并在我的React应用程序中使用它(使用create-react-app创建),最好享有一些静态类型能力(当前使用flow)。
当前情况
Swagger Editor中的任何选项似乎都不起作用:
javascript
- 提供一个普通的node模块,您需要将其作为依赖项npm install
到您的项目中。现在,这不仅没有任何类/类型,而且还会失败:Uncaught Error: Cannot find module "ApiClient" at webpackMissingModule (index.js:17) at exports.ApiClient (index.js:17) at Object.<anonymous> (index.js:22) at __webpack_require__ (bootstrap 75f547b…:555) at fn (bootstrap 75f547b…:86) at new Index (index.js:87) at ReactCompositeComponent.js:295 at measureLifeCyclePerf (ReactCompositeComponent.js:75) at ReactCompositeComponentWrapper._constructComponentWithoutOwner (ReactCompositeComponent.js:294) at ReactCompositeComponentWrapper._constructComponent (ReactCompositeComponent.js:280)
typescript-*
选项与js不兼容,我不一定知道/想要将TypeScript添加到我的项目中。*-angular
选项当然是不相关的。
解决方法
- 生成
.ts
文件并将其转换为flow
。如何实现? - 手动将生成的
.js
文件添加到我的项目中。当前无法正常工作,因为生成的代码带有自己的依赖项。 - 在我的项目中添加TypeScript(我应该替换
flow
吗?)。如何实现?
谢谢