MCPInstall

ddd4j-validation

DDD4J 自定义校验规则技能。覆盖四个自定义约束(@AllowedValues/@PhoneNumber/@NumberValue/@StringDateValue)、@StringDateValue空字符串静默通过规则、校验器禁用默认消息插值约束、校验层位置(Param/DTO而非独立Validator)、libphonenumber国际手机号校验。 当用户在 DDD4J 项目中编写参数校验、手机号/日期格式校验、枚举值校验时需要此技能。 配合 ddd4j-core 技能使用。

Installs
52
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/full-stack-skills/ddd-skills --skill ddd4j-validation
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads ddd4j-validation automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

DDD4J 自定义校验规则

编码 DDD4J 项目中四个自定义 Bean Validation 约束的使用规则。LLM 不知道这些约束存在,会自己写校验逻辑。

为什么需要这个技能

LLM 会用 @Pattern(regexp="^1[3-9]\\d{9}$") 校验手机号——DDD4J 有 @PhoneNumber(基于 libphonenumber,支持国际化)。LLM 会用 @DateFormat 校验日期——DDD4J 有 @StringDateValue(空字符串静默通过)。这些自定义约束 LLM 完全不知道。

Capability Boundaries

✅ Strong Suits

  1. @AllowedValues — 字符串数组白名单校验,支持 nullable
  2. @PhoneNumber — Google libphonenumber 手机号校验
  3. @NumberValue — 正则数字格式校验
  4. @StringDateValue — 日期字符串格式校验(空串通过)

❌ Out of Scope

  1. 实体定义/返回值约定 → ddd4j-core
  2. Jackson 序列化校验 → ddd4j-jackson

LLM 最常犯的错误

#错误正确做法
1@Pattern(regexp="1[3-9]\\d{9}") 校验手机号用 @PhoneNumber(libphonenumber,国际化)
2@DateTimeFormat 校验日期用 @StringDateValue(format="yyyy-MM-dd HH:mm:ss")
3自定义 Validator 类做校验校验注解放在 Param/DTO 字段上
4给 @StringDateValue 的字段传空字符串空字符串静默通过,不是校验失败
5不写 message 属性所有自定义约束必须显式写 message
6用 @NotEmpty 代替 @AllowedValues.nullable=falsenullable 控制空值行为

核心规则速查

// ✅ 正确:四个自定义约束

// @AllowedValues — 白名单校验
public class UserParam extends BaseParam {
    @AllowedValues(values = {"MALE", "FEMALE", "OTHER"}, nullable = false,
        message = "性别必须为 MALE/FEMALE/OTHER 之一")
    private String gender;

    @AllowedValues(values = {"ACTIVE", "INACTIVE"}, nullable = true,
        message = "状态必须为 ACTIVE/INACTIVE")
    private String status;  // nullable=true → 空值通过校验
}

// @PhoneNumber — 手机号校验(libphonenumber)
public class RegisterParam extends BaseParam {
    @PhoneNumber(lang = "CN", message = "手机号格式不正确")
    private String phone;

    @PhoneNumber(lang = "US", message = "Invalid US phone number")
    private String usPhone;
}

// @NumberValue — 数字格式
public class IdParam {
    @NumberValue(regex = "^[0-9\\-]+$", message = "ID只能包含数字和横线")
    private String id;
}

// @StringDateValue — 日期字符串
public class DateParam {
    @StringDateValue(format = "yyyy-MM-dd HH:mm:ss", message = "日期格式错误")
    private String beginTime;   // "" 空字符串 → 静默通过
    // SimpleDateFormat.setLenient(false) → 严格模式
}

Gotchas

  1. @StringDateValue 空字符串静默通过 — 空值不触发校验,需要用 @NotEmpty 配合
  2. 所有自定义约束必须提供 message — 校验器 disableDefaultConstraintViolation 禁用了默认消息
  3. @PhoneNumber 依赖 libphonenumber — 需要引入 com.googlecode.libphonenumber
  4. @AllowedValues.nullable=true 时 null/空串都通过 — nullable=false 时空值不通过
  5. @NumberValue 默认正则 ^[0-9\\-]+$ — 只允许数字和横线
  6. 校验注解放在 Param/DTO 上 — 不要创建独立的 Validator 类
  7. @StringDateValue 使用严格模式 — SimpleDateFormat.setLenient(false),非严格日期不通过

