Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

api-contract-reviewAPI contract 审查

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

1,004

周安装

41

GitHub Stars

539

下载量

321
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:api-contract-review(API contract 审查)
来源仓库:https://github.com/decebals/claude-code-java
仓库路径:skills/api-contract-review
安装命令:
npx skills add https://github.com/decebals/claude-code-java --skill api-contract-review
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/decebals/claude-code-java --skill api-contract-review

简介

审计 REST API 设计的正确性与兼容性,识别常见反模式与潜在风险点。

  • 适用于发布前检查控制器变更,确保 HTTP 方法、版本控制与错误格式合规。
  • 使用时需提供接口定义或代码片段,重点验证实体暴露与状态码合理性。
  • 安装方式:通过 npx skills add 从 GitHub 仓库安装,支持主流 AI 开发工具链。
  • 注意:审查结果应以 actionable 建议形式呈现,而非简单标记问题项。

SKILL.md

API Contract Review Skill

Audit REST API design for correctness, consistency, and compatibility.

When to Use

  • User asks "review this API" / "check REST endpoints"
  • Before releasing API changes
  • Reviewing PR with controller changes
  • Checking backward compatibility

Quick Reference: Common Issues

IssueSymptomImpact
Wrong HTTP verbPOST for idempotent operationConfusion, caching issues
Missing versioning/users instead of /v1/usersBreaking changes affect all clients
Entity leakJPA entity in responseExposes internals, N+1 risk
200 with error{"status": 200, "error": "..."}Breaks error handling
Inconsistent naming/getUsers vs /usersHard to learn API

HTTP Verb Semantics

Verb Selection Guide

VerbUse ForIdempotentSafeRequest Body
GETRetrieve resourceYesYesNo
POSTCreate new resourceNoNoYes
PUTReplace entire resourceYesNoYes
PATCHPartial updateNo*NoYes
DELETERemove resourceYesNoOptional

*PATCH can be idempotent depending on implementation

Common Mistakes

// ❌ POST for retrieval
@PostMapping("/users/search")
public List<User> searchUsers(@RequestBody SearchCriteria criteria) { }

// ✅ GET with query params (or POST only if criteria is very complex)
@GetMapping("/users")
public List<User> searchUsers(
    @RequestParam String name,
    @RequestParam(required = false) String email) { }

// ❌ GET for state change
@GetMapping("/users/{id}/activate")
public void activateUser(@PathVariable Long id) { }

// ✅ POST or PATCH for state change
@PostMapping("/users/{id}/activate")
public ResponseEntity<Void> activateUser(@PathVariable Long id) { }

// ❌ POST for idempotent update
@PostMapping("/users/{id}")
public User updateUser(@PathVariable Long id, @RequestBody UserDto dto) { }

// ✅ PUT for full replacement, PATCH for partial
@PutMapping("/users/{id}")
public User replaceUser(@PathVariable Long id, @RequestBody UserDto dto) { }

@PatchMapping("/users/{id}")
public User updateUser(@PathVariable Long id, @RequestBody UserPatchDto dto) { }

API Versioning

Strategies

StrategyExampleProsCons
URL path/v1/usersClear, easy routingURL changes
HeaderAccept: application/vnd.api.v1+jsonClean URLsHidden, harder to test
Query param/users?version=1Easy to addEasy to forget

Recommended: URL Path

// ✅ Versioned endpoints
@RestController
@RequestMapping("/api/v1/users")
public class UserControllerV1 { }

@RestController
@RequestMapping("/api/v2/users")
public class UserControllerV2 { }

// ❌ No versioning
@RestController
@RequestMapping("/api/users")  // Breaking changes affect everyone
public class UserController { }

Version Checklist

  • All public APIs have version in path
  • Internal APIs documented as internal (or versioned too)
  • Deprecation strategy defined for old versions

Request/Response Design

DTO vs Entity

// ❌ Entity in response (leaks internals)
@GetMapping("/{id}")
public User getUser(@PathVariable Long id) {
    return userRepository.findById(id).orElseThrow();
    // Exposes: password hash, internal IDs, lazy collections
}

// ✅ DTO response
@GetMapping("/{id}")
public UserResponse getUser(@PathVariable Long id) {
    User user = userService.findById(id);
    return UserResponse.from(user);  // Only public fields
}

Response Consistency

// ❌ Inconsistent responses
@GetMapping("/users")
public List<User> getUsers() { }  // Returns array

@GetMapping("/users/{id}")
public User getUser(@PathVariable Long id) { }  // Returns object

@GetMapping("/users/count")
public int countUsers() { }  // Returns primitive

// ✅ Consistent wrapper (optional but recommended for large APIs)
@GetMapping("/users")
public ApiResponse<List<UserResponse>> getUsers() {
    return ApiResponse.success(userService.findAll());
}

// Or at minimum, consistent structure:
// - Collections: always wrapped or always raw (pick one)
// - Single items: always object
// - Counts/stats: always object { "count": 42 }

Pagination

// ❌ No pagination on collections
@GetMapping("/users")
public List<User> getAllUsers() {
    return userRepository.findAll();  // Could be millions
}

// ✅ Paginated
@GetMapping("/users")
public Page<UserResponse> getUsers(
    @RequestParam(defaultValue = "0") int page,
    @RequestParam(defaultValue = "20") int size) {
    return userService.findAll(PageRequest.of(page, size));
}

HTTP Status Codes

Success Codes

