Skip to content

Commit 4e39fd8

Browse files
committed
Add UnparseableSchemaError
1 parent af489b8 commit 4e39fd8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/lib/schema.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import type { ZodTypeAny } from 'zod'
88

9+
import { isZodObject } from './zod.js'
10+
911
type ValueType =
1012
| 'string'
1113
| 'number'
@@ -18,6 +20,18 @@ interface ParamSchema {
1820
[key: string]: ParamSchema | ValueType
1921
}
2022

21-
export const zodSchemaToParamSchema = (_schema: ZodTypeAny): ParamSchema => {
23+
export const zodSchemaToParamSchema = (schema: ZodTypeAny): ParamSchema => {
24+
if (!isZodObject(schema)) {
25+
throw new UnparseableSchemaError(
26+
'top level schema must be an object schema',
27+
)
28+
}
2229
return {}
2330
}
31+
32+
export class UnparseableSchemaError extends Error {
33+
constructor(message: string) {
34+
super(`Could not parse Zod schema: ${message}`)
35+
this.name = this.constructor.name
36+
}
37+
}

0 commit comments

Comments
 (0)