Skip to content

Latest commit

Β 

History

History
676 lines (564 loc) Β· 11.7 KB

File metadata and controls

676 lines (564 loc) Β· 11.7 KB

OpenAPI Quick Reference Guide

A quick reference for understanding and maintaining the Dialgen OpenAPI specification.

πŸ“‹ Table of Contents

πŸ“ File Structure

dialgen-docs/
β”œβ”€β”€ openapi.json              # Main OpenAPI 3.0 specification
β”œβ”€β”€ docs.json                 # Mintlify configuration (references openapi.json)
└── api-reference/
    └── introduction.mdx      # API introduction page

πŸ”§ OpenAPI Specification Sections

1. Info Section

{
  "openapi": "3.0.3",
  "info": {
    "title": "Dialgen API",
    "description": "API description",
    "version": "1.0.0",
    "contact": {
      "name": "Dialgen Support",
      "url": "https://sa.dialgen.ai"
    }
  }
}

2. Servers Section

{
  "servers": [
    {
      "url": "https://sa.dialgen.ai",
      "description": "Production server"
    }
  ]
}

3. Security Section

{
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Bearer token authentication"
      }
    }
  }
}

4. Paths Section

Defines all API endpoints:

{
  "paths": {
    "/api/v1/endpoint": {
      "get": {
        "summary": "Endpoint summary",
        "description": "Detailed description",
        "operationId": "uniqueOperationId",
        "tags": ["Category"],
        "parameters": [...],
        "responses": {...}
      }
    }
  }
}

5. Components Section

Reusable schemas, responses, and parameters:

{
  "components": {
    "schemas": {
      "SchemaName": {...}
    },
    "responses": {
      "ResponseName": {...}
    },
    "parameters": {
      "ParameterName": {...}
    }
  }
}

πŸ› οΈ Common Tasks

Adding a New Endpoint

  1. Add to paths section:
{
  "paths": {
    "/api/v1/new-endpoint": {
      "post": {
        "summary": "New Endpoint",
        "description": "Description here",
        "operationId": "newEndpoint",
        "tags": ["Category"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NewResponse"
                }
              }
            }
          }
        }
      }
    }
  }
}
  1. Add schemas:
{
  "components": {
    "schemas": {
      "NewRequest": {
        "type": "object",
        "required": ["field1"],
        "properties": {
          "field1": {
            "type": "string",
            "description": "Field description"
          }
        }
      },
      "NewResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
  1. Update docs.json navigation:
{
  "navigation": {
    "tabs": [
      {
        "tab": "API Reference",
        "groups": [
          {
            "group": "Category",
            "pages": [
              "POST /api/v1/new-endpoint"
            ]
          }
        ]
      }
    ]
  }
}

Adding Query Parameters

{
  "parameters": [
    {
      "name": "paramName",
      "in": "query",
      "description": "Parameter description",
      "required": true,
      "schema": {
        "type": "string",
        "example": "example-value"
      }
    }
  ]
}

Adding Request Body

{
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/RequestSchema"
        },
        "example": {
          "field": "value"
        }
      }
    }
  }
}

Adding Response

{
  "responses": {
    "200": {
      "description": "Success description",
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/ResponseSchema"
          },
          "example": {
            "success": true,
            "data": {}
          }
        }
      }
    }
  }
}

πŸ“Š Schema Patterns

Basic Object Schema

{
  "SchemaName": {
    "type": "object",
    "required": ["field1", "field2"],
    "properties": {
      "field1": {
        "type": "string",
        "description": "Field description"
      },
      "field2": {
        "type": "number",
        "minimum": 0,
        "maximum": 100
      }
    }
  }
}

Array Schema

{
  "ArraySchema": {
    "type": "array",
    "items": {
      "$ref": "#/components/schemas/ItemSchema"
    },
    "minItems": 1,
    "maxItems": 100
  }
}

Enum Schema

{
  "StatusSchema": {
    "type": "string",
    "enum": ["PENDING", "PROCESSING", "COMPLETED", "FAILED"],
    "description": "Status of the operation"
  }
}

Nested Object Schema

{
  "ParentSchema": {
    "type": "object",
    "properties": {
      "childObject": {
        "type": "object",
        "properties": {
          "nestedField": {
            "type": "string"
          }
        }
      }
    }
  }
}

Schema with Reference

{
  "ComplexSchema": {
    "type": "object",
    "properties": {
      "simpleField": {
        "type": "string"
      },
      "referencedField": {
        "$ref": "#/components/schemas/OtherSchema"
      }
    }
  }
}

Nullable Fields

{
  "NullableSchema": {
    "type": "object",
    "properties": {
      "optionalField": {
        "type": "string",
        "nullable": true,
        "description": "Can be null"
      }
    }
  }
}

Additional Properties

{
  "FlexibleSchema": {
    "type": "object",
    "properties": {
      "knownField": {
        "type": "string"
      }
    },
    "additionalProperties": true
  }
}

🎯 Response Codes

Standard Response Codes Used in Dialgen API

