ValidationError
data
schema_error
ai_generated
true
JSON Schema 验证失败:format 'uri-reference' 拒绝有效的相对 URI
JSON Schema validation fails: format 'uri-reference' rejects valid relative URIs
ID: data/json-schema-format-uri-reference
90%修复率
87%置信度
1证据数
2023-09-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| JSON Schema Draft 7+ | active | — | — | — |
| ajv 8.12.0+ | active | — | — | — |
| jsonschema 4.18.0+ (Python) | active | — | — | — |
| json-schema-validator 4.0.0+ (Java) | active | — | — | — |
根因分析
JSON Schema 验证器使用不同的 'uri-reference' 格式实现;一些应用严格的 RFC 3986 解析,拒绝没有 scheme 的相对 URI。
English
JSON Schema validators use different implementations of the 'uri-reference' format; some apply strict RFC 3986 parsing that rejects relative URIs without a scheme.
官方文档
https://json-schema.org/understanding-json-schema/reference/string.html#format解决方案
-
使用自定义格式验证器接受相对 URI:`ajv.addFormat('uri-reference', { validate: (s) => /^[\w\/:.?&=#-]+$/.test(s) })` -
在验证前预处理数据,通过添加基础 URL 将相对 URI 转换为绝对 URI。
-
切换到使用更宽松的 uri-reference 实现的验证器,如 `@cfworker/json-schema`。
无效尝试
常见但无效的做法:
-
80% 失败
'uri' format is stricter and requires absolute URIs with scheme, rejecting relative paths.
-
50% 失败
Weakens schema constraints and may allow invalid data to pass validation.