8-9 October

Chancery Pavilion Hotel, Bengaluru

Apidays India 2025

8-9 October

Chancery Pavilion Hotel, Bengaluru

OpenAPI’s Broken Tooling: Roundtrip Fidelity Failure with CodeGen and DocGen​

By Naresh Jain

Share this page

Exploring the Strengths and Weaknesses of Automated API Development 

Maintaining well-documented and reliable APIs is essential for any microservices development pipelines. At the heart of this process for OpenAPI specs are two important tools: CodeGen and DocGen. CodeGen, short for code generation, and DocGen, documentation generation, are designed to streamline the development cycle by automating the creation of server code and API documentation from OpenAPI specifications. 

The concept is elegant in its simplicity. Start with a clear API specification, use CodeGen to automatically generate the necessary boilerplate code for your API server, and then utilize DocGen to maintain up-to-date documentation. This supposedly creates a seamless, round-trip cycle where the specification and the implementation remain perpetually in sync. 

However, the practical application of these tools is not without its pitfalls. When we tested this, comparing the original API specification with the one regenerated from the code, discrepancies like dropped examples and duplicated details came to light. These inconsistencies are more than minor inconveniences; they highlight significant concerns regarding the reliability of these automated tools. 

What is Contract-Driven Development? 

Contract-Driven Development (CDD) is an approach where API specifications serve as executable contracts between API providers and consumers. This methodology enables efficient communication among teams, ensuring everyone adheres to the agreed-upon API structures. By maintaining these API specifications in a central Git repository, CDD allows for seamless version control and collaboration. 

The Round Trip: Specification to Code and Back 

Let’s explore an example by introducing a simple OpenAPI specification for a product API. This API includes a single path called /product, which supports the POST method to create a product. The path includes response codes for successful creation (201) and bad requests (400). 

To showcase the capabilities of CodeGen, we run a command using the OpenAPI generator, which takes the given specification file and generates boilerplate code for a Spring Boot application. Within moments, the tool produces the necessary controller and other classes. The generated code is substantial enough to bootstrap development and ensure that all components are in place. 

Ensuring the Generated Code Works 

Next, we employ Maven to compile and run the generated Spring Boot application. This step is crucial to confirm the application’s functionality and ensure it runs without issues. Once the application is up and running, we shift our focus towards using the DocGen tool. 

From Code Back to Specification with DocGen 

Transitioning to DocGen, we extract the OpenAPI specification from the running code. This round-trip exercise aims to validate the fidelity of the code-to-specification conversion. Ideally, the regenerated specification should match the original specification, thus proving the accuracy and reliability of both CodeGen and DocGen processes. 

Identifying Discrepancies and Areas for Improvement 

A critical analysis reveals notable discrepancies between the original and the regenerated specification. While comparing the two files, we can see that certain examples in the request and response have been omitted. Furthermore, a significant issue arises with the duplication of fields. In the original schema, the product is composed of product details and an ID using the allOf construct. However, the regenerated specification flattened this structure, leading to unnecessary duplication of data fields. 

Limitations and Trust Issues with CodeGen and DocGen 

The discrepancies identified during this round-trip test raise significant concerns about the reliability of CodeGen and DocGen, such fundamental mismatches erode trust in these automation tools. When a simple round trip fails to preserve the original schema’s integrity, developers may face challenges in relying on these tools for more complex API specifications. 

Conclusion: The Need for Robust Contract-Driven Development Tools 

While tools like CodeGen and DocGen offer promising automation capabilities for API development and documentation, this demonstration highlights critical areas where improvements are needed. Contract-Driven Development hinges on the accuracy and reliability of these tools to ensure seamless collaboration and communication among teams. As the industry continues to evolve, robust and trustworthy automation tools will be crucial for maximizing the benefits of microservices architecture. 

Next time you consider using CodeGen and DocGen, reflect on this case study and scrutinize whether these tools meet your standards for reliability and accuracy. Investing in comprehensive testing and validation of your API specifications can help mitigate risks and enhance the efficacy of your development processes. 

Related Posts

mcp auto test exposed mcp servers lying

By Yogesh Nikam

Exposed: MCP Servers Are Lying About Their Schemas

Table of Contents Practical Lessons from MCP Server Testing Over the last few weeks the Specmatic team ran a focused series of MCP server testing
Read More
specmatic genie mcp

By Jaydeep Kulkarni

Curate, Validate and Publish an MCP Server from an OpenAPI Spec with Specmatic Genie

In this walk-through we'll show exactly how we took the Postman APIs, curated the set of API end points we want to expose via MCP,
Read More
specmaticmcpdemo linkedin mcp

By Hari Krishnan

Specmatic MCP as guardrails for Coding Agents: API Spec to Full Stack implementation in minutes

Table of Contents In this walkthrough we'll show how to use Specmatic MCP server for API testing (Contract and Resiliency) and Mocking as a guardrail
Read More
arazzo openapi asyncapi demo with specmatic

By Hari Krishnan

Authoring & Leveraging Arazzo Spec for OpenAPI & AsyncAPI Workflow Testing

Seamlessly test both synchronous and asynchronous APIs in realistic workflows before they ever hit production! Discover how combining OpenAPI and AsyncAPI specs can simplify complex
Read More
Arazzo API workflow demo

By Hari Krishnan

Visual Workflow Mocking and Testing with Specmatic and Arazzo API Specifications

Table of Contents API workflow testing with Arazzo and Specmatic: Visual authoring, workflow mocking, and backend verification Here we'll walk through a practical approach to
Read More
Specmatic vs Microcks comparison

By Hari Krishnan

Specmatic vs Microcks

When evaluating tools for API testing and mocking, the choice often comes down to understanding not just what each tool can do, but how their
Read More
jaydeep aws lambda

By Jaydeep Kulkarni

AWS Lambda Data Pipeline Testing using LocalStack with Specmatic

Table of Contents Mastering Testing AWS Lambda Functions with LocalStack and Specmatic With fast-evolving data ecosystems, building reliable and scalable data products is essential. One
Read More
api days revised 1920x1080

By John

New features and a BIG Announcement! Specmatic is bringing apidays to India!

In the past few months, we have launched a flurry of exciting features, presented at several global conferences and onboarded several new team members. We
Read More
Speakers presenting on API Governance at tech conference.

Update: See how Specmatic is transforming API testing & development

We've been hard at work, rolling out exciting new features and sharing the power of Specmatic and Contract Driven Development around the globe! Let's explore
Read More

By Joel Rosario

Build Apps from API specs using AI: Self-Correcting Contract-Driven Agentic Workflows with Specmatic

Harnessing the Power of API Specifications for Robust Microservices  Modern microservice architecture hinges on precise and dependable communication between services. This is where API specifications
Read More