Using Swagger to Generate Client SDKs for REST APIs

These days Swagger is a popular, easy-to-use tool for (semi-)automatically documenting REST APIs on-the-fly. For example, in order to document a REST API created with Spring Boot and Jersey literally all you have to do is add these two entries to your Maven pom.xml:

You’ll then get a ready-made documentation for all your REST API endpoints. An example of how this looks like can be seen here.

While this already is very useful in that it helps with properly documenting your software, especially that part of it that will be consumed by other components, another, probably lesser-known feature of Swagger or rather part of the Swagger tool suite is Swagger Codegen (source code available here), which allows you to generate client SDKs for REST APIs documented with Swagger.

Supporting a wide variety of languages (currently more than 20) and client frameworks Swagger Codegen not only removes tedious plumbing from the development process but also provides tried and tested code for accessing REST APIs, which helps tremendously with improving the reliability and maintainability of client code.

Instead of constantly re-inventing the wheel when dealing with REST APIs you can just have Swagger Codegen create REST API servicing code for you.