# JSON Schema验证失败：格式 'iri-reference' 未被识别

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

## 根因

JSON Schema规范将 'iri-reference' 定义为需要选择性加入验证的格式；许多验证器（如旧版ajv或jsonschema）默认不支持它。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| JSON Schema 2020-12 | active | — | — |
| ajv 8.12+ | active | — | — |
| jsonschema 4.20+ | active | — | — |
| OpenAPI 3.1 | active | — | — |

## 解决方案

1. ```
   在验证器中显式启用格式验证。对于ajv：`const ajv = new Ajv({ formats: { 'iri-reference': true } });` 或使用`ajv-formats`插件：`import addFormats from 'ajv-formats'; addFormats(ajv, ['iri-reference']);`
   ```
2. ```
   在模式中将'iri-reference'替换为自定义正则表达式模式：`"pattern": "^[a-zA-Z][a-zA-Z0-9+.-]*:.*$"` 以近似IRI-reference验证。
   ```
3. ```
   使用原生支持'iri-reference'的验证器，例如`@cfworker/json-schema` 2.0+版本或安装了`rfc3987`包的`jsonschema`。
   ```

## 无效尝试

- **** — This bypasses validation for all formats, potentially allowing invalid data that should be caught by other format checks. (60% 失败率)
- **** — 'iri-reference' allows relative IRIs and fragment-only IRIs, which 'uri' does not. This will reject valid data. (85% 失败率)
- **** — Format validation is often disabled by default; upgrading alone does not enable it. (70% 失败率)
