-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Current Situation/Problem
Currently, itdoc provides excellent test-driven API documentation generation through its function-based approach using describeAPI() and itDoc(). However, this approach requires developers to write verbose boilerplate code and manually integrate with test frameworks
Proposed Feature
Introduce decorator-based API documentation support that allows developers to add documentation decorators to existing E2E tests in their preferred test frameworks, providing a seamless way to generate API documentation from existing test suites:
// Proposed decorator-based approach - enhancing existing E2E tests
import { ApiDoc, DocumentEndpoint } from 'itdoc/decorators'
import request from 'supertest'
import { app } from '../src/app'
describe('User Authentication API', () => {
@ApiDoc({
method: "POST",
path: "/signup",
summary: "User Registration API",
description: "Register a new user with username and password",
tag: "Auth"
})
it('should register user successfully', async () => {
const response = await request(app)
.post('/signup')
.send({
username: 'testuser',
password: 'password123'
})
.expect(201)
expect(response.body).toEqual({
message: 'User registered successfully',
userId: expect.any(String)
})
})
@ApiDoc({
method: "POST",
path: "/signup",
summary: "User Registration API - Validation Error",
description: "Returns error when username is missing",
tag: "Auth"
})
it('should fail when username is missing', async () => {
const response = await request(app)
.post('/signup')
.send({
password: 'password123'
})
.expect(400)
expect(response.body).toEqual({
error: 'Username is required'
})
})
})
// Works with any test framework
describe('Product API', () => {
@DocumentEndpoint({
method: "GET",
path: "/products/:id",
summary: "Get Product by ID",
tag: "Products"
})
test('should return product details', async () => {
// Existing Jest/Mocha/Vitest test code
const response = await request(app)
.get('/products/123')
.expect(200)
expect(response.body.id).toBe(123)
expect(response.body.name).toBeDefined()
})
})Benefits of decorator-based approach:
- Non-intrusive integration: Add documentation to existing E2E tests without changing test logic
- Framework agnostic: Works seamlessly with any test framework (Jest, Mocha, Vitest, etc.)
- Minimal learning curve: Developers can keep using their familiar testing patterns
- Better IDE support: Enhanced autocomplete, IntelliSense, and refactoring capabilities
- Gradual adoption: Teams can incrementally add documentation decorators to existing tests
- Automatic documentation generation: Extract API specs directly from real, working tests
- Test-driven documentation: Documentation is always in sync with actual test behavior
Alternatives (Optional)
No response
Additional Information
No response
Reactions are currently unavailable