Canonicalise `oneOf` sub-schemas to exclude shared types

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

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
data, testing

调研方向

Start with the not sub-schema handling and the referenced test case in tests/test_from_schema.py; the corpus example is in tests/corpus-suite-schemas.json. Compare canonicalising oneOf branches to include type: object with lowering oneOf to anyOf using not. Done means the supplied case generates values without excessive filtering and the tests catch plausible semantic mistakes.

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

描述

Consider the schema {"oneOf": [{"required": ["foo"]}, {"required": ["bar"]}]}

What values could match this? Because the two sub-schemas only constrain objects, all values of any other type will be valid against both sub-schemas... and therefore invalid against the oneOf schema.

This tends to result in a lot of filtering, so we have a workaround in our tests for this test case.

Obviously it would be nicer to support such schemas properly, by canonicalising them to include type: object (i.e. exclude other types) and therefore translate them to a Hypothesis strategy which doesn't have to filter out so much.

The semantics are a bit too tricky for me to tag this good first issue, though the tests will catch any plausible mistakes you could make. We have some prior art in the handling of "not" sub-schemas, which might provide a good starting point; you might even move shared logic to a new helper function.

Alternatively, 'lowering' oneOf: [a, b, c] to anyOf: [{**a, not: {anyOf: [b, c]}}, ...] would automatically share any improvements to not-logic, which would be nice. Just a question of balancing that against the less elegant canonical form.

主要语言
Python
星标
281
派生
35
PR 合并指标
30 天内没有已合并 PR

环境准备

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

从这里开始

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

python-jsonschema/hypothesis-jsonschema 的其他 Issue

查看 python-jsonschema/hypothesis-jsonschema 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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