data validation_error ai_generated true

由于大小写敏感不匹配,JSON Schema枚举验证失败

JSON Schema enum validation fails due to case sensitivity mismatch

ID: data/json-schema-enum-case

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

https://json-schema.org/understanding-json-schema/reference/generic.html#enum

解决方案

  1. Normalize input data to match enum casing before validation: data['status'] = data['status'].lower(); then validate against enum ['active', 'inactive']
  2. Expand enum to include all case variants: "enum": ["Active", "active", "ACTIVE"]

无效尝试

常见但无效的做法:

  1. Adding 'caseInsensitive': true to the schema definition 85% 失败

    JSON Schema does not support case-insensitive enum matching natively; custom keywords may not be portable.

  2. Using pattern validation with regex for each enum value 70% 失败

    This only works in specific validators and is not standard JSON Schema.