Api contract

From weisser-dev/awesome-opencode · View interactive version

Api contract is an AI agent skill from the GitHub repository weisser-dev/awesome-opencode. Generate or validate OpenAPI and AsyncAPI specs from code or requirements with consistent naming, errors, and pagination

How to use this skill

Skill file

What I do

When to use me

Use this skill when you need to:

Process

  1. Discover: Analyze existing API code or requirements
  1. Design resource model: Map domain entities to API resources
  1. Define endpoints: Specify each operation
  1. Standardize patterns: Apply consistent conventions
  1. Generate spec: Produce the OpenAPI/AsyncAPI document
  1. Validate: Check spec for completeness and correctness

Naming Conventions

| Element | Convention | Example |

|---------|-----------|---------|

| Paths | kebab-case, plural nouns | /api/v1/user-accounts |

| Query params | camelCase | ?pageSize=20&sortBy=createdAt |

| Request/response fields | camelCase | { "firstName": "Jane" } |

| Schema names | PascalCase | UserAccount, OrderItem |

| Enum values | UPPER_SNAKE_CASE | "ORDER_PENDING" |

Standard Error Format

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Human-readable description",
    "details": [
      {
        "field": "email",
        "message": "Must be a valid email address",
        "code": "INVALID_FORMAT"
      }
    ],
    "requestId": "req_abc123"
  }
}

HTTP Status Code Usage

| Code | Usage |

|------|-------|

| 200 | Successful GET, PUT, PATCH |

| 201 | Successful POST that creates a resource |

| 204 | Successful DELETE with no response body |

| 400 | Validation error or malformed request |

| 401 | Missing or invalid authentication |

| 403 | Authenticated but insufficient permissions |

| 404 | Resource not found |

| 409 | Conflict (duplicate, state violation) |

| 422 | Semantically invalid request |

| 429 | Rate limit exceeded |

| 500 | Unexpected server error |

Pagination Pattern

# Query parameters
parameters:
  - name: page
    in: query
    schema:
      type: integer
      minimum: 1
      default: 1
  - name: pageSize
    in: query
    schema:
      type: integer
      minimum: 1
      maximum: 100
      default: 20

# Response envelope
PagedResponse:
  type: object
  properties:
    data:
      type: array
      items: { $ref: '#/components/schemas/Item' }
    pagination:
      type: object
      properties:
        page: { type: integer }
        pageSize: { type: integer }
        totalItems: { type: integer }
        totalPages: { type: integer }

Validation Checklist

Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.