动态JSON模式验证

发布于 2025-01-22 03:12:25 字数 2418 浏览 2 评论 0原文

In Python 3.8, I'm trying to mock up a validation JSON schema for the structure below:

{
    # some other key/value pairs
    "data_checks": {
        "check_name": {
            "sql": "SELECT col FROM blah",
            "expectations": {
                "expect_column_values_to_be_unique": {
                    "column": "col",
                },
                # additional items as required
            }
        },
        # additional items as required
    }
}

The requirements I'm trying to enforce include:

  • At least one item in data_checks that can have a dynamic name.项目键应该是唯一的。
  • sql and expectations keys must be present
  • sql should be a text string
  • At least one item in expectations.项目键应该是唯一的。
  • Within expectations, item keys must be equal to available methods provided by dir(class_name)

More advanced capability would include:

  • Enforcing expectations method items to only include kwargs for that method

I currently have the following JSON schema for the data_checks portion:

"data_checks": {
    "description": "Data quality checks against provided sources.",
    "minProperties": 1,
    "type": "object",
    "patternProperties": {
        ".+": {
            "required": ["expectations", "sql"],
            "sql": {
                "description": "SQL for data quality check.",
                "minLength": 1,
                "type": "string",
            },
            "expectations": {
                "description": "Great Expectations function name.",
                "minProperties": 1,
                "type": "object",
                "anyOf": [
                    {
                        "type": "string",
                        "minLength": 1,
                        "pattern": [e for e in dir(SqlAlchemyDataset) if e.startswith("expect_")],
                    }
                ],
            },
        },
    },
},

This JSON schema does not enforce expectations to have at least one如果E.StartSwith(“ Expect _”),则项目也不是for e in dir(sqlalchemydataset)中预期的嵌套键的有效方法名称。我并没有真正考虑为所选方法执行kwargs(甚至可能吗?)。

我不知道这是否与嵌套的事物有关,但是如何执行适当的验证要求?

谢谢!

In Python 3.8, I'm trying to mock up a validation JSON schema for the structure below:

{
    # some other key/value pairs
    "data_checks": {
        "check_name": {
            "sql": "SELECT col FROM blah",
            "expectations": {
                "expect_column_values_to_be_unique": {
                    "column": "col",
                },
                # additional items as required
            }
        },
        # additional items as required
    }
}

The requirements I'm trying to enforce include:

  • At least one item in data_checks that can have a dynamic name. Item keys should be unique.
  • sql and expectations keys must be present
  • sql should be a text string
  • At least one item in expectations. Item keys should be unique.
  • Within expectations, item keys must be equal to available methods provided by dir(class_name)

More advanced capability would include:

  • Enforcing expectations method items to only include kwargs for that method

I currently have the following JSON schema for the data_checks portion:

"data_checks": {
    "description": "Data quality checks against provided sources.",
    "minProperties": 1,
    "type": "object",
    "patternProperties": {
        ".+": {
            "required": ["expectations", "sql"],
            "sql": {
                "description": "SQL for data quality check.",
                "minLength": 1,
                "type": "string",
            },
            "expectations": {
                "description": "Great Expectations function name.",
                "minProperties": 1,
                "type": "object",
                "anyOf": [
                    {
                        "type": "string",
                        "minLength": 1,
                        "pattern": [e for e in dir(SqlAlchemyDataset) if e.startswith("expect_")],
                    }
                ],
            },
        },
    },
},

This JSON schema does not enforce expectations to have at least one item nor does it enforce valid method names for the nested keys as expected from [e for e in dir(SqlAlchemyDataset) if e.startswith("expect_")]. I haven't really looked into enforcing kwargs for the selected method (is that even possible?).

I don't know if this is related to things being nested, but how would I enforce the proper validation requirements?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文