【发布时间】:2021-07-19 20:34:53
【问题描述】:
我正在寻找一个用于从 python 字典生成 json_schema 的 python 库
例如这本词典
fields = {
"field1": {"title": "Field1 Title", "type": "string"},
"field2": {"title": "Field2 Title", "type": "integer"},
"field3": {"title": "Field3 Title", "type": "numeric", "description": "description", "multipleOf": 0.01},
}
应该处理到下一个json_schema:
{
"title": "",
"type": "object",
"properties": {
"field1": {
"title": "Field1 Title",
"type": "string"
},
"field2": {
"title": "Field2 Title",
"type": "integer"
},
"field3": {
"title": "Field3 Title",
"description": "description",
"type": "numeric",
"multipleOf": 0.01,
}
},
"required": ["field1", "field2"]
}
【问题讨论】:
-
Python 是一种动态语言,因此将第一个数据结构转换为第二个数据结构非常简单。
-
您可能希望为此进行自定义键、值映射,因为在您的情况下它不是 1:1 映射。请参考此线程的答案:stackoverflow.com/questions/26745519/…
标签: python json jsonschema json-schema-validator python-jsonschema