This project helps generate an API Wrapper (SDK) for any API based on its OpenAPI Specification. The generated module provides a structured and easy-to-use Java client for interacting with the API, reducing the need to manually handle HTTP requests, responses, and error handling.
- Automatic API Client Generation – Converts an OpenAPI Specification into a ready-to-use Java SDK.
- Supports OkHttp & Retrofit – Choose between OkHttp (low-level control) or Retrofit (high-level API client).
- Handles Request & Response Parsing – Uses Gson for automatic JSON serialization.
- Customizable Dependencies – Select dependencies dynamically via CLI.
- Improved API Integration – No need to manually construct API requests.
When developing applications, directly handling HTTP requests, retries, response parsing, and API errors can lead to unnecessary complexity. By using a generated API Wrapper (SDK):
- API requests and responses are managed within a structured Java client.
- Business logic remains separate from network-related concerns.
- Handling retries, authentication, and error handling becomes standardized.
- Java 17 or later
- Maven
- OpenAPI YAML file (named
openapi.yaml
)
- Clone the repository:
git clone https://github.com/your-username/openapi-java-parser.git cd openapi-java-parser
- Build the Project:
mvn clean package
- The compiled JAR will be available at:
target/openapi-java-parser-{latest-version}.jar
You can visit our youtube channel to check the working of it: https://youtu.be/nEoP3hjDhIQ
To generate an API wrapper, run the JAR with the following options:
java -jar target/openapi-java-parser-{latest-release-version}.jar
-spec path/to/openapi.yaml
-output path/to/output_directory
-dependencies okhttp,jackson,slf4j
-type okhttp
Option | Description |
---|---|
-s, --spec |
Path to the OpenAPI YAML file |
-o, --output |
Output directory for the generated SDK |
-d, --dependencies |
Comma-separated list of dependencies (e.g., retrofit,jackson,okhttp ) |
-t, --type |
Type of API wrapper (retrofit or okhttp ) |
Once the SDK is generated, navigate to the output directory:
ls output
It should contain:
generated-sdk
├── pom.xml
├── src/main/java/com/example/
│ ├── MainApplication.java
│ ├── api/
│ │ ├── ApiWrapper.java
│ │ ├── RetrofitAPIClient.java (For Retrofit)
│ │ ├── OkHttpAPIClient.java (For OkHttp)
- Navigate to SDK Directory:
cd generated-sdk
- Build the SDK
mvn clean package
- Run the SDK:
mvn exec:java -Dexec.mainClass="com.example.MainApplication"
Contributions are welcome. If you would like to contribute, follow these steps:
- Fork the repository
- Create a new branch (feature/new-feature)
- Commit your changes (git commit -m 'Add new feature')
- Push to the branch (git push origin feature/new-feature)
- Open a pull request
- Email: krishjaiswal1701@gmail.com
- Linkedin: https://linkedin.com/in/jaiswal-krish