This blog will give you a overview on generating Java client library for NodeJS project using Swagger Codegen.
Step-by-step guide
Add the steps involved:
- Install Swagger Codegen in your machine as detailed in page
- Make sure that we have endpoint in NodeJS project that exposes Swagger JSON Definition (/api-docs is exposed with Swagger Definition)
- Validate the Swagger Definition with help of Swagger Editor
- Invoke Code using the following command:
- swagger-codegen generate -i http://localhost:18138/api-docs -l java -o flex/executionconfig -c config.json --api-package com.ooyala.flex --artifact-id executionConfiguration --artifact-version 0.0.1
- Swagger Codegen options that is been used are described as follows:
- -i --> Spec file (JSON in our case)
- -l --> language for which the client library has to generated
- -o --> output directory
- -c --> custom configuration file location
- --api-package --> respective package name
- --artifact-id --> respective artifact ID
- --artifact-version --> version for the client
- The following custom config.json file that is used{"library":"feign",}
- codegen will create a src for client library similar to the following:
- Generated code will have README.md which will help us with the next steps
- To generate java client library and deploy to repository use any of the following based on the need
- mvn install
- man deploy
- Once the package/library is created we can use it in our java project by injecting the dependency
No comments:
Post a Comment