简体   繁体   English

Swagger 客户端生成

[英]Swagger client generation

I have a npm -based project and I want to introduce swagger -based REST API client into it.我有一个基于npm的项目,我想在其中引入基于swagger的 REST API 客户端。 My idea is to have API description yaml file and generate client on build step.我的想法是拥有 API 描述yaml文件并在构建步骤中生成客户端。 Is there any well knows approaches to do it?是否有任何众所周知的方法来做到这一点? I found only swagger-js-codegen but I don't clearly understand how to integrate it into building process.我只找到了swagger-js-codegen但我不清楚如何将它集成到构建过程中。

Given that you've your REST API documented in Swagger/OpenAPI spec, you can then simply use curl (or other http tools) to send an HTTP request to generate API clients as part of your build process.鉴于您在 Swagger/OpenAPI 规范中记录了 REST API,然后您可以简单地使用curl (或其他 http 工具)发送 HTTP 请求以生成 API 客户端,作为构建过程的一部分。 An example of the curl request to generate ruby client for http://petstore.swagger.io/v2/swagger.json is as follows:http://petstore.swagger.io/v2/swagger.json生成 ruby​​ 客户端的 curl 请求示例如下:

curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' https://generator.swagger.io/api/gen/clients/ruby

Please refer to https://github.com/swagger-api/swagger-codegen#online-generators for more info.请参阅https://github.com/swagger-api/swagger-codegen#online-generators了解更多信息。

UPDATE: On May 2018, about 50 top contributors and template creators of Swagger Codegen decided to fork Swagger Codegen to maintain a community-driven version called OpenAPI Generator .更新:2018 年 5 月,大约 50 名 Swagger Codegen 的顶级贡献者和模板创建者决定分叉 Swagger Codegen 以维护一个名为OpenAPI Generator的社区驱动版本。 Please refer to the Q&A for more information.请参阅问答以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM