Skip to content

Commit b094520

Browse files
committed
feat: generate WebSocket docs for watch methods
The OpenAPI generator now classifies watch*/unwatch* methods as 'ws' and generates WebSocket transport documentation with connection URLs (local sidecar + hosted API), subscribe/unsubscribe protocol, and JSON message examples. Mintlify renders these automatically.
1 parent 79d8656 commit b094520

4 files changed

Lines changed: 1044 additions & 1845 deletions

File tree

core/scripts/generate-openapi.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,14 @@ function extractParamMeta(method) {
12791279
});
12801280
}
12811281

1282+
const WS_METHODS = new Set([
1283+
'watchOrderBook', 'watchOrderBooks', 'watchAllOrderBooks',
1284+
'watchTrades', 'watchAddress',
1285+
'unwatchOrderBook', 'unwatchAddress',
1286+
]);
1287+
12821288
function classifyVerb(methodName, paramsMeta) {
1289+
if (WS_METHODS.has(methodName)) return 'ws';
12831290
if (!methodName.startsWith('fetch')) return 'post';
12841291
if (paramsMeta.length === 0) return 'get';
12851292
// Reject unknown kinds outright — we can't safely serialise them.
@@ -1387,6 +1394,68 @@ function buildPathSpec(method, sourceFile) {
13871394
const summary = camelToTitle(name);
13881395
const deprecated = isDeprecated(method, sourceFile);
13891396

1397+
// ---- WS: WebSocket streaming method ------------------------------------
1398+
if (verb === 'ws') {
1399+
const wsDescription = [
1400+
description || summary,
1401+
'',
1402+
'**Transport:** WebSocket',
1403+
'',
1404+
'| Environment | URL |',
1405+
'|---|---|',
1406+
'| Local sidecar | `ws://localhost:3847/ws` |',
1407+
'| Hosted API | `wss://api.pmxt.dev/ws?apiKey=YOUR_KEY` |',
1408+
'',
1409+
'**Subscribe:**',
1410+
'```json',
1411+
`{ "id": "req-1", "action": "subscribe", "method": "${name}", "args": [...] }`,
1412+
'```',
1413+
'',
1414+
'**Server response:**',
1415+
'```json',
1416+
'{ "event": "data", "id": "req-1", "method": "' + name + '", "symbol": "...", "data": { ... } }',
1417+
'```',
1418+
'',
1419+
'**Unsubscribe:**',
1420+
'```json',
1421+
'{ "id": "req-1", "action": "unsubscribe" }',
1422+
'```',
1423+
].join('\n');
1424+
1425+
const pathObj = {
1426+
post: {
1427+
summary: summary + ' (WebSocket)',
1428+
operationId: name,
1429+
parameters: [{ $ref: '#/components/parameters/ExchangeParam' }],
1430+
description: wsDescription,
1431+
requestBody: {
1432+
content: {
1433+
'application/json': {
1434+
schema: {
1435+
title: name.charAt(0).toUpperCase() + name.slice(1) + 'Request',
1436+
type: 'object',
1437+
properties: {
1438+
args: { type: 'array', items: { type: 'string' } },
1439+
credentials: { $ref: '#/components/schemas/ExchangeCredentials' },
1440+
},
1441+
},
1442+
},
1443+
},
1444+
},
1445+
responses: {
1446+
'200': {
1447+
description: `${summary} response (WebSocket data event)`,
1448+
content: {
1449+
'application/json': { schema: responseSchema },
1450+
},
1451+
},
1452+
},
1453+
},
1454+
};
1455+
if (deprecated) pathObj.post.deprecated = true;
1456+
return { name, pathObj, verb, paramsMeta };
1457+
}
1458+
13901459
// ---- GET: query-parameter shape, no request body ----------------------
13911460
if (verb === 'get') {
13921461
const parameters = [{ $ref: '#/components/parameters/ExchangeParam' }];

core/src/server/method-verbs.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
]
296296
},
297297
"watchOrderBook": {
298-
"verb": "post",
298+
"verb": "ws",
299299
"args": [
300300
{
301301
"name": "outcomeId",
@@ -310,7 +310,7 @@
310310
]
311311
},
312312
"watchOrderBooks": {
313-
"verb": "post",
313+
"verb": "ws",
314314
"args": [
315315
{
316316
"name": "outcomeIds",
@@ -325,7 +325,7 @@
325325
]
326326
},
327327
"unwatchOrderBook": {
328-
"verb": "post",
328+
"verb": "ws",
329329
"args": [
330330
{
331331
"name": "outcomeId",
@@ -335,7 +335,7 @@
335335
]
336336
},
337337
"watchTrades": {
338-
"verb": "post",
338+
"verb": "ws",
339339
"args": [
340340
{
341341
"name": "outcomeId",
@@ -360,7 +360,7 @@
360360
]
361361
},
362362
"watchAddress": {
363-
"verb": "post",
363+
"verb": "ws",
364364
"args": [
365365
{
366366
"name": "address",
@@ -375,7 +375,7 @@
375375
]
376376
},
377377
"unwatchAddress": {
378-
"verb": "post",
378+
"verb": "ws",
379379
"args": [
380380
{
381381
"name": "address",

0 commit comments

Comments
 (0)