Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions packages/rest/src/rest-server.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -216,10 +216,7 @@ export class RestServer {
* Register discovery endpoints
*/
private registerDiscoveryEndpoints(basePath: string): void {
this.routeManager.register({
method: 'GET',
path: basePath,
handler: async (_req: any, res: any) => {
const discoveryHandler = async (_req: any, res: any) => {
try {
const discovery = await this.protocol.getDiscovery();

Expand DownExpand Up@@ -250,7 +247,24 @@ export class RestServer {
} catch (error: any) {
res.status(500).json({ error: error.message });
}
};

// Register at basePath (e.g. /api/v1)
this.routeManager.register({
method: 'GET',
path: basePath,
handler: discoveryHandler,
metadata: {
summary: 'Get API discovery information',
tags: ['discovery'],
},
});

// Register at basePath/discovery (e.g. /api/v1/discovery)
this.routeManager.register({
method: 'GET',
path: `${basePath}/discovery`,
handler: discoveryHandler,
metadata: {
summary: 'Get API discovery information',
tags: ['discovery'],
Expand Down
5 changes: 3 additions & 2 deletions packages/rest/src/rest.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -309,8 +309,9 @@ describe('RestServer', () => {

// Expect at least discovery + metadata + CRUD routes
const paths = routes.map((r) => r.path);
// Discovery
// Discovery (both basePath and basePath/discovery)
expect(paths).toContain('/api/v1');
expect(paths).toContain('/api/v1/discovery');
// Metadata
expect(paths.some((p) => p.includes('/meta'))).toBe(true);
// CRUD
Expand DownExpand Up@@ -356,7 +357,7 @@ describe('RestServer', () => {
rest.registerRoutes();

const routes = rest.getRoutes();
// Discovery route is the basePath itself (e.g. /api/v1)
// Neither basePath nor basePath/discovery should be registered
const discoveryRoutes = routes.filter((r) =>
r.metadata?.tags?.includes('discovery'),
);
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime/src/dispatcher-plugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,11 @@ export function createDispatcherPlugin(config: DispatcherPluginConfig = {}): Plu
res.json({ data: dispatcher.getDiscoveryInfo(prefix) });
});

// ── Discovery (versioned API path) ──────────────────────────
server.get(`${prefix}/discovery`, async (_req: any, res: any) => {
res.json({ data: dispatcher.getDiscoveryInfo(prefix) });
});
Comment on lines +95 to +97

CopilotAIFeb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added ${prefix}/discovery route in createDispatcherPlugin isn't covered by tests. Since packages/runtime already has Vitest coverage for runtime/dispatcher behavior, please add a unit test that starts the plugin against a mocked IHttpServer and asserts the discovery route is registered (and, ideally, that it doesn’t conflict when @objectstack/rest is also present).

Copilot uses AI. Check for mistakes.
Comment on lines +95 to +97

CopilotAIFeb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createDispatcherPlugin now registers GET ${prefix}/discovery, but @objectstack/rest (RestServer) also registers GET /api/v1/discovery. In the default stacks (e.g. CLI serve and DevPlugin) both plugins are enabled, so this will double-register the same method/path on the same IHttpServer, which can cause route conflicts (some servers throw on duplicates, others have precedence rules) and can return a different payload shape than RestServer (Dispatcher returns HttpDispatcher.getDiscoveryInfo(...), RestServer returns protocol.getDiscovery()). Consider avoiding duplicate registration when com.objectstack.rest.api is present (e.g. via ctx.getKernel().getPlugins()), or make this handler delegate to the protocol discovery response to keep the payload consistent.

Copilot uses AI. Check for mistakes.

// ── Auth ────────────────────────────────────────────────────
server.post(`${prefix}/auth/login`, async (req: any, res: any) => {
try {
Expand Down
Loading