JsonSchemaFormatValidationError
data
schema_error
ai_generated
true
JSON Schema验证失败:格式 'iri-reference' 未被识别
JSON Schema validation fails: format 'iri-reference' is not recognized
ID: data/json-schema-format-iri-reference
82%修复率
88%置信度
1证据数
2023-11-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| JSON Schema 2020-12 | active | — | — | — |
| ajv 8.12+ | active | — | — | — |
| jsonschema 4.20+ | active | — | — | — |
| OpenAPI 3.1 | active | — | — | — |
根因分析
JSON Schema规范将 'iri-reference' 定义为需要选择性加入验证的格式;许多验证器(如旧版ajv或jsonschema)默认不支持它。
English
The JSON Schema specification defines 'iri-reference' as a format that requires opt-in validation; many validators (e.g., older versions of ajv or jsonschema) do not support it by default.
官方文档
https://json-schema.org/understanding-json-schema/reference/string.html#format解决方案
-
在验证器中显式启用格式验证。对于ajv:`const ajv = new Ajv({ formats: { 'iri-reference': true } });` 或使用`ajv-formats`插件:`import addFormats from 'ajv-formats'; addFormats(ajv, ['iri-reference']);` -
在模式中将'iri-reference'替换为自定义正则表达式模式:`"pattern": "^[a-zA-Z][a-zA-Z0-9+.-]*:.*$"` 以近似IRI-reference验证。
-
使用原生支持'iri-reference'的验证器,例如`@cfworker/json-schema` 2.0+版本或安装了`rfc3987`包的`jsonschema`。
无效尝试
常见但无效的做法:
-
60% 失败
This bypasses validation for all formats, potentially allowing invalid data that should be caught by other format checks.
-
85% 失败
'iri-reference' allows relative IRIs and fragment-only IRIs, which 'uri' does not. This will reject valid data.
-
70% 失败
Format validation is often disabled by default; upgrading alone does not enable it.