java-openapi-annotations

A Java rule for adding OpenAPI 3 annotations to REST endpoints. OpenAPI is a machine-readable description of an HTTP API that can power documentation and code-generation tools.

In plain words
What is it for?
Use it when creating or changing Spring REST controllers, endpoint parameters, request and response models, and their API documentation.
Why use it?
Without these annotations, endpoints may not appear in Swagger UI, and their operations may not be available to the repository’s API integration tools.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/xc404/kiwi/java-openapi-annotations
Clone the repo
git clone --depth 1 https://github.com/xc404/kiwi

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 818 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00818
Opus 5 $0.00000 $0.00409
Sonnet 5 $0.00000 $0.00164
Haiku 4.5 $0.00000 $0.00082

Measured yesterday against content hash 36a62a1f8df5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

java-openapi-annotations scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/java-openapi-annotations.mdc · 51 lines

What it actually says

REST 接口 OpenAPI 注解(kiwi-admin)

新增或修改 kiwi-admin/backend 的 REST 接口时,必须同步补充 OpenAPI 3 注解(io.swagger.v3.oas.annotations.*),与现有 Controller 风格一致。未标注的接口不会进入 Swagger UI,且 @Operation 缺失时无法被 MCP OpenAPI 工具同步(见 KiwiOpenApiSyncMcpToolsConfiguration)。

Controller 类

  • @RestController 上添加 @Tag(name = "…", description = "…")description 可选)。
  • name 用中文业务名,与模块一致(如「系统菜单」「BPM 组件」)。

每个公开端点方法

  • 添加 @Operation,且 必须 包含:
    • operationId:全局唯一、稳定,供 MCP / 前端 codegen 引用;格式 {前缀}_{动作},前缀为控制器简称(camelCase),例如 menu_getbpmComp_pagedict_addDictcodeEnt_createauth_userInfo
    • summary:一句中文,说明接口做什么。
  • 分页、查询条件、请求体字段等非显而易见时,补充 description(中文,写清默认值与约束,如「page 从 0 开始,size 默认 20、最大 100」)。
  • @Operation 放在映射注解(@GetMapping 等)上方,与现有代码一致。

路径 / 查询 / 请求体参数

  • @PathVariable / @RequestParam:语义不清时加 @Parameter(description = "…")
  • @RequestBody:需要说明字段时,使用 io.swagger.v3.oas.annotations.parameters.RequestBody(勿与 Spring 的 @RequestBody 混淆);Spring 绑定仍用 org.springframework.web.bind.annotation.RequestBody

请求 / 响应 DTO(dto 包或 Controller 内嵌类)

  • 类上:@Schema(description = "…")
  • 对外暴露、含义不直观的字段:@Schema(description = "…")(必要时 examplerequiredMode)。

示例(与 SysMenuCtl 一致)

@Tag(name = "系统菜单", description = "菜单 CRUD 与树")
public class SysMenuCtl {

    @Operation(operationId = "menu_get", summary = "按 id 获取菜单详情")
    @GetMapping("{id}")
    public SysMenu menu(@PathVariable("id") String id) { ... }
}

禁止 / 注意

  • 不要 只写 Spring MVC 映射而不写 @Operation(除非明确为内部、非文档化端点,且团队确认不需要 Swagger/MCP)。
  • 不要 省略 operationId 或随意改名(会破坏 MCP 工具与已有集成)。
  • 使用 OpenAPI 3 注解包名 io.swagger.v3.oas.annotations不要 使用已废弃的 Swagger 2 io.swagger.annotations
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 51 lines · 0 tokens per session scan A 36a62a1f8df5

Subscribe to this mod's changes

java-openapi-annotations is a cursor rule published in the GitHub repository xc404/kiwi (7 stars, last pushed 7d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 818 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.