API Spec — Tạo OpenAPI Specification

Tự động generate OpenAPI (Swagger) specification cho API endpoints từ code hiện có hoặc feature description.

Cú pháp

/api-spec                          # Generate từ codebase hiện tại
/api-spec "payment API endpoints"  # Generate từ description

Luồng hoạt động

1

Bước 1: Scan API routes

Đọc controllers/routes, extract endpoints, methods, parameters.
2

Bước 2: Analyze schemas

Đọc DTOs, Zod schemas, Prisma models → generate request/response schemas.
3

Bước 3: Generate OpenAPI

Tạo OpenAPI 3.0 spec: paths, schemas, authentication, examples.
4

Bước 4: Validate

Validate spec syntax, check completeness.

Ví dụ thực tế

# Generated: docs/api/openapi.yaml
openapi: 3.0.0
info:
  title: PrimeCommerce API
  version: 1.0.0
paths:
  /api/v1/products:
    get:
      summary: List products
      parameters:
        - name: page
          in: query
          schema: { type: integer, default: 1 }
        - name: limit
          in: query
          schema: { type: integer, default: 20 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProductList'

Khi nào dùng / không dùng

DùngKhông dùng
Sau khi viết API endpointsFrontend-only project
Cần share API spec với frontend teamInternal utility functions
Tạo Swagger docs cho external APIKhi API chưa implement