将棒棒糖架构转换为json架构的库
lollipop-jsonschema的Python项目详细描述
要转换的库Lollipop schema 到JSON schema。
示例
importlollipop.typesasltimportlollipop.validatorsaslvEMAIL_REGEXP=r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"USER=lt.Object({'name':lt.String(validate=lv.Length(min=1)),'email':lt.String(validate=lv.Regexp(EMAIL_REGEXP)),'age':lt.Optional(lt.Integer(validate=lv.Range(min=18))),},name='User',description='User information')fromlollipop_jsonschemaimportjson_schemaimportjsonprintjson.dumps(json_schema(USER),indent=2)# {# "title": "User",# "description": "User information",# "type": "object",# "properties": {# "age": {# "type": "integer",# "minimum": 18# },# "name": {# "type": "string",# "minLength": 1# },# "email": {# "type": "string",# "pattern": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$"# }# },# "required": [# "name",# "email"# ]# }
安装
$ pip install lollipop-jsonschema
要求
- python>;=2.7和<;=3.6
- lollipop>;=1.1.5
项目链接
许可证
麻省理工学院许可。有关详细信息,请参见捆绑的LICENSE文件。