(ref: string, ctx: ConversionContext)
| 119 | } |
| 120 | |
| 121 | function resolveRef(ref: string, ctx: ConversionContext): JSONSchema.JSONSchema { |
| 122 | if (!ref.startsWith("#")) { |
| 123 | throw new Error("External $ref is not supported, only local refs (#/...) are allowed"); |
| 124 | } |
| 125 | |
| 126 | const path = ref.slice(1).split("/").filter(Boolean); |
| 127 | |
| 128 | // Handle root reference "#" |
| 129 | if (path.length === 0) { |
| 130 | return ctx.rootSchema; |
| 131 | } |
| 132 | |
| 133 | const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions"; |
| 134 | |
| 135 | if (path[0] === defsKey) { |
| 136 | const key = path[1]; |
| 137 | if (!key || !ctx.defs[key]) { |
| 138 | throw new Error(`Reference not found: ${ref}`); |
| 139 | } |
| 140 | return ctx.defs[key]!; |
| 141 | } |
| 142 | |
| 143 | throw new Error(`Reference not found: ${ref}`); |
| 144 | } |
| 145 | |
| 146 | function convertBaseSchema(schema: JSONSchema.JSONSchema, ctx: ConversionContext): ZodType { |
| 147 | // Handle unsupported features |
no test coverage detected