OpenAPI & Swagger: Creating Clear API Specifications with YAML

Islam NabiyevIslam Nabiyev
5 min read

In modern software development, clear API specifications are essential. Without them, developers guess, testers struggle, and integrations break. That’s why industry standards like OpenAPI and tools like Swagger are crucial—they help define, document, and communicate how APIs work in a clear, structured, and testable format.

As a Business or System Analyst, learning how to read and write API specifications in YAML using OpenAPI empowers you to create alignment between business goals, technical implementation, and QA verification.

This article walks you through OpenAPI, Swagger tools, YAML structure, and how these fit into API design workflows like Code-First and Design-First.


🧾 What Is OpenAPI?

OpenAPI Specification (OAS) is a standardized way to describe RESTful APIs. It defines:

  • What endpoints an API exposes

  • What input (parameters) and output (responses) each endpoint expects

  • The format of the data (schemas)

  • Authentication requirements

It is written in YAML or JSON—with YAML being more human-readable and preferred for documentation purposes.


🤝 What Is Swagger?

Swagger is a set of open-source tools built around the OpenAPI specification. It allows developers, analysts, and testers to work with APIs using a common, visual, and interactive interface.

Swagger Tools:

ToolPurpose
Swagger EditorWrite and validate OpenAPI specs in YAML
Swagger UIRender OpenAPI specs as live API documentation
Swagger CodegenAuto-generate client/server code from specs

OpenAPI is the standard.
🛠 Swagger is the toolkit that helps you use it effectively.


📄 OpenAPI YAML: Structure & Example

Here’s a minimal OpenAPI spec written in YAML:

yamlCopyEditopenapi: 3.0.0
info:
  title: User API
  version: 1.0.0

paths:
  /users/{id}:
    get:
      summary: Get a user by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                  name:
                    type: string

🔍 Key Components of an API Spec

ElementPurpose
openapiSpecifies version of the OpenAPI format
infoMetadata: title, version, description
pathsDefines each API endpoint and method (GET, POST, etc.)
parametersInput fields like query/path/header/body
responsesExpected outputs for each status code (200, 404, etc.)
schemaStructure and data types of the response body

These are mandatory building blocks of every OpenAPI definition.


🏗 Code-First vs Design-First Approaches

There are two main strategies teams use to define and build APIs:

🔹 Code-First (Traditional Developer-Led)

  • Developers write backend logic first

  • API documentation (OpenAPI) is generated after coding using annotations or tools

🔹 Design-First (API-First Approach)

  • Analysts or architects define the API in YAML before any code is written

  • Developers build the API based on this shared contract

  • QA and frontend teams use the spec from day one

🎯 Analysts play a key role in Design-First projects by defining endpoints, fields, and rules using OpenAPI before handoff.


📌 Why YAML?

YAML (Yet Another Markup Language) is:

  • Easier to read and write than JSON

  • Cleaner syntax (no brackets or commas)

  • Ideal for human-authored API specifications

YAML Example vs JSON:

YAML:

yamlCopyEditname: Islam
email: islam@example.com

JSON:

jsonCopyEdit{
  "name": "Islam",
  "email": "islam@example.com"
}

🧩 Swagger vs Postman: What’s the Difference?

FeatureSwaggerPostman
PurposeAPI specification, design, documentationAPI testing, debugging, and simulation
Format SupportOpenAPI YAML/JSONREST, SOAP, GraphQL, OpenAPI (import)
FocusAPI design and lifecycleHands-on testing and collection management
Key UsersAnalysts, architects, developersAnalysts, QA, developers

Use Swagger to define the API.
Use Postman to test and explore the API.


🧠 Benefits for Analysts

  • Define API behavior clearly (no misinterpretation)

  • Align business rules with technical fields and responses

  • Create specs that dev, QA, and product all understand

  • Help ensure compliance, versioning, and documentation best practices


🛠 Tools You Can Use

ToolPurpose
Swagger EditorWrite and preview OpenAPI specs in YAML
Swagger UITurn specs into interactive documentation
RedoclyAdvanced rendering of OpenAPI docs
StoplightVisual API design and governance
PostmanImport OpenAPI to auto-generate requests

🛠 Create a POST API Spec Example

yamlCopyEditpaths:
  /users:
    post:
      summary: Create a new user
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - email
              properties:
                name:
                  type: string
                email:
                  type: string
      responses:
        '201':
          description: User created successfully

This defines:

  • A POST method to create users

  • Two required fields: name and email

  • A success response: 201 Created


🧑‍💻 Can You Create YAML Files?

Yes. With the knowledge from this article:

  • You can read OpenAPI specs written in YAML

  • You can create or edit basic endpoint definitions

  • You can validate YAML in tools like editor.swagger.io


🧠 Final Thoughts

OpenAPI and Swagger bring structure, clarity, and automation to the API lifecycle. As an analyst, learning to work with these tools and write YAML specifications gives you the power to:

  • Define API requirements precisely

  • Improve collaboration with dev and QA teams

  • Build scalable, testable, and documented systems from day one

Start with Swagger Editor. Learn YAML basics. Own the API conversation.

0
Subscribe to my newsletter

Read articles from Islam Nabiyev directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Islam Nabiyev
Islam Nabiyev