Reputation: 1561
I have a npm
-based project and I want to introduce swagger
-based REST API client into it. My idea is to have API description yaml
file and generate client on build step.
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.
Upvotes: 1
Views: 6466
Reputation: 10807
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. An example of the curl request to generate ruby client for http://petstore.swagger.io/v2/swagger.json
is as follows:
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.
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. Please refer to the Q&A for more information.
Upvotes: 3