Openapi

From event4u-app/agent-config · View interactive version

Openapi is an AI agent skill from the GitHub repository event4u-app/agent-config. Use when documenting APIs — OpenAPI/Swagger, PHP attributes, Redocly validation, versioned specs — even when the user just says 'document this endpoint' without naming OpenAPI.

How to use this skill

Skill file

openapi

When to use

Use this skill when adding or updating API documentation, writing OpenAPI annotations on controllers, or validating API specs.

Procedure: Add OpenAPI documentation

  1. Gather context — read agents/reference/docs/controller.md for OpenAPI patterns, agents/settings/contexts/api-versioning.md for versioning, and check 2-3 existing controllers for annotation style.
  2. Detect tooling — check composer.json for l5-swagger or laravel-openapi, look for @OA\ vs #[OA\ syntax in existing controllers, find the config file.
  3. Write annotations — add #[OA\...] attributes to the controller method. Include path, summary, tags, all parameters, and all response codes (200, 401, 403, 404, 422).
  4. Define schemas — create or reuse #[OA\Schema] for request/response types. Use $ref for shared types.
  5. Validate — run the spec validation (npx @redocly/cli lint or php artisan l5-swagger:generate). Fix any errors.
  6. Verify accuracy — compare the documented request/response with the actual controller + FormRequest + Resource to ensure they match.

OpenAPI attributes

Detection

Check the project for OpenAPI tooling:

PHP 8 attribute syntax

Modern Laravel projects use PHP 8 attributes instead of docblock annotations:

#[OA\Get(
    path: '/projects',
    summary: 'List all projects',
    tags: ['Projects'],
    parameters: [
        new OA\Parameter(
            name: 'page',
            in: 'query',
            required: false,
            schema: new OA\Schema(type: 'integer'),
        ),
    ],
    responses: [
        new OA\Response(
            response: 200,
            description: 'Successful operation',
        ),
    ],
)]
public function __invoke(ListProjectsRequest $request): ProjectCollection
{
    // ...
}

Conventions

then path: '/projects' resolves to /api/v1/projects. Never repeat the server prefix in the path.

Response documentation

Resource schemas

Define reusable schemas for API Resources:

#[OA\Schema(
    schema: 'Project',
    properties: [
        new OA\Property(property: 'id', type: 'integer'),
        new OA\Property(property: 'name', type: 'string'),
        new OA\Property(property: 'status', type: 'string', enum: ['active', 'archived']),
    ],
)]

Pagination schema

Document paginated responses with meta and links:

#[OA\Response(
    response: 200,
    description: 'Paginated list',
    content: new OA\JsonContent(
        properties: [
            new OA\Property(property: 'data', type: 'array', items: new OA\Items(ref: '#/components/schemas/Project')),
            new OA\Property(property: 'meta', ref: '#/components/schemas/PaginationMeta'),
        ],
    ),
)]

Validation with Redocly

If the project uses Redocly for OpenAPI validation:

# Validate the spec
npx @redocly/cli lint openapi.yaml

# Preview documentation
npx @redocly/cli preview-docs openapi.yaml

Check for .redocly.yaml or redocly.yaml config in the project root.

Versioned documentation

When the API uses URL-based versioning (e.g., /api/v1/, /api/v2/):

Output format

  1. OpenAPI annotations as PHP attributes on controllers/models
  2. Spec validation passing via Redocly

Auto-trigger keywords

Gotcha

Do NOT

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.