用于 Swagger/OpenAPI API 规范的 Reactjs 客户端 [英] Reactjs client for Swagger / OpenAPI API specification

查看:31
本文介绍了用于 Swagger/OpenAPI API 规范的 Reactjs 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Background

Using Swagger Editor, I created a spec for my API. I see that Swagger also provide a "Generate a client" option in their Swagger Editor (probably using Swagger Codegen).

Objective

I want to generate a client and use it in my React app (created with create-react-app), and preferably enjoy some static typing capabilities (currently using flow).

Currently

None of the options in Swagger Editor there seem to work:

  • javascript - provides a vanilla node module that you need to npm install it as a dependency to your project. Now, not only this doesn't have any classes / types, but also fails with: 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-* options are not compatible with js, and I don't necessarilty know how / want to add TypeScript to my project.
  • *-angular options are of course irrelevant.

Approaches

  • Generate .ts file and covert it to flow. How??
  • Manually adding the generated .js files to my project. Currently doesn't work as the generated code comes with its own dependencies.
  • Add TypeScript to my project (should I replace flow then?). How??

Thanks

解决方案

There is a simple solution until a generator is out to use dynamic implementation such as swagger-js

这篇关于用于 Swagger/OpenAPI API 规范的 Reactjs 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