Inaccurate error message while using "unevaluatedProperties": False

未关闭
#1,169 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 6 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
testing-qa

调研方向

首先,在当前的 jsonschema 测试设置下,使用 issue 中的 schema 和数据重现报告的验证问题。跟踪 unevaluatedProperties 的处理,并为嵌套的 state.cc 情况添加回归测试;当报告的未评估属性与实际失败的属性匹配,且不破坏成功情况时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Enhancement Error Reporting

I am using jsonschema to validate JSON data against a schema using "unevaluatedProperties": False. When my data contains an unexpected property, the error message lists all the evaluated properties as unexpected, instead of the actual unevaluated property.

Here is a schema as an example:

{
  "allOf": [
    {
      "properties": {
        "street_address": { "type": "string" },
        "city":           { "type": "string" },
        "state":          { 
          "type": "object",
          "properties": {
            "name": { "type": "string" },
          },
          "additionalProperties": False
        }
      }
    },
    {
      "properties": {
        "type":  { "type": "string" },
      }
    }
  ],
  "type": "object",
  "unevaluatedProperties": False
}

And here is a json data:

{
  "street_address": "21 2nd Street",
  "city": "New York",
  "state": {"name": "NY", "cc": "Unexpected field"},
  "type": "home"
}

In this case, 'cc' under 'state' is unexpected. If I remove 'cc', the validation is successful. However, the error message reported by jsonschema is: jsonschema.exceptions.ValidationError: Unevaluated properties are not allowed ('city', 'state', 'street_address' were unexpected).

My questions are:

Why is the error message not mentioning 'cc', the actual cause of the error?
Are there any better ways to provide compatibility with the unevaluatedProperties keyword that could help us identify the specific unevaluated properties?
Please let me know if you need additional details.

Information about my current environment:

Python version: 3.7.16
jsonschema version: 4.16.0
Thanks in advance for your help.

主要语言
Python
星标
5k
派生
741
平均合并
4 天 17 小时
30 天内合并 PR
6

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-jsonschema/jsonschema 的其他 Issue

查看 python-jsonschema/jsonschema 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。