DEV Community

Cover image for The Good, the Bad, and the OpenAPI: Why Developers Love and Hate It
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on

The Good, the Bad, and the OpenAPI: Why Developers Love and Hate It

According to SmartBear, the parent company of Swagger:

"The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection."

To put it simply, OpenAPI provides a structured way to describe RESTful APIs, enabling better documentation, automation, and interoperability across different platforms and programming languages.

Why Use OpenAPI?

OpenAPI has become the industry standard for describing RESTful APIs. Here’s why:

Portability: It’s language-agnostic, making it compatible with systems written in different programming languages.

Robust Tooling: Tools like Swagger, Postman, and Redoc leverage OpenAPI to generate documentation, mock servers, and client SDKs.

While alternatives like RAML and API Blueprint exist, OpenAPI’s widespread adoption and comprehensive tooling make it the go-to choice for most developers.

The Ugly Side of OpenAPI

While OpenAPI aims to simplify API documentation, it often feels like a burden. The biggest pain points include:

  1. Tedious Manual Work – Every API requires explicit definitions, meaning developers have to manually annotate or describe each endpoint, input, and response.
  2. Poor UI/UX – OpenAPI-generated documentation tools like Swagger UI are functional but often lack an intuitive experience.
  3. Decorator Overload – In frameworks like NestJS, defining OpenAPI specs requires adding multiple decorators to each endpoint and DTO.
  4. Output File Complexity – The resulting OpenAPI JSON or YAML file can be massive and hard to manage.

Image description

In Action: A NestJS Example

Let’s take a look at a simple API endpoint in NestJS. To define it properly with OpenAPI, we need to manually annotate the controller and DTOs:

Step 1: Install Dependencies

npm install --save @nestjs/swagger swagger-ui-express
Enter fullscreen mode Exit fullscreen mode

Step 2: Enable OpenAPI in Your Application

Modify your main.ts file to configure Swagger documentation.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .setTitle('NestJS API')
    .setDescription('API documentation for NestJS application')
    .setVersion('1.0')
    .addBearerAuth()
    .build();

  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, document);

  await app.listen(3000);
}
bootstrap();
Enter fullscreen mode Exit fullscreen mode

Step 3: Annotate Your Controllers:

NestJS uses decorators to define API metadata. Example:

Creating a DTO:
import { ApiProperty } from '@nestjs/swagger';

export class SampleResponseDto {
  @ApiProperty({ example: 'Data for ID: 123' })
  message: string;
}
Enter fullscreen mode Exit fullscreen mode
Updating a Controller
import { Controller, Get, Query } from '@nestjs/common';
import { ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
import { SampleResponseDto } from './dto/sample-response.dto';

@ApiTags('Sample')
@Controller('sample')
export class SampleController {
  @Get()
  @ApiQuery({ name: 'id', type: String, required: true })
  @ApiResponse({ status: 200, type: SampleResponseDto })
  async getSample(@Query('id') id: string): Promise<SampleResponseDto> {
    return { message: `Data for ID: ${id}` };
  }
}
Enter fullscreen mode Exit fullscreen mode

Step 4: Running the Application

Start the NestJS application:

npm run start
Enter fullscreen mode Exit fullscreen mode

Navigate to http://localhost:3000/api to see the auto-generated Swagger UI documentation.

Now, after running the application, we generate an OpenAPI JSON file:

Output OpenAPI JSON:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Sample API",
    "version": "1.0.0"
  },
  "paths": {
    "/sample": {
      "get": {
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

OpenAPI Components Breakdown

Paths and Endpoints

Each API endpoint is defined with HTTP methods (GET, POST, PUT, DELETE) under the paths section.

Request and Response Models

Schemas define the structure of request and response bodies.

Parameters

API parameters include path, query, header, and body parameters, defined with types and validation rules.

Response Codes

Responses use standard HTTP codes like 200 OK, 400 Bad Request, and 500 Internal Server Error.

Security

Security mechanisms like API keys, OAuth2, and JWT authentication are supported.

The Problem: Too Much Manual Work

  • Each API requires multiple annotations.
  • Input and output types must be explicitly defined.
  • The OpenAPI file is still complex and hard to read.
  • Making changes requires modifying multiple places.

Image description

Looking for a Simpler Way?

I'm working on a product called LiveAPI to make your life easier!

What if you could skip all the manual work of creating OpenAPI specs—no decorators, no JSON parsing, no headaches?

That’s exactly what LiveAPI does for you.

It automatically extracts your API definitions, handles types, and generates clean, complete OpenAPI specs in just a few minutes.

With LiveAPI, you can:

  • Say goodbye to manual annotations and decorators
  • Get fully automated, interactive API documentation
  • Let users test APIs directly from the browser

Image description

If you’re tired of spending hours documenting APIs, LiveAPI is here to make your life easier.

Give it a try at hexmos.com/LiveAPI and see how effortless API documentation can be!

Top comments (2)

Collapse
 
dansasser profile image
Daniel T Sasser II

Hey, that's Sweet Brown from right here in Oklahoma City.!
Ain't nobody got time for that 😆

Collapse
 
lovestaco profile image
Athreya aka Maneshwar

Hehehe 💯