将JSON模式转换为Pydantic模型
项目描述
jsonschema-pydantic
简单的jsonschema到Pydantic模型的转换。
支持的jsonschema功能
- 原始类型
- 对象
- 数组
- 嵌套对象
- 可选字段
- 默认值
安装
pip install jsonschema-pydantic
使用方法
from jsonschema_pydantic import jsonschema_to_pydantic
jsonschema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
},
"required": ["name"],
}
pydantic_model = jsonschema_to_pydantic(jsonschema)
开发
运行pytest测试套件
make test
代码风格检查
运行所有代码风格检查工具
make lint
格式化
格式化Python代码
make fmt
文档
生成文档
make docs
贡献
阅读CONTRIBUTING.md文件。