Skip to content

Commit 2c444bf

Browse files
Copilothotlong
andcommitted
Use Zod schema validation instead of type assertion for runtime safety
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent b5bc43b commit 2c444bf

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

packages/core/src/api-registry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
ApiDiscoveryQuery,
88
ApiDiscoveryResponse,
99
} from '@objectstack/spec/api';
10+
import { ApiRegistryEntrySchema } from '@objectstack/spec/api';
1011
import type { Logger } from '@objectstack/spec/contracts';
1112

1213
/**
@@ -80,8 +81,8 @@ export class ApiRegistry {
8081
throw new Error(`[ApiRegistry] API '${api.id}' already registered`);
8182
}
8283

83-
// Cast to full type after validation
84-
const fullApi = api as ApiRegistryEntry;
84+
// Parse and validate the input using Zod schema
85+
const fullApi = ApiRegistryEntrySchema.parse(api);
8586

8687
// Validate and register endpoints
8788
for (const endpoint of fullApi.endpoints) {

0 commit comments

Comments
 (0)