Swagger / OpenAPI API规范的Reactjs客户端

问题描述 投票:5回答:1

背景

使用Swagger Editor,我为我的API创建了一个规范。我看到Swagger在其Swagger编辑器中还提供了“生成客户端”选项(可能使用Swagger Codegen)。

目的

[我想生成一个客户端并在我的React应用程序(使用create-react-app创建)中使用它,并且最好享受一些静态键入功能(当前使用flow)。

当前

Swagger编辑器中的所有选项似乎都不起作用:

  • javascript-提供一个香草节点模块,您需要将其作为对项目的依赖项。现在,不仅没有任何类/类型,而且还失败了: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) ]选项与js不兼容,我不必知道如何/想要将TypeScript添加到我的项目中。
  • typescript-*选项当然是不相关的。

方法

  • 生成*-angular文件并将其转换为.ts。怎么样??
  • 手动将生成的flow文件添加到我的项目中。当前不起作用,因为生成的代码带有其自己的依赖项。
  • 将TypeScript添加到我的项目中(我应该替换.js吗?)。怎么样??

谢谢

reactjs typescript swagger flowtype swagger-codegen
1个回答
0
投票

有一个简单的解决方案,直到生成器退出使用动态实现,例如flow为止

© www.soinside.com 2019 - 2024. All rights reserved.