Skip to content

OpenAPI Specification — The Industry Standard for REST API Documentation

DodaTech Updated 2026-06-28 2 min read

In this tutorial, you will learn about OpenAPI Specification. We cover key concepts, practical examples, and best practices to help you master this topic.

The OpenAPI Specification is a vendor-neutral, machine-readable format for describing REST APIs that enables automated documentation, client generation, and testing.

What You'll Learn

  • OpenAPI file structure and key sections
  • Writing OpenAPI specs in YAML
  • Generating documentation from OpenAPI

Why It Matters

OpenAPI is the industry standard. Tools like Swagger UI, Redoc, and Postman all read OpenAPI specs. Learning OpenAPI unlocks the entire API documentation ecosystem.

Code Examples

# Basic OpenAPI 3.0 specification
openapi: "3.0.3"
info:
  title: Durga Threat Intelligence API
  description: API for querying threat intelligence data
  version: "1.0.0"
  contact:
    name: DodaTech API Support
    email: api@dodatech.com

servers:
  - url: https://api.durga-antivirus.com/v1
    description: Production server

paths:
  /threats:
    get:
      summary: List known threats
      parameters:
        - name: severity
          in: query
          schema:
            type: string
            enum: [low, medium, high, critical]
      responses:
        "200":
          description: List of threats
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Threat"
# Reading OpenAPI spec programmatically
import yaml

with open("openapi.yaml") as f:
    spec = yaml.safe_load(f)

print(f"API: {spec['info']['title']} v{spec['info']['version']}")
for path, methods in spec['paths'].items():
    for method in methods:
        print(f"  {method.upper()} {path}")

Common Mistakes

1. Not Specifying Response Content Types

Always declare what content types each endpoint returns.

2. Missing Error Response Definitions

Define all error responses (400, 401, 404, 500) for every endpoint.

3. Inconsistent Parameter Naming

Use consistent snake_case or camelCase across all parameters.

4. No Security Scheme Definition

Define how authentication works in the components/securitySchemes section.

5. Overly Complex Spec Files

Break large specs into multiple files using $ref for organization.

Practice Questions

  1. What format does OpenAPI use?
  2. What are the four main sections of an OpenAPI spec?
  3. How does OpenAPI handle data type definitions?
  4. What is the purpose of the servers section?
  5. How can you organize a large OpenAPI spec?

Answers:

  1. YAML or JSON.
  2. info, servers, paths, components.
  3. Through components/schemas with $ref references.
  4. To specify the base URLs for different environments.
  5. Use multiple files with $ref to reference external schema files.

Challenge: Write an OpenAPI 3.0 spec for a simple note-taking API with create, read, update, and delete operations for notes.

FAQ

What is the difference between OpenAPI 2.0 and 3.0?

: OpenAPI 3.0 adds better support for request bodies, callbacks, links, and server variables.

Is OpenAPI only for REST APIs?

: Primarily, but it can describe other HTTP-based APIs.

Can I convert between OpenAPI and other formats?

: Yes. Tools exist for RAML and API Blueprint conversion.

What's Next

Learn about OpenAPI Structure (info, paths, components), then explore OpenAPI Paths.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro