In this short tutorial, we'll show how to generate a Java client application from Swagger file. There are multiple tools to achieve this, and here we'll use the simplest one-click approach, using Swagger.io code generator feature.
Some of the tools that could be used for this purpose are:
If you want to use
2. Generate Java Client Application From Swagger File
As we said, our focus will be on the Swagger.io code generator. So, let's see how to do this.
Step 1. Go to https://editor.swagger.io and copy/paste your Swagger file there. It could be in both JSON and YML format. Double-check that your Swagger file is valid. The swagger editor will tell you if there are any issues with your file.
Step 2. In the upper menu, click on Generate Client and then choose Java (or whatever else you prefer).
This will generate and download a zip file with the client application on your machine. The generated project will have support for both Maven and Gradle.
Open this zip and import it as a project.
In this short tutorial, we demonstrated how to create a Java REST client for your application that exposes REST API. If you want to have more flexibility and be able to choose which libraries will be used in client, you can check this tutorial where we show how to generate application client with Swagger Codegen, or this one where we'll use OpenAPI Generator.