Allow "required" list to have undefined properties

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

还没有人认领这个 Issue。

评估

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

调研方向

Start in openapi_spec_validator/validators.py around the require_properties argument and the linked validation block, then read tests/integration/test_validators.py around the existing case. Check the relevant OpenAPI and JSON Schema behavior before deciding the expected result; done means the validator and integration tests consistently accept or reject the undefined required properties case.

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

描述

I think requiring property names listed in required to be defined in properties is too strict. I also couldn't find this requirement in the JSON Schema or OpenAPI specs. JSON Schema validators and the Swagger Editor are fine with property names listed in required that are not defined in properties.

It makes sense to list required properties without defining them in properties when using allOf where one sub-schema requires some properties but does not specify them while another sub-schema only provides the specifications of the properties (possibly even without stating which ones are required and which ones aren't). This is especially useful when referencing and merging schema definitions or when expressing discriminated unions with some properties that are common to all union members.

I suggest to remove the following code block

https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/openapi_spec_validator/validators.py#L134-L142

and the require_properties argument:

https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/openapi_spec_validator/validators.py#L123

I have seen the test case

https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/tests/integration/test_validators.py#L83-L115

but it also seems to be valid to express this schema like this:

{
    'Credit': {
        'type': 'object',
        'properties': {
            'clientId': {'type': 'string'},
        }
    },
    'CreditCreate': {
        'type': 'object',
        'required': ['clientId'],
        'allOf': [
            {
                '$ref': '#/components/schemas/Credit'
            },
            # possibly more schemas to merge ...
        ]
    }
}

Or did I miss this rule somewhere in the spec?

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

贡献指南

打开贡献指南

从这里开始

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

python-openapi/openapi-spec-validator 的其他 Issue

查看 python-openapi/openapi-spec-validator 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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