# JSON Schema 验证失败：format 'uri-reference' 拒绝有效的相对 URI

- **ID:** `data/json-schema-format-uri-reference`
- **领域:** data
- **类别:** schema_error
- **错误码:** `ValidationError`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

JSON Schema 验证器使用不同的 'uri-reference' 格式实现；一些应用严格的 RFC 3986 解析，拒绝没有 scheme 的相对 URI。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| JSON Schema Draft 7+ | active | — | — |
| ajv 8.12.0+ | active | — | — |
| jsonschema 4.18.0+ (Python) | active | — | — |
| json-schema-validator 4.0.0+ (Java) | active | — | — |

## 解决方案

1. ```
   使用自定义格式验证器接受相对 URI：`ajv.addFormat('uri-reference', { validate: (s) => /^[\w\/:.?&=#-]+$/.test(s) })`
   ```
2. ```
   在验证前预处理数据，通过添加基础 URL 将相对 URI 转换为绝对 URI。
   ```
3. ```
   切换到使用更宽松的 uri-reference 实现的验证器，如 `@cfworker/json-schema`。
   ```

## 无效尝试

- **** — 'uri' format is stricter and requires absolute URIs with scheme, rejecting relative paths. (80% 失败率)
- **** — Weakens schema constraints and may allow invalid data to pass validation. (50% 失败率)