CodeWhen to UseResponse Body
200 OKSuccessful GET, PUT, PATCHResource or result
201 CreatedSuccessful POST (created)Created resource + Location header
204 No ContentSuccessful DELETE, or PUT with no bodyEmpty

Error Codes

CodeWhen to UseCommon Mistake
400 Bad RequestInvalid input, validation failedUsing for "not found"
401 UnauthorizedNot authenticatedConfusing with 403
403 ForbiddenAuthenticated but not allowedUsing 401 instead
404 Not FoundResource doesn't existUsing 400
409 ConflictDuplicate, concurrent modificationUsing 400
422 UnprocessableSemantic error (valid syntax, invalid meaning)Using 400
500 Internal ErrorUnexpected server errorExposing stack traces

Anti-Pattern: 200 with Error Body

// ❌ NEVER DO THIS
@GetMapping("/{id}")
public ResponseEntity<Map<String, Object>> getUser(@PathVariable Long id) {
    try {
        User user = userService.findById(id);
        return ResponseEntity.ok(Map.of("status", "success", "data", user));
    } catch (NotFoundException e) {
        return ResponseEntity.ok(Map.of(  // Still 200!
            "status", "error",
            "message", "User not found"
        ));
    }
}

// ✅ Use proper status codes
@GetMapping("/{id}")
public ResponseEntity<UserResponse> getUser(@PathVariable Long id) {
    return userService.findById(id)
        .map(ResponseEntity::ok)
        .orElse(ResponseEntity.notFound().build());
}

Error Response Format

Consistent Error Structure

// ✅ Standard error response
public class ErrorResponse {
    private String code;        // Machine-readable: "USER_NOT_FOUND"
    private String message;     // Human-readable: "User with ID 123 not found"
    private Instant timestamp;
    private String path;
    private List<FieldError> errors;  // For validation errors
}

// In GlobalExceptionHandler
@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<ErrorResponse> handleNotFound(
        ResourceNotFoundException ex, HttpServletRequest request) {
    return ResponseEntity.status(HttpStatus.NOT_FOUND)
        .body(ErrorResponse.builder()
            .code("RESOURCE_NOT_FOUND")
            .message(ex.getMessage())
            .timestamp(Instant.now())
            .path(request.getRequestURI())
            .build());
}

Security: Don't Expose Internals

// ❌ Exposes stack trace
@ExceptionHandler(Exception.class)
public ResponseEntity<String> handleAll(Exception ex) {
    return ResponseEntity.status(500)
        .body(ex.getStackTrace().toString());  // Security risk!
}

// ✅ Generic message, log details server-side
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleAll(Exception ex) {
    log.error("Unexpected error", ex);  // Full details in logs
    return ResponseEntity.status(500)
        .body(ErrorResponse.of("INTERNAL_ERROR", "An unexpected error occurred"));
}

Backward Compatibility

Breaking Changes (Avoid in Same Version)

ChangeBreaking?Migration
Remove endpointYesDeprecate first, remove in next version
Remove field from responseYesKeep field, return null/default
Add required field to requestYesMake optional with default
Change field typeYesAdd new field, deprecate old
Rename fieldYesSupport both temporarily
Change URL pathYesRedirect old to new

Non-Breaking Changes (Safe)

  • Add optional field to request
  • Add field to response
  • Add new endpoint
  • Add new optional query parameter

Deprecation Pattern

@RestController
@RequestMapping("/api/v1/users")
public class UserControllerV1 {

    @Deprecated
    @GetMapping("/by-email")  // Old endpoint
    public UserResponse getByEmailOld(@RequestParam String email) {
        return getByEmail(email);  // Delegate to new
    }

    @GetMapping(params = "email")  // New pattern
    public UserResponse getByEmail(@RequestParam String email) {
        return userService.findByEmail(email);
    }
}

API Review Checklist

1. HTTP Semantics

  • GET for retrieval only (no side effects)
  • POST for creation (returns 201 + Location)
  • PUT for full replacement (idempotent)
  • PATCH for partial updates
  • DELETE for removal (idempotent)

2. URL Design

  • Versioned (/v1/, /v2/)
  • Nouns, not verbs (/users, not /getUsers)
  • Plural for collections (/users, not /user)
  • Hierarchical for relationships (/users/{id}/orders)
  • Consistent naming (kebab-case or camelCase, pick one)

3. Request Handling

  • Validation with @Valid
  • Clear error messages for validation failures
  • Request DTOs (not entities)
  • Reasonable size limits

4. Response Design

  • Response DTOs (not entities)
  • Consistent structure across endpoints
  • Pagination for collections
  • Proper status codes (not 200 for errors)

5. Error Handling

  • Consistent error format
  • Machine-readable error codes
  • Human-readable messages
  • No stack traces exposed
  • Proper 4xx vs 5xx distinction

6. Compatibility

  • No breaking changes in current version
  • Deprecated endpoints documented
  • Migration path for breaking changes

Token Optimization

For large APIs:

  1. List all controllers: find. -name "*Controller.java"
  2. Sample 2-3 controllers for pattern analysis
  3. Check @ExceptionHandler configuration once
  4. Grep for specific anti-patterns: # Find potential entity leaks grep -r "public.*Entity.*@GetMapping" --include="*.java" # Find 200 with error patterns grep -r "ResponseEntity.ok.*error" --include="*.java" # Find unversioned APIs grep -r "@RequestMapping.*api" --include="*.java" | grep -v "/v[0-9]"

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.47%
按下载量换算120

Claude

29.53%
按下载量换算95

Cursor

17.86%
按下载量换算57

Gemini CLI

9.27%
按下载量换算30

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills