data
validation_error
ai_generated
true
由于大小写敏感不匹配,JSON Schema枚举验证失败
JSON Schema enum validation fails due to case sensitivity mismatch
ID: data/json-schema-enum-case
90%修复率
82%置信度
1证据数
2023-08-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| JSON Schema Draft 2020-12 | active | — | — | — |
| Ajv 8.12.0 | active | — | — | — |
| Python jsonschema 4.17.0 | active | — | — | — |
根因分析
JSON Schema枚举验证默认区分大小写,但输入数据可能包含不同大小写的值(例如'Active' vs 'active'),导致拒绝。
English
JSON Schema enum validation is case-sensitive by default, but input data may contain values with different casing (e.g., 'Active' vs 'active'), causing rejection.
官方文档
https://json-schema.org/understanding-json-schema/reference/generic.html#enum解决方案
-
Normalize input data to match enum casing before validation: data['status'] = data['status'].lower(); then validate against enum ['active', 'inactive']
-
Expand enum to include all case variants: "enum": ["Active", "active", "ACTIVE"]
无效尝试
常见但无效的做法:
-
Adding 'caseInsensitive': true to the schema definition
85% 失败
JSON Schema does not support case-insensitive enum matching natively; custom keywords may not be portable.
-
Using pattern validation with regex for each enum value
70% 失败
This only works in specific validators and is not standard JSON Schema.