Br write schema

From Lonsdale201/wp-agent-skills · View interactive version

Br write schema is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Configure Better Route 1.1 Resource writeSchema or payloadSchema validation for create and update payloads. Use when defining writable fields, coercion, sanitization, required and nullable values, lengths, ranges, regexes, enums, or structured fieldErrors.

How to use this skill

Skill file

Better Route Resource write schema

Use writeSchema() to validate and normalize Resource create/update payload fields. payloadSchema() is an exact alias.

Resource::make('articles')
    ->allow(['create', 'update'])
    ->fields(['id', 'title', 'status', 'priority', 'published_at'])
    ->writeSchema([
        'title' => [
            'type' => 'string',
            'required' => true,
            'sanitize' => 'text',
            'minLength' => 1,
            'maxLength' => 180,
        ],
        'status' => [
            'type' => 'enum',
            'values' => ['draft', 'published'],
        ],
        'priority' => ['type' => 'int', 'min' => 0, 'max' => 100],
        'published_at' => ['type' => 'date', 'nullable' => true],
    ]);

The enum allowlist is flat: use ['type' => 'enum', 'values' => [...]]. Do not nest values under an enum key.

Rule contract

Resource writable fields come from configured fields minus the ID field. Unknown payload keys fail with 400 validation_failed; they are not silently dropped. A field denied by fieldPolicy also fails, rather than disappearing from the write.

Validation errors use the standard error envelope with details.fieldErrors. Boolean fieldPolicy: false produces a 400 non-writable validation error; failed capabilities or policy callbacks produce 403 errors. Follow br-resource-policy for authorization.

Checks

Source reference: src/Resource/Resource.php (readPayload, coercePayloadValue, assertValueConstraints, validationError).

References

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.