动态JSON模式验证
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
andexpectations
keys must be presentsql
should be a text string- At least one item in
expectations
.项目键应该是唯一的。 - Within
expectations
, item keys must be equal to available methods provided bydir(class_name)
More advanced capability would include:
- Enforcing
expectations
method items to only includekwargs
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
andexpectations
keys must be presentsql
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 bydir(class_name)
More advanced capability would include:
- Enforcing
expectations
method items to only includekwargs
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论