AGENT SKILL

spring-controller

Generate a Spring Boot @RestController with matching DTOs, mappers, @ControllerAdvice handler, and unit tests following hexagonal architecture.

License 许可
MIT
最近更新
2026-10-27
Stars
★ 0
Forks
1

01 前言 Front Matter

name
spring-controller
model
sonnet
visibility
public
description
Generate a Spring Boot @RestController with matching DTOs, mappers, @ControllerAdvice handler, and unit tests following hexagonal architecture.
allowed-tools
[ "Read", "Write", "Edit", "Bash", "Skill" ]
requires-capabilities
[ "web.spring.boot" ]

03 SKILL.md 正文

Skill: Spring Controller Generator

Purpose

Generates a complete Spring Boot inbound adapter (controller) layer following the hexagonal architecture pattern established by this project. Produces:

  1. @RestController class with CRUD or custom endpoints
  2. Request/Response DTOs (record types with @RegisterReflectionForBinding)
  3. Static mapper class (DtoMapper)
  4. @RestControllerAdvice exception handler (or extends existing)
  5. Unit tests for controller and mapper

Triggers

  • /spring-controller <ResourceName> [--operations GET,POST,DELETE] — generate full controller for a resource
  • /spring-controller <ResourceName> --crud — generate standard CRUD (GET list, GET by id, POST, PUT, DELETE)
  • /spring-controller <ResourceName> --read-only — generate GET endpoints only

Parameters

Parameter Required Description
ResourceName Yes PascalCase resource name (e.g., Merchant, Transaction)
--operations No Comma-separated HTTP methods to generate (default: all)
--crud No Shorthand for GET list, GET by id, POST, PUT, DELETE
--read-only No Shorthand for GET list and GET by id only
--path No Override API path (default: /api/v1/{resource-name-plural})
--port No Port interface name (default: {ResourceName}ManagementPort)

Workflow

Step 1 — Read Project Context

Read existing conventions:

  • knowledge/stack-patterns/spring/index.md — Spring Boot patterns
  • knowledge/layer-templates.md — Layer template patterns
  • knowledge/architecture-hexagonal.md — Hexagonal architecture conventions
  • Existing controller in src/main/java/**/adapter/inbound/ for naming conventions

Step 2 — Generate DTOs

Create request and response records following Spring patterns:

// src/main/java/{package}/adapter/inbound/rest/{ResourceName}Request.java
@RegisterReflectionForBinding
public record {ResourceName}Request(
    @NotBlank @Size(max = N) String field1,
    @NotNull Type field2
) {}

// src/main/java/{package}/adapter/inbound/rest/{ResourceName}Response.java
@RegisterReflectionForBinding
public record {ResourceName}Response(Long id, String field1, Type field2) {}

Step 3 — Generate Mapper

// src/main/java/{package}/adapter/inbound/rest/{ResourceName}DtoMapper.java
public final class {ResourceName}DtoMapper {
    private {ResourceName}DtoMapper() {}

    public static {DomainType} toDomain({ResourceName}Request request) { ... }
    public static {ResourceName}Response toResponse({DomainType} domain) { ... }
}

Step 4 — Generate Controller

Follow knowledge/stack-patterns/spring/index.md §4 RestController pattern:

// src/main/java/{package}/adapter/inbound/rest/{ResourceName}Controller.java
@RestController
@RequestMapping("{path}")
public class {ResourceName}Controller {
    // Constructor injection of port
    // Endpoints per --operations
}

Step 5 — Generate/Update Exception Handler

Check if GlobalExceptionHandler exists in adapter/inbound/rest/:

  • If exists: add missing @ExceptionHandler methods for domain exceptions
  • If not exists: generate new GlobalExceptionHandler following §5 pattern

Step 6 — Generate Tests

// src/test/java/{package}/adapter/inbound/rest/{ResourceName}ControllerTest.java
@WebMvcTest({ResourceName}Controller.class)
class {ResourceName}ControllerTest {
    @Autowired MockMvc mockMvc;
    @MockBean {ResourceName}ManagementPort port;

    // One test per endpoint per scenario (happy path + error paths)
}

Output Checklist

  • [ ] DTOs are records with @RegisterReflectionForBinding
  • [ ] Validation annotations on all request fields (@NotBlank, @NotNull, @Size, etc.)
  • [ ] Mapper is a final class with private constructor (static methods only)
  • [ ] Controller uses constructor injection (no @Autowired on fields)
  • [ ] HTTP status codes correct: 200 GET, 201 POST, 204 DELETE/PUT with no body
  • [ ] @ExceptionHandler present for each domain exception type
  • [ ] Tests cover: success path, not found (404), conflict (409), validation failure (400)
  • [ ] Tests use MockMvc with @WebMvcTest (not @SpringBootTest)

Knowledge Pack References

  • knowledge/stack-patterns/spring/index.md — Spring Boot patterns (§4 RestController, §5 ControllerAdvice)
  • knowledge/layer-templates.md — Layer template patterns
  • knowledge/architecture-hexagonal.md — Hexagonal architecture
  • knowledge/coding-standards/coding-conventions.md — Naming conventions

04 同仓库更多 Skills

review-bench
review-bench/edercnj_ia-dev-environment

x-parallel-eval

Detects and classifies file-collision risks between work units (tasks, stories, or epic phases) before parallel execution. Reads ## File Footprint blocks produced by x-task-plan / x-story-plan, applies the parallelism-heuristics knowledge pack (hard / regen / soft categories + hotspot overrides), and emits a collision matrix + serialization recommendation in Markdown (default) or JSON.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

parallelism-heuristics

Canonical catalog of file-collision heuristics for parallel task, story, and epic execution. Defines the File Footprint block format, the three Conflict Categories (hard / regen / soft), a hotspot list of high-contention paths, and the degrade-with-warning policy. Consumed by x-task-plan, x-story-plan, x-epic-map, x-parallel-eval, and x-dev-*-implement.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

x-watch-pr-ci

Polls a PR's CI checks and Copilot review status, blocking until checks complete or timeout. Returns one of 8 stable exit codes (SUCCESS=0, CI_PENDING_PROCEED=10, CI_FAILED=20, TIMEOUT=30, PR_ALREADY_MERGED=40, NO_CI_CONFIGURED=50, PR_CLOSED=60, PR_NOT_FOUND=70). Writes a versioned state-file for session resume.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

x-validate-docs

Documentation freshness gate: validates 6 dimensions (readme, api-specs, grpc-proto, adr, skill-docs, system-architecture) against code changes in a PR. Stack-aware — only validates targets declared/auto-detected from ProjectConfig.documentation.targets. Returns exit non-zero on staleness; produces structured report.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

x-update-system-architecture

Incrementally updates docs/architecture/system.md after an epic completes. Appends new entries to the Decision Log (§11) using x-internal-write-report --append (dedup by ## ID: marker) and surgically inserts component/integration changes into sections 1-10 via Edit. Idempotent: re-running with the same epic produces a byte-identical system.md.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

x-update-architecture

Incrementally updates the service architecture document with changes from architecture plans. Adds new components, integrations, flows, and ADR references without rewriting existing content. Use after implementation to keep architecture documentation current.

★ 0