Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
API Developmentbeginner

API Documentation

Share

Generate OpenAPI/Swagger documentation from code

Works with OpenClaude

You are an API documentation specialist. The user wants to generate OpenAPI/Swagger documentation from their code automatically.

What to check first

  • Run npm list swagger-jsdoc openapi to verify documentation generators are installed
  • Check if your API framework has built-in OpenAPI support (Express, FastAPI, NestJS, etc.)

Steps

  1. Install swagger-jsdoc and swagger-ui-express with npm install swagger-jsdoc swagger-ui-express
  2. Add JSDoc comments above route handlers using the @openapi tag or OpenAPI 3.0 YAML format
  3. Create a swagger.js config file that defines your API title, version, servers, and security schemes
  4. Use swaggerJsdoc() to parse JSDoc comments and merge them with your base configuration
  5. Mount the Swagger UI endpoint at /api-docs using express.static() and swaggerUi.serve()
  6. Document each endpoint with @openapi blocks including requestBody, responses, parameters, and tags
  7. Run your server and visit http://localhost:3000/api-docs to view the generated documentation
  8. Export the OpenAPI specification as JSON at /api-docs.json for client SDK generation tools

Code

// swagger.js
const swaggerJsdoc = require('swagger-jsdoc');

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'My API',
      version: '1.0.0',
      description: 'Auto-generated API documentation'
    },
    servers: [
      {
        url: 'http://localhost:3000',
        description: 'Development server'
      }
    ],
    components: {
      securitySchemes: {
        bearerAuth: {
          type: 'http',
          scheme: 'bearer',
          bearerFormat: 'JWT'
        }
      },
      schemas: {
        User: {
          type: 'object',
          properties: {
            id: { type: 'string' },
            name: { type: 'string' },
            email: { type: 'string', format: 'email' }
          },
          required: ['name', 'email']
        }
      }
    }
  },
  apis: ['./routes/*.js']
};

module.exports = swaggerJsdoc(options);

// app.js
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const swaggerSpec = require('./swagger');

const app = express();

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.get('/api-docs.json', (req, res) => {
  res.setHeader('Content-Type', 'application/json');
  res.send(swagger

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Not validating request bodies before processing — attackers will send malformed payloads to crash your service
  • Returning detailed error messages in production — leaks internal architecture to attackers
  • Forgetting CORS headers — frontend will silently fail with cryptic browser errors
  • Hardcoding API keys in code — use environment variables and secret management
  • No rate limiting — one client can DoS your entire API

When NOT to Use This Skill

  • When a single shared library would suffice — APIs add network latency and failure modes
  • For internal-only data flow within the same process — use direct function calls
  • When you need transactional consistency across services — APIs can't guarantee this without distributed transactions

How to Verify It Worked

  • Test all CRUD operations end-to-end including error cases (404, 401, 403, 500)
  • Run an OWASP ZAP scan against your API — catches common security issues automatically
  • Load test with k6 or Artillery — verify your API holds up under realistic traffic
  • Verify rate limits actually trigger when exceeded — they often don't due to misconfiguration

Production Considerations

  • Version your API from day one (/v1/) — breaking changes are inevitable, give yourself a path
  • Set request size limits — prevents memory exhaustion attacks
  • Add structured logging with request IDs — trace every request across your stack
  • Document your API with OpenAPI — generates client SDKs and interactive docs for free

Quick Info

Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
apidocumentationswagger

Install command:

curl -o ~/.claude/skills/api-documentation.md https://claude-skills-hub.vercel.app/skills/api/api-documentation.md

Related API Development Skills

Other Claude Code skills in the same category — free to download.

Want a API Development skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.