Skip to content

Commit 8030ca6

Browse files
authored
Merge pull request #621 from objectstack-ai/copilot/fix-discovery-api-endpoint
2 parents ea27bc9 + cbfa464 commit 8030ca6

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

packages/rest/src/rest-server.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ export class RestServer {
216216
* Register discovery endpoints
217217
*/
218218
private registerDiscoveryEndpoints(basePath: string): void {
219-
this.routeManager.register({
220-
method: 'GET',
221-
path: basePath,
222-
handler: async (_req: any, res: any) => {
219+
const discoveryHandler = async (_req: any, res: any) => {
223220
try {
224221
const discovery = await this.protocol.getDiscovery();
225222

@@ -250,7 +247,24 @@ export class RestServer {
250247
} catch (error: any) {
251248
res.status(500).json({ error: error.message });
252249
}
250+
};
251+
252+
// Register at basePath (e.g. /api/v1)
253+
this.routeManager.register({
254+
method: 'GET',
255+
path: basePath,
256+
handler: discoveryHandler,
257+
metadata: {
258+
summary: 'Get API discovery information',
259+
tags: ['discovery'],
253260
},
261+
});
262+
263+
// Register at basePath/discovery (e.g. /api/v1/discovery)
264+
this.routeManager.register({
265+
method: 'GET',
266+
path: `${basePath}/discovery`,
267+
handler: discoveryHandler,
254268
metadata: {
255269
summary: 'Get API discovery information',
256270
tags: ['discovery'],

packages/rest/src/rest.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ describe('RestServer', () => {
309309

310310
// Expect at least discovery + metadata + CRUD routes
311311
const paths = routes.map((r) => r.path);
312-
// Discovery
312+
// Discovery (both basePath and basePath/discovery)
313313
expect(paths).toContain('/api/v1');
314+
expect(paths).toContain('/api/v1/discovery');
314315
// Metadata
315316
expect(paths.some((p) => p.includes('/meta'))).toBe(true);
316317
// CRUD
@@ -356,7 +357,7 @@ describe('RestServer', () => {
356357
rest.registerRoutes();
357358

358359
const routes = rest.getRoutes();
359-
// Discovery route is the basePath itself (e.g. /api/v1)
360+
// Neither basePath nor basePath/discovery should be registered
360361
const discoveryRoutes = routes.filter((r) =>
361362
r.metadata?.tags?.includes('discovery'),
362363
);

packages/runtime/src/dispatcher-plugin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export function createDispatcherPlugin(config: DispatcherPluginConfig = {}): Plu
9191
res.json({ data: dispatcher.getDiscoveryInfo(prefix) });
9292
});
9393

94+
// ── Discovery (versioned API path) ──────────────────────────
95+
server.get(`${prefix}/discovery`, async (_req: any, res: any) => {
96+
res.json({ data: dispatcher.getDiscoveryInfo(prefix) });
97+
});
98+
9499
// ── Auth ────────────────────────────────────────────────────
95100
server.post(`${prefix}/auth/login`, async (req: any, res: any) => {
96101
try {

0 commit comments

Comments
 (0)