JsonSchemaFormatValidationError
data
schema_error
ai_generated
true
JSON Schema validation fails: format 'iri-reference' is not recognized
ID: data/json-schema-format-iri-reference
82%Fix Rate
88%Confidence
1Evidence
2023-11-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| JSON Schema 2020-12 | active | — | — | — |
| ajv 8.12+ | active | — | — | — |
| jsonschema 4.20+ | active | — | — | — |
| OpenAPI 3.1 | active | — | — | — |
Root Cause
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.
generic中文
JSON Schema规范将 'iri-reference' 定义为需要选择性加入验证的格式;许多验证器(如旧版ajv或jsonschema)默认不支持它。
Official Documentation
https://json-schema.org/understanding-json-schema/reference/string.html#formatWorkarounds
-
90% success Enable format validation explicitly in the validator. For ajv: `const ajv = new Ajv({ formats: { 'iri-reference': true } });` or use `ajv-formats` plugin: `import addFormats from 'ajv-formats'; addFormats(ajv, ['iri-reference']);`
Enable format validation explicitly in the validator. For ajv: `const ajv = new Ajv({ formats: { 'iri-reference': true } });` or use `ajv-formats` plugin: `import addFormats from 'ajv-formats'; addFormats(ajv, ['iri-reference']);` -
75% success Replace 'iri-reference' with a custom regex pattern in the schema: `"pattern": "^[a-zA-Z][a-zA-Z0-9+.-]*:.*$"` to approximate IRI-reference validation.
Replace 'iri-reference' with a custom regex pattern in the schema: `"pattern": "^[a-zA-Z][a-zA-Z0-9+.-]*:.*$"` to approximate IRI-reference validation.
-
80% success Use a validator that natively supports 'iri-reference', such as `@cfworker/json-schema` version 2.0+ or `jsonschema` with the `rfc3987` package installed.
Use a validator that natively supports 'iri-reference', such as `@cfworker/json-schema` version 2.0+ or `jsonschema` with the `rfc3987` package installed.
中文步骤
在验证器中显式启用格式验证。对于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`。
Dead Ends
Common approaches that don't work:
-
60% fail
This bypasses validation for all formats, potentially allowing invalid data that should be caught by other format checks.
-
85% fail
'iri-reference' allows relative IRIs and fragment-only IRIs, which 'uri' does not. This will reject valid data.
-
70% fail
Format validation is often disabled by default; upgrading alone does not enable it.