self-validating-example
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
Project-Specific Learnings
Before starting work, check for project-specific learnings:
# Check if skill memory exists for this skill
cat .specweave/skill-memories/self-validating-example.md 2>/dev/null || echo "No project learnings yet"
Project learnings are automatically captured by the reflection system when corrections or patterns are identified during development. These learnings help you understand project-specific conventions and past decisions.
More from anton-abyzov/specweave
technical-writing
Technical writing expert for API documentation, README files, tutorials, changelog management, and developer documentation. Covers style guides, information architecture, versioning docs, OpenAPI/Swagger, and documentation-as-code. Activates for technical writing, API docs, README, changelog, tutorial writing, documentation, technical communication, style guide, OpenAPI, Swagger, developer docs.
45spec-driven-brainstorming
Spec-driven brainstorming and product discovery expert. Helps teams ideate features, break down epics, conduct story mapping sessions, prioritize using MoSCoW/RICE/Kano, and validate ideas with lean startup methods. Activates for brainstorming, product discovery, story mapping, feature ideation, prioritization, MoSCoW, RICE, Kano model, lean startup, MVP definition, product backlog, feature breakdown.
43kafka-architecture
Apache Kafka architecture expert for cluster design, capacity planning, and high availability. Use when designing Kafka clusters, choosing partition strategies, or sizing brokers for production workloads.
34docusaurus
Docusaurus 3.x documentation framework - MDX authoring, theming, versioning, i18n. Use for documentation sites or spec-weave.com.
29frontend
Expert frontend developer for React, Vue, Angular, and modern JavaScript/TypeScript. Use when creating components, implementing hooks, handling state management, or building responsive web interfaces. Covers React 18+ features, custom hooks, form handling, and accessibility best practices.
29reflect
Self-improving AI memory system that persists learnings across sessions in CLAUDE.md. Use when capturing corrections, remembering user preferences, or extracting patterns from successful implementations. Enables continual learning without starting from zero each conversation.
27