Skip to content

Commit 3cd3867

Browse files
committed
chore: add cursor rule for OpenAPI API specification documentation
1 parent 89620bf commit 3cd3867

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: OpenAPI Specification and Implementation
3+
description: Guidelines for maintaining OpenAPI specifications in sync with API implementation
4+
globs:
5+
- "docs/openapi/**"
6+
- "src/**"
7+
alwaysApply: false
8+
version: "1.0.0"
9+
---
10+
11+
# OpenAPI Specification and Implementation
12+
13+
## Context
14+
When changes touch API specification files under `docs/openapi` **or** implementation files under `src`, this rule applies.
15+
16+
## Core Principles
17+
18+
### Specification-Implementation Sync
19+
- Any new endpoint, modification of existing endpoint, or removal must include **both** the OpenAPI spec change **and** the matching implementation in `src`
20+
- If the implementation is deferred, the spec's endpoint description **must start with** `Not implemented yet`
21+
and the actual handler must return HTTP **501** with a clear JSON message:
22+
```json
23+
{ "error": "Not implemented yet: <feature-name>" }
24+
```
25+
- Keep examples in sync with actual API behavior
26+
27+
### Schema Management
28+
- All request/response bodies and parameters **must reference** schemas in `schemas.yaml`
29+
- Reuse existing schemas wherever possible to avoid duplication
30+
- Avoid redefining data structures inline unless absolutely necessary
31+
- Use **composition, inheritance, polymorphism** (as supported by OpenAPI 3.1.1) to reuse common parts
32+
- When introducing new audit types, update:
33+
- Audit type enum
34+
- Audit result schema
35+
- At least one complete example
36+
37+
### Examples
38+
- Add examples to `examples.yaml` and reference them (don't inline)
39+
- Include at least one request and response example per endpoint
40+
- Examples must validate against the schema and represent realistic, production-like data
41+
42+
### Precision & Consistency
43+
- Keep definitions as precise as possible (correct types, constraints, formats, etc.)
44+
- Endpoints under the same tag must follow consistent naming, path structure, response format, etc.
45+
46+
### Validation & Documentation Build
47+
- After modifying OpenAPI specs, **always run** `npm run docs:lint` to validate the specification
48+
- Before completing implementation, **must run** `npm run docs:build` to generate documentation
49+
- Fix any linting errors or build failures before considering the task complete
50+
51+
## API Design Patterns
52+
53+
### Pagination
54+
- Set strict limits on collection resource items returned
55+
- Support optional `limit` query parameter with documented defaults, min/max values
56+
- Use cursor-based pagination with `cursor` query parameter
57+
- Response format: `{ "cursor": "next-token", "items": [...] }`
58+
- Omit `cursor` property when no more items exist
59+
- Use consistent naming: `limit` and `cursor` across all paginated endpoints
60+
61+
### Bulk Operations
62+
- **Prefer bulk endpoints over separate single/multi-item endpoints**
63+
- Accept arrays containing one or more items
64+
- Document explicitly in description that single items can be passed in arrays
65+
- Set strict limits on bulk POST/PUT/PATCH/DELETE request sizes
66+
- Response format: `{ "metadata": { "total": N, "success": N, "failure": N }, "failures": [...], "items": [...] }`
67+
- Specify atomicity behavior and per-item error reporting
68+
69+
### Parameters
70+
- For URLs passed as path parameters, use {base64Url} and encode as URL-safe base64 without padding (RFC 4648 §5) to avoid +/= issues in paths
71+
- Maintain consistent naming across all endpoints
72+
73+
### POST Requests
74+
- Document idempotency behavior explicitly
75+
- Specify duplicate detection mechanism if applicable
76+
- Indicate whether upserts are supported
77+
78+
### PATCH Requests
79+
- Implementation must update only fields provided in request. If other fields are modified or reset, document this behavior clearly in the endpoint description

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ admin-idp-p*.json
1414
*.code-workspace
1515
.prettierrc
1616
.vscode/settings.json
17-
.cursor
17+
.cursor/*
18+
!.cursor/rules/

0 commit comments

Comments
 (0)