Code Name Usage
200 OK Successful GET request
202 Accepted Async operation accepted (batches)
400 Bad Request Invalid parameters or body
401 Unauthorized Missing/invalid API key
402 Payment Required Insufficient credits
403 Forbidden Access denied
404 Not Found Resource not found
409 Conflict Resource conflict (duplicate call)
500 Internal Server Error Server error

Response Template

{
  "responses": {
    "200": {
      "description": "Success",
      "content": {
        "application/json": {
          "schema": {...}
        }
      }
    },
    "400": {
      "$ref": "#/components/responses/BadRequest"
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    },
    "404": {
      "$ref": "#/components/responses/NotFound"
    },
    "500": {
      "$ref": "#/components/responses/InternalServerError"
    }
  }
}

βœ… Validation

Using Swagger Editor

  1. Visit https://editor.swagger.io/
  2. Copy openapi.json contents
  3. Paste into editor
  4. Check for errors in right panel

Using Mint CLI

# Install Mintlify CLI
npm i -g mintlify

# Validate OpenAPI spec
mintlify openapi-check openapi.json

Common Validation Errors

Missing operationId

// ❌ Wrong
{
  "get": {
    "summary": "Get Data"
  }
}

// βœ… Correct
{
  "get": {
    "summary": "Get Data",
    "operationId": "getData"
  }
}

Invalid $ref

// ❌ Wrong
{
  "$ref": "#/components/schemas/NonExistentSchema"
}

// βœ… Correct
{
  "$ref": "#/components/schemas/ExistingSchema"
}

Missing required fields

// ❌ Wrong
{
  "type": "object",
  "required": ["field1"],
  "properties": {
    "field2": {
      "type": "string"
    }
  }
}

// βœ… Correct
{
  "type": "object",
  "required": ["field1"],
  "properties": {
    "field1": {
      "type": "string"
    }
  }
}

πŸ” Finding Information

Find all endpoints with a specific tag

Search for "tags": ["TagName"] in the paths section.

Find all schemas

Look in components.schemas section.

Find all error responses

Look in components.responses section.

Find authentication details

Look in components.securitySchemes section.

πŸ“ Best Practices

1. Naming Conventions

  • operationId: camelCase (e.g., getAgent, createBatch)
  • Schema names: PascalCase (e.g., Agent, CallStatus)
  • Properties: camelCase (e.g., agentId, phoneNumber)

2. Descriptions

  • Always include descriptions for schemas and properties
  • Use clear, concise language
  • Include examples where helpful

3. Examples

  • Provide realistic examples
  • Include all required fields
  • Show common use cases

4. Reusability

  • Use $ref for repeated schemas
  • Create reusable response templates
  • Define common parameters once

5. Versioning

  • Include version in info section
  • Document breaking changes
  • Maintain backward compatibility when possible

πŸš€ Quick Commands

Start development server

cd dialgen-docs
mintlify dev

Validate OpenAPI spec

mintlify openapi-check openapi.json

Format JSON

# Using jq (if installed)
jq . openapi.json > openapi.formatted.json

Search for specific endpoint

# Using grep (Git Bash or WSL)
grep -A 5 "/api/v1/agent" openapi.json

πŸ“š Resources

πŸŽ“ Learning Path

  1. Understand OpenAPI basics

    • Read OpenAPI specification
    • Explore example APIs
  2. Study the Dialgen spec

    • Review openapi.json
    • Understand schema structure
  3. Make small changes

    • Update descriptions
    • Add examples
  4. Add new endpoints

    • Follow existing patterns
    • Validate changes
  5. Advanced features

    • Complex schemas
    • Custom responses
    • Webhooks

πŸ’‘ Tips

  • Always validate after making changes
  • Use consistent formatting (2-space indentation)
  • Keep examples up to date
  • Document all required fields
  • Use meaningful operationIds
  • Group related endpoints with tags
  • Reuse schemas when possible
  • Include error responses for all endpoints

πŸ†˜ Troubleshooting

Endpoint not appearing in docs

  1. Check OpenAPI spec is referenced in docs.json
  2. Verify endpoint path in navigation matches OpenAPI
  3. Validate OpenAPI spec for errors
  4. Clear browser cache and restart dev server

Schema not rendering correctly

  1. Check for syntax errors in schema definition
  2. Verify all $ref paths are correct
  3. Ensure required fields exist in properties
  4. Validate with Swagger Editor

Examples not showing

  1. Add example to schema or response
  2. Check JSON syntax is valid
  3. Ensure example matches schema structure

πŸ“Š Dialgen API Statistics

  • Total Endpoints: 11
  • GET Endpoints: 6
  • POST Endpoints: 5
  • Schemas: 20+
  • Tags: 3 (Agents, Calls, Batches)
  • Response Codes: 8 (200, 202, 400, 401, 402, 403, 404, 409, 500)

🎯 Summary

This quick reference provides:

  • βœ… Common OpenAPI patterns
  • βœ… Schema examples
  • βœ… Validation methods
  • βœ… Best practices
  • βœ… Troubleshooting tips
  • βœ… Quick commands

Use this guide as a reference when working with the Dialgen OpenAPI specification.