# JSON Schema 验证失败：format 'uri' 拒绝包含 IP 地址或非常见协议的合法 URI

- **ID:** `data/json-schema-format-uri-referencing`
- **领域:** data
- **类别:** validation_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

某些库（如 Python 的 jsonschema）中 JSON Schema 内置的 'uri' 格式验证器使用严格的 RFC 3986 解析，可能拒绝包含 IPv6 字面量或自定义方案（如 'dns://'）的合法 URI。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| jsonschema 4.17.3 | active | — | — |
| ajv 8.12.0 | active | — | — |
| json-schema-validator 4.0.1 | active | — | — |

## 解决方案

1. ```
   Use a custom format checker with relaxed URI validation: from jsonschema import validators; from rfc3986_validator import validate_rfc3986; def custom_uri(instance): return validate_rfc3986(instance, require_scheme=True, allow_relative=False); validator = validators.validate(..., format_checker=validators.Draft7Validator.FORMAT_CHECKER.replaces('uri', custom_uri))
   ```
2. ```
   Change schema to use pattern validation instead of format: '"pattern": "^[a-zA-Z][a-zA-Z0-9+.-]*://.*$"'. This is more portable across validators.
   ```

## 无效尝试

- **** — Completely bypasses URI validation, allowing invalid URIs through and defeating the purpose of schema validation. (60% 失败率)
- **** — uri-reference is even more permissive and may not catch intended validation issues, plus it's not supported by all validators. (55% 失败率)
