Skip to content

Commit 034935b

Browse files
Merge pull request #1046 from Immaculate0606/feature/issue-740-openapi-webhooks
docs: Add OpenAPI examples for /api/webhooks
2 parents 5d66b2e + 671b5da commit 034935b

2 files changed

Lines changed: 104 additions & 0 deletions

File tree

src/openapi.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,82 @@ paths:
830830
message: Error definition 999 not found
831831
requestId: req-errors-delete-404
832832
timestamp: "2026-07-27T09:15:00.000Z"
833+
/api/webhooks:
834+
post:
835+
summary: Register a webhook
836+
description: Registers a new webhook for the authenticated developer.
837+
requestBody:
838+
required: true
839+
content:
840+
application/json:
841+
schema:
842+
type: object
843+
examples:
844+
registerWebhook:
845+
summary: Register a webhook for API and balance events
846+
value:
847+
developerId: "dev-123"
848+
url: "https://example.com/webhook"
849+
events:
850+
- "new_api_call"
851+
- "low_balance_alert"
852+
secret: "my_super_secret"
853+
retryPolicy:
854+
maxRetries: 3
855+
initialIntervalMs: 1000
856+
backoffFactor: 2.0
857+
responses:
858+
"201":
859+
description: Webhook registered successfully
860+
content:
861+
application/json:
862+
schema:
863+
type: object
864+
examples:
865+
registered:
866+
summary: Successfully registered
867+
value:
868+
message: Webhook registered successfully.
869+
developerId: "dev-123"
870+
url: "https://example.com/webhook"
871+
events:
872+
- "new_api_call"
873+
- "low_balance_alert"
874+
/api/webhooks/{developerId}:
875+
get:
876+
summary: Get webhook config
877+
description: Returns the webhook configuration for the given developer.
878+
responses:
879+
"200":
880+
description: Webhook configuration
881+
content:
882+
application/json:
883+
schema:
884+
type: object
885+
examples:
886+
found:
887+
summary: Webhook config
888+
value:
889+
developerId: "dev-123"
890+
url: "https://example.com/webhook"
891+
events:
892+
- "new_api_call"
893+
- "low_balance_alert"
894+
retryPolicy:
895+
maxRetries: 3
896+
initialIntervalMs: 1000
897+
backoffFactor: 2.0
898+
"404":
899+
description: Webhook not found
900+
content:
901+
application/json:
902+
schema:
903+
type: object
904+
examples:
905+
notFound:
906+
summary: No webhook registered
907+
value:
908+
message: "No webhook registered for this developer."
833909
components:
834910
securitySchemes:
835911
bearerAuth:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
4+
describe('src/openapi.yaml — webhooks examples', () => {
5+
const yamlPath = path.join(process.cwd(), 'src', 'openapi.yaml');
6+
7+
test('documents GET /api/webhooks/{developerId} endpoint', () => {
8+
const content = fs.readFileSync(yamlPath, 'utf8');
9+
expect(content).toContain('/api/webhooks/{developerId}');
10+
expect(content).toContain('Get webhook config');
11+
});
12+
13+
test('documents POST /api/webhooks endpoint', () => {
14+
const content = fs.readFileSync(yamlPath, 'utf8');
15+
expect(content).toContain('/api/webhooks');
16+
expect(content).toContain('Register a webhook');
17+
});
18+
19+
test('includes register and get response examples for webhooks', () => {
20+
const content = fs.readFileSync(yamlPath, 'utf8');
21+
expect(content).toContain('Register a webhook for API and balance events');
22+
expect(content).toContain('Successfully registered');
23+
expect(content).toContain('Webhook config');
24+
expect(content).toContain('No webhook registered');
25+
expect(content).toContain('new_api_call');
26+
expect(content).toContain('low_balance_alert');
27+
});
28+
});

0 commit comments

Comments
 (0)