Data Privacy

本技能不收集、存储或传输任何用户数据。

FAQ

What does the ddd4j-validation skill do?

DDD4J 自定义校验规则技能。覆盖四个自定义约束(@AllowedValues/@PhoneNumber/@NumberValue/@StringDateValue)、@StringDateValue空字符串静默通过规则、校验器禁用默认消息插值约束、校验层位置(Param/DTO而非独立Validator)、libphonenumber国际手机号校验。 当用户在 DDD4J 项目中编写参数校验、手机号/日期格式校验、枚举值校验时需要此技能。 配合 ddd4j-core 技能使用。

How do I install ddd4j-validation?

Run npx skills add https://github.com/full-stack-skills/ddd-skills --skill ddd4j-validation in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/ddd4j-validation/ (personal) or .claude/skills/ddd4j-validation/ (project).

Which AI agents can use ddd4j-validation?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is ddd4j-validation safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains ddd4j-validation?

It is published by full-stack-skills in full-stack-skills/ddd-skills. It has 52 recorded installs.

More from full-stack-skills/ddd-skills

View all →

ddd-code-reviewer

full-stack-skills/ddd-skills

DDD code review and anti-pattern detection — anemia model detection, layered compliance checking, aggregate design review, rich model verification, scoring system (5 dimensions), and ArchUnit automated validation. Use when user asks about code review, 代码审查, DDD review, 架构审查, anti-pattern detection, 反模式检测, or needs to check if code follows DDD.

ddd-api-designer

full-stack-skills/ddd-skills

API design from domain model — CQRS command/query separation, REST API endpoint design, data object conversion chain (PO→DO→DTO→VO), unified response format, OpenAPI/Swagger generation, BFF pattern, API versioning, and security design. Use when user asks about API design, REST API, OpenAPI, BFF, DTO design, 接口设计, or data object conversion.

Backend & APIs139 installs

ddd-domain-designer

full-stack-skills/ddd-skills

Open the skill to read its SKILL.md instructions.

Frontend & Design133 installs

ddd-devops-integration

full-stack-skills/ddd-skills

DDD DevOps integration — CI/CD pipeline with ArchUnit automated architecture validation, multi-module build optimization for DDD projects, containerized deployment with Docker/K8s for layered/hexagonal/clean architectures, database migration strategies for domain events, and monitoring domain health. Use when user asks about DevOps, CI/CD, DDD deployment, ArchUnit CI, or needs to automate DDD project builds.

DevOps & Cloud131 installs

ddd-event-storming

full-stack-skills/ddd-skills

Open the skill to read its SKILL.md instructions.

127 installs

ddd-architecture-clean

full-stack-skills/ddd-skills

Open the skill to read its SKILL.md instructions.

Popular other skills

View category →

hyperframes-cli

heygen-com/hyperframes

The HyperFrames CLI by job - scaffold, check, look at frames, edit the timeline, preview, render locally or in the cloud, publish, project history - plus reading its JSON and recovering from build or render failures.

1.3M installs

triage

mattpocock/skills

Move issues and external PRs through a state machine of triage roles, categorise, verify, grill if needed, and write agent-ready briefs.

1M installs

ask-matt

mattpocock/skills

Ask which skill or flow fits your situation. A router over the skills in this repo.

778.4K installs

to-questionnaire

mattpocock/skills

Turn a decision you can't fully answer into a questionnaire for someone else to fill in.

508.9K installs

wait-what

mattpocock/skills

Stop. That last message did not land: re-pitch it.

459.7K installs

loop-me

mattpocock/skills

Grill me about specs for the workflows I want to build, within this workspace.

447.9K installs