custom-validator skill
Symfony 제약 조건 또는 Laravel 유효성 검사 규칙을 사용하여 API Platform 리소스용 커스텀 유효성 검사 제약 조건을 생성합니다.
- GitHub 스타
- 29
- 파일
- 1
- 마지막 커밋
- 2026년 10월 22일
- 라이선스
- —
- 허용된 도구
- —
custom-validator skill은 무엇을 하나요?
custom-validator은(는) agent skill입니다. Symfony 제약 조건 또는 Laravel 유효성 검사 규칙을 사용하여 API Platform 리소스용 커스텀 유효성 검사 제약 조건을 생성합니다.
skill의 SKILL.md에서 생성된 요약입니다.
custom-validator skill 정보
이 SKILL은 백엔드 개발자가 API Platform 리소스에 대한 복잡한 비즈니스 로직을 개발할 수 있도록 지원합니다. 표준 Symfony 또는 Laravel 규칙만으로는 특정 요구 사항을 충족하기 부족할 때, 커스텀 유효성 검사 제약 조건을 구현하는 데 필요한 패턴을 제공합니다. 사용자가 도메인 특화 형식을 강제하거나, 고유성을 확인하거나, 쓰기 작업 중에 속도 및 플랜 제한을 구현해야 하는 경우 에이전트가 이 SKILL을 로드해야 합니다.
Symfony 기반 프로젝트의 경우, 이 SKILL은 계정 한도 확인과 같은 로직을 처리하기 위해 Constraint 클래스와 그에 대응하는 ConstraintValidator 클래스를 생성하는 방법을 보여줍니다. 또한 다중 필드 유효성 검사를 위한 클래스 수준 제약 조건과 DTO를 위한 콜백 유효성 검사도 다룹니다. Laravel 환경에서는 ApiResource 어트리뷰트 내에서 rules 옵션을 사용하는 데 중점을 두며, 배열, 클로저 또는 FormRequest 클래스 문자열을 지원합니다. 이를 통해 커스텀 비즈니스 규칙이 422 ConstraintViolationList 응답을 정확하게 반환하도록 보장합니다.
agent가 수행할 수 있는 작업
- 1플랜 기반 계정 한도 강제사용자의 현재 구독 플랜에 따라 특정 계정 수를 초과하지 못하도록 하는 유효성 검사기를 생성합니다.
skill의 SKILL.md를 기반으로 작성되었습니다. 모든 사용 사례는 해당 문서의 인용구와 대조 확인되었습니다.
custom-validator skill 설치 방법
각 명령은 skill 폴더를 클라이언트의 skills 디렉터리에 복사합니다. 클라이언트를 재시작하거나 새 세션을 시작하여 로드하세요.플러그인에 custom-validator skill 설치
/plugin marketplace add api-platform/skillset /plugin install api-platform@api-platform-skillset
Claude Code에 custom-validator skill 설치
~/.claude/skills/custom-validator/SKILL.md
$ npx degit api-platform/skillset/skills/custom-validator ~/.claude/skills/custom-validatorClaude Code (project)에 custom-validator skill 설치
.claude/skills/custom-validator/SKILL.md
$ npx degit api-platform/skillset/skills/custom-validator .claude/skills/custom-validatorCodex에 custom-validator skill 설치
~/.agents/skills/custom-validator/SKILL.md
$ npx degit api-platform/skillset/skills/custom-validator ~/.agents/skills/custom-validatorGemini CLI에 custom-validator skill 설치
~/.gemini/skills/custom-validator/SKILL.md
$ npx degit api-platform/skillset/skills/custom-validator ~/.gemini/skills/custom-validatorClaude.ai에 custom-validator skill 설치
npx degit api-platform/skillset/skills/custom-validator custom-validator && zip -r custom-validator.zip custom-validator # claude.ai → Customize → Skills → + → Create skill → Upload a skill → custom-validator.zip
SKILL.md
GitHub에서 보기Custom Validation Constraints
Create custom validators when built-in Symfony constraints are insufficient.
Constraint Class
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class IsValidAccountLimit extends Constraint
{
public string $message = 'Account limit reached for your current plan.';
public int $limit = 50;
}
Validator Class
Convention: {ConstraintName}Validator in the same namespace.
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class IsValidAccountLimitValidator extends ConstraintValidator
{
public function __construct(
private readonly UserHelper $userHelper,
private readonly AccountRepository $accountRepository,
) {}
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof IsValidAccountLimit) {
throw new \InvalidArgumentException('Unexpected constraint type');
}
if (null === $value || '' === $value) {
return;
}
$user = $this->userHelper->getUser();
$count = $this->accountRepository->countByUser($user->getId());
if ($count >= $constraint->limit) {
$this->context->buildViolation($constraint->message)
->addViolation();
}
}
}
Usage on Properties
use App\Validator\IsValidAccountLimit;
use Symfony\Component\Validator\Constraints as Assert;
class Account
{
#[Assert\NotBlank(groups: ['account:write'])]
#[Assert\Email(groups: ['account:write'])]
#[IsValidAccountLimit(groups: ['account:write'])]
public ?string $address;
}
Class-Level Constraint (UniqueEntity)
For constraints that validate across multiple fields:
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
class MongoDBUnique extends Constraint
{
public array $fields = [];
public string $message = 'This value is already used.';
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}
}
Usage:
#[MongoDBUnique(fields: ['address'], groups: ['account:write', 'account:patch'])]
class Account {}
Validation Groups with Operations
Target a constraint to specific operations by passing groups: (as shown above)
and wiring those groups into each operation's validationContext — see
operations for the full per-operation setup.
Callback Validation
For quick one-off validation on DTOs:
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class SendMessage
{
public ?string $text = null;
public ?string $html = null;
#[Assert\Callback]
public function validateContent(ExecutionContextInterface $context): void
{
if (null === $this->text && null === $this->html) {
$context->buildViolation('Either text or html content is required.')
->atPath('text')
->addViolation();
}
}
}
Laravel
Laravel does not use Symfony Constraints/ConstraintValidator. Validation is
declared with Laravel validation rules via the
rules option on #[ApiResource] or per-operation (rules can be an array, a closure,
or a FormRequest class-string). The ValidateProvider runs them before the
processor and emits the same 422 ConstraintViolationList shape.
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
#[ApiResource(rules: ['title' => 'required|min:2'])]
#[Post(rules: ['isbn' => ['required', 'string']])] // per-operation override
class Book extends Model {}
For business rules beyond built-in rules, write a Laravel custom rule (a class
implementing Illuminate\Contracts\Validation\ValidationRule, scaffold with
php artisan make:rule) or a closure rule, and reference it in rules. A
FormRequest class-string is also accepted — its authorize()/rules() run, and an
AuthorizationException maps to 403, ValidationException to 422. Validation groups
and Symfony validationContext do not apply on Laravel; scope rules per operation
instead. Partial PATCH can relax required to sometimes via
partial_patch_validation in config/api-platform.php.
이 스킬의 파일
1custom-validator skill 질문
Claude Code에 custom-validator skill을 어떻게 설치하나요?
npx degit api-platform/skillset/skills/custom-validator ~/.claude/skills/custom-validator를 실행합니다. Claude Code는 ~/.claude/skills(모든 프로젝트) 또는 .claude/skills(한 프로젝트)에서 skills를 로드하며, 설명이 작업과 일치할 때 skill을 사용합니다.
custom-validator skill을 사용할 수 있는 클라이언트는 무엇인가요?
Agent Skills 형식을 읽는 모든 클라이언트(Claude Code, Codex, Gemini CLI, claude.ai(ZIP으로 업로드))가 사용할 수 있습니다. skill 내 스크립트는 클라이언트가 코드 실행을 허용하는 경우에만 실행됩니다.
API Platform을 위한 Symfony 커스텀 유효성 검사기를 어떻게 만드나요?
동일한 네임스페이스 내에서 {ConstraintName}Validator 명명 규칙을 따르는 Constraint 클래스와 그에 대응하는 Validator 클래스를 생성해야 합니다.