{"API Evangelist"}

Comparison of Automatic API Code Generation Tools For Swagger

I have met with the APIMATIC team several times over the last couple weeks to discuss the state of API definitions. If you aren't familiar with APIMATIC, they are a API code as a service provider, that generates high quality client code in several languages, if your APIs are defined using common API definition formats like Swagger (they are also the people behind SDKs.io). APIMATIC is as passionate about high quality Swagger definitions as I am, and have shared some really valuable research to help push forward the API definition conversation.

In May, APIMATIC wanted to compare the quality of automatic code generation tools, using common Swagger specifications they found on Github. To set the bar for their research, APIMATIC established some basic operational parameters:

While this research focuses on Swagger, I think the findings can be applied when thinking about other API definition formats like API Blueprint or RAML, but kicking things off with a focus on Swagger is wise. With a basic framework defined, APIMATIC picked four of the leading code generation tools out there currently:

As part of the decision to look at Swagger CodeGen, REST United, Restlet Studio, and their own APIMATIC solution, they provide a little detail on the code generation engines behind each solution:

They took a sampling of Swagger specifications out of the thousands they found, and did a side by side comparison of how well each of the platforms did with the Swagger definitions, bringing us to the meat of this research, which as APIMATIC states “successful compilation does not mean that the SDK will work out of the box!”. In short, there are a lot of things to consider when generating code, and APIMATIC helps us see the problems with approaches to code generation, as well as the overall quality of Swagger definitions that are available out there.

Embarrassingly two of the Swagger definitions they used were mine, which I acknowledge are often very incomplete, but they did use others well, including the sample Petstore definition used as demo for Swagger. The message is pretty loud -- the quality of Swagger definitions right now is pretty poor, and while APIMATIC goes a long way to ensure a usable client SDK is generated, they can only do so much with crap Swagger definitions.

 APIMATIC looks at some of the tops reasons why the code generated is so bad, resulting in code that often times just will not work:

As they put it, here is APIMATIC’s struggle: "SDK’s should work out of the box! Generated code often does not work out of the box, AND to make matter even worse, its not even easy to fix by hand. APIMATIC has implemented fallbacks to handle missing schemas and model definitions, but missing auth info cannot be fixed by any fallback measure."

After you separate the differences in approaches by each code generation engine, it really comes down to a handful of reasons why the Swagger definitions are incomplete--something I see a lot of, as I look for Swagger definitions across the space:

These are the common problems I suffer from with many of my own Swagger definitions, as well as many I discover across the Internet. In my opinion, a complete Swagger definition is more art than tech, and you need the human who really cares about an API to hand finish it. I have many Swagger definitions that are complete, well as complete as the API is, but many I have for public APIs in my API Stack directory, are a work in progress.

APIMATIC also provides three interesting proposal for enhancing Swagger definitions so we can automatically generate more robust code in the future:

The last one is just good API design, the other two are more about additions to the Swagger specification. APIMATIC also provides us with a look at the future, if we get our collective Swagger together, we can realize some serious benefits that will help us throughout the API life cycle:

I see APIMATIC as just one of many emerging API service providers who live along a Swagger driven API life cycle, but I feel they are one of the most important barometers we have, that we can use to understand the overall health of the Swagger ecosystem. If you can’t generate working client code from your Swagger, it is likely you won’t be able to mock, test, monitor, or achieve other critical stops along the API life cycle.

Of course, I would be neglectful if I didn’t mention that the APIMATIC team is obviously biased, as their motivation is to sell their services. This is true, but APIMATIC is the only player to emerge in the code generation game that I’ve seen actually provide a high quality perspective and solution to the problem of client code generation. Look at what they offer:

I also known Adeel and Zeeshan, and know they truly care about the health and quality of the API ecosystem, as well as looking to sell the valuable services they bring to the table with APIMATIC and SDKs.io. There is a lot of valuable insights to work with in the research they have started, something I will be contributing to in the future. I will let you review the slide deck from their research below, but I also wanted to point out two addition slides that I thought were interesting.

Statistics for Sources of API Descriptions (Where They Found Definitions)

Statistics for API Descriptions Located (What Format The Definitions Were)

There are two things interesting here, what formats are available, and where are people putting them. I’m focused heavily on supporting Swagger and API Blueprint, and often find that discovery and indexing of these definitions is very difficult. I can find definitions on Github fairly easy, but finding them on the open Internet is proving to be more challenging, and resource intensive—something I will be working with the APIMATIC team on more as well.

The moral of this story is that the Swagger definitions we are creating need to be more complete, and I think it points to the fact that we need more services and tooling to help us validate the completeness of our definitions, something I will also be working with the APIMATIC team on. We need a community driven way to share these API definitions, and as a community to help validate and certify API definitions, and also help complete them when necessary.

I will work with APIMATIC to conduct this research on a regular basis, and is something we are both committed to improving on. In future posts, I’ll talk about the work we are doing between APIMATIC, SDKs.io, and my API Stack research, which will provide opportunities for the community to get involved—so stay tuned.