sw:validated-api
11
总安装量
11
周安装量
#27910
全站排名
安装命令
npx skills add https://github.com/anton-abyzov/specweave --skill sw:validated-api
Agent 安装分布
claude-code
10
cursor
8
opencode
7
codex
7
antigravity
7
gemini-cli
7
Skill 文档
Self-Validating API Endpoint Generator
You are generating a REST API endpoint with automatic validation.
How Self-Validation Works
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â YOUR CODE WILL BE AUTOMATICALLY VALIDATED â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â â
â 1. PRE-CHECK: Verify project has Express installed â
â â
â 2. GENERATE: You create the endpoint + tests â
â â
â 3. VALIDATE (automatic): â
â ââ npm test â Must pass â
â ââ npm run lint â Auto-fixed if needed â
â ââ tsc --noEmit â Must type-check â
â â
â 4. If validation fails: â
â ââ You get feedback and retry (max 3 times) â
â â
â 5. If still failing after 3 attempts: â
â ââ Pause for human review â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Required Outputs
1. API Endpoint (src/routes/[name].ts)
import { Router, Request, Response } from 'express';
const router = Router();
// GET /api/[name]
router.get('/', async (req: Request, res: Response) => {
// Implementation
});
// POST /api/[name]
router.post('/', async (req: Request, res: Response) => {
// Implementation with validation
});
export default router;
2. Test File (src/routes/[name].test.ts) – REQUIRED!
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import request from 'supertest';
import app from '../app';
describe('[Name] API', () => {
describe('GET /api/[name]', () => {
it('should return 200 with data', async () => {
const res = await request(app).get('/api/[name]');
expect(res.status).toBe(200);
expect(res.body).toBeDefined();
});
});
describe('POST /api/[name]', () => {
it('should create resource with valid data', async () => {
const res = await request(app)
.post('/api/[name]')
.send({ /* valid data */ });
expect(res.status).toBe(201);
});
it('should return 400 for invalid data', async () => {
const res = await request(app)
.post('/api/[name]')
.send({ /* invalid data */ });
expect(res.status).toBe(400);
});
});
});
Validation Criteria
| Check | Command | Required |
|---|---|---|
| Tests pass | npm test -- --testPathPattern="$OUTPUT" |
â Yes |
| Lint clean | npm run lint -- $OUTPUT |
â Yes (auto-fix) |
| Types valid | npx tsc --noEmit $OUTPUT |
â Yes |
Self-Healing Behavior
If tests fail, you will receive:
- The test output showing which tests failed
- A request to fix the failing tests
- Another attempt (up to 3 total)
Example failure feedback:
ð´ VALIDATION FAILED (attempt 1/3)
Test Results:
â GET /api/users should return 200 with data
Expected: 200
Received: 404
Please fix the route handler and regenerate.
Important Notes
- Always generate tests – The skill will NOT complete without passing tests
- Use proper types – TypeScript errors block completion
- Follow lint rules – Auto-fixed but avoid common issues
- Handle edge cases – Test both success and error paths