Problem: Spreadsheets. Solution: Specifications
Tags: productivity, openapi, postman, schema
Published: 2021-05-10 13:47:34

This is a story inspired by true events, about a team and the everyday struggles they faced while building an API defined by spreadsheets and documents. What can come to the rescue in such a scenario? API specifications.
<h2>In analysis</h2>
<figure><img class="wp-image-11573" src="https://blog.postman.com/wp-content/uploads/2021/04/image1-1.png" alt="A business analyst and a developer may have different objectives and perspectives" width="600" height="373" /><figcaption>A business analyst and a developer may have different objectives and perspectives</figcaption></figure>

Here’s an example of a conversation that you may have been part of sometime in your life as a developer.

<b>Business Analyst</b>: Our next user story involves creating an API (let’s call it “Customer API”).
<b>Developer A</b>: How novel! That’s what I did yesterday and the day before and the day before that.
<b>Business Analyst</b>: Great, should I let the clients know that it wouldn’t take as long to build it?
<b>Developer A</b>: Hold on. We haven’t even heard the requirements for Customer API.
<b>Business Analyst</b>: It’s just a couple of hundred fields that Customer API needs to send to another downstream API to perform the transaction.
<b>Developer A</b>: And how will we know the values for these fields that Customer API needs to send?
<b>Business Analyst</b>: I’ll take care of it. I have already spoken to the lead developer from the downstream API team, and he’s sent me a spreadsheet. It has all the fields and the values that need to be part of the request body. He’s also sent me a document with information on the headers and auth details required to call the downstream API.
<b>Developer A</b>: Is this downstream API available in a testing environment? A playground, maybe?
<b>Business Analyst</b>: They’re still working on building the downstream API, so they don’t have a working version yet.
<h2>In development</h2>
Developer A gets to work. She pairs with Developer B, another application developer on her team, to finish the Customer API story. Business Analyst sends them an email with a spreadsheet containing the fields and a document that includes the API currently in development by the downstream API team. It seems like Developer A and Developer B have all the information required to start building the Customer API, so they come up with the following list of tasks:
<ol>
 	<li aria-level="1">Create the Customer Request model that has all the fields from the spreadsheet.</li>
 	<li aria-level="1">Fill the model with default values.</li>
 	<li aria-level="1">Build the Customer API that will use this model as part of the request body.</li>
</ol>
Seems straightforward. That’s what Developer A and Developer B felt too. Let's see what happened.
<h2>In the soup</h2>
When Developer A and Developer B scanned the spreadsheet, it didn’t have a hundred fields (as Business Analyst said) but 300 fields. Did that slow them down? Yes, it did.

Let’s look at some of the challenges they faced and what they did.

<b>How did Developer A and Developer B convert fields from the spreadsheet to data members of a class?</b>

Developer B started by showing off some editing skills in his favorite integrated development environment (IDE). To be fair, he recently acquired these skills from another developer last week. Now was his chance to shine. He simply showed Developer A how to paste the fields from the spreadsheet to the class file and some shortcuts on the IDE to clean the copy/paste bit and replace it with Kotlin (the language they used) syntax for a class.

<b>How did they assign the values to the fields? </b>

Not all fields had default values, so assigning defaults to specific fields became a manual process for them, which of course took a while and some patience to complete.

<b>Why are we saying they were in the soup?</b>

Because here’s what happened over the course of the project. Integration failed due to:
<ul>
 	<li aria-level="1">Incorrectly spelled fields</li>
 	<li aria-level="1">Case sensitive fields</li>
 	<li aria-level="1">Mismatched data types: Some fields were represented as Boolean when they were actually Strings</li>
 	<li aria-level="1">Error parsing issues, since the document misrepresented it</li>
 	<li aria-level="1">Missing responses (200 OK even) for some paths</li>
</ul>
<figure><img class="wp-image-11574 size-full" src="https://blog.postman.com/wp-content/uploads/2021/04/image2.png" alt="A developer can feel in the soup due to integration failure" width="492" height="447" /><figcaption>A developer can feel in the soup due to integration failure</figcaption></figure>
<h2>In retrospect</h2>
I relate to the character of Developer A in this scenario so much, because these are issues that my team has faced. For us, the problems kept popping up frequently, and the integration took a couple of months. I always wondered if there was a better way to communicate—or a process to spend less time on—the issues we faced. Fast-forward to today, and I am glad to report that I’m now fairly acquainted with API specifications.
<h2>What are API specifications, and why use them?</h2>
A spreadsheet (or a doc) may be tempting to use because it doesn’t come with a lot of rules, but a specification has the same benefit plus more. Here are a few reasons why I’ve become an advocate of specifications (like the <a href="https://blog.postman.com/openapi-specification-postman-how-to/">OpenAPI Specification</a>):
<h3>Conformance to a format</h3>
Specifications have a format, and the format could be JSON/YAML, which is much closer to an API than plain text. Examples of APIs and their formats:
<ul>
 	<li aria-level="1"><a href="https://www.postman.com/twilio/workspace/twilio-api/api/d4f6010f-a731-4741-bcff-fd88640a9036?version=03c17ae1-c0ed-4a51-8763-67a858cda324&amp;tab=overview">Twilio Messaging API</a>: Defined in JSON format</li>
 	<li aria-level="1"><a href="https://www.postman.com/postman/workspace/postman-public-workspace/api/f00b3236-8241-43ce-925f-80f6f73f8ffc?version=26b1363e-2b53-4ec3-85b2-21ae480c86fe&amp;tab=overview">Postman API</a>: Defined in YAML format</li>
</ul>
<h3>Schema objects</h3>
<a href="https://spec.openapis.org/oas/v3.1.0#schema-object">Schema objects</a> can be defined, and that would resolve the error response parsing issues we faced earlier. Below is an example of a defined schema object.

In the <a href="https://www.postman.com/dolbyio/workspace/dolby-io-public-workspace/api/1836eb91-6406-4783-a683-ed7d7685560b?version=475ae55d-7eb0-4609-b6cd-96c9ece9002b&amp;tab=define">Dolby Media Analyze OpenAPI</a>, <code>RequestError</code> is a schema object defined as follows:
<pre>RequestError:     
     type: object     
     properties:       
       type:         
         description: A URL that uniquely identifies the problem type.         
         type: string         
         example: "/problem/validation-error"       
     title:         
       description: A human readable description of the error.         
       type: string         
       example: "Your request parameters didn't validate"       
     status:         
       description: The HTTP response code.         
       type: number         
       example: 400       
     instance:         
       description: The URL of the call for which the error occurred.         
       type: string         
       example: "/media/analyze"       
     detail:         
       description: An optional field with more information depending on the type.         
       type: string         
       example: "job_id is required"</pre>
<h3>Schema validations</h3>
Validations on the specification ensure that at least one successful response is defined for a path. In addition, there are a lot of other validations on the schema.

<figure><img class="wp-image-11575 size-large" src="https://blog.postman.com/wp-content/uploads/2021/04/image3-1-1024x512.png" alt="Discourse API (Validation Errors Example) demonstrating validation errors" width="640" height="320" /><figcaption>Discourse API (Validation Errors Example) demonstrating validation errors</figcaption></figure>

The above screenshot displays validation errors found in the schema. Dive right into the <a href="https://www.postman.com/postman/workspace/postman-blog/api/20e74ed8-66d2-497d-ba01-db5360c0131d?version=9a08a555-2fdc-4a06-bc77-45e120f9960b&amp;tab=define">Discourse API (Validation Errors Example)</a> to learn more.
<h3>Tooling</h3>
Specifications are supported by extensive <a href="https://openapi.tools/">tooling</a>—like code generators, mock servers, documentation, etc. Leverage the tooling available in Postman by following the detailed walkthrough <a href="https://learning.postman.com/docs/designing-and-developing-your-api/the-api-workflow/#developing-an-api">here</a>.
<h2>Helpful API blueprints</h2>
API specifications are a blueprint for APIs, providing a huge help by describing the structure of the API. Read Postman Chief Evangelist <a href="https://blog.postman.com/author/kinlane/">Kin Lane</a>’s <a href="https://apievangelist.com/2020/11/23/a-high-level-look-at-api-specifications/">blog post</a> to get a high-level view of API specifications currently available.

> Spreadsheets served us well in the information age, but as enterprise organizations wrestle with their digital transformation, they are realizing they need a much more precise set of human- and machine-readable tools that can track the exponentially increasing data being produced each day. Specifications now help teams keep up with the perpetual pace of change and remain competitive in today’s ever-evolving and shifting digital landscape.
— *Postman Chief Evangelist Kin Lane*

To get started, you can define the API schema in Postman using the <a href="https://learning.postman.com/docs/designing-and-developing-your-api/the-api-workflow/">API Builder</a>. Share your experiences with and without specifications, and then give us your feedback by leaving a comment below.

&nbsp;