使用 json-forms 生成你的配置
在使用 json 格式存储配置的时候,总是需要在管理后台写一堆代码,去校验参数是否合法,防止用户乱写。
最近发现了一个超级好用的工具,可以把开发人员从这个繁琐的工作中解脱出来。
那就是 json-forms,可以使用 json schema 自动生成表单,方便的一塌糊涂。
这是它的demo地址
http://brutusin.org/json-forms/
示例 json schema 代码
{ "$schema": "http://json-schema.org/draft-03/schema#", "type": "object", "properties": { "species": { "title": "Species supported", "description": "Changes in this property (`$.species`) trigger the resolution of the actual (depending on the values being selected) schema of a dependent property (`$.subspecies`)", "type": "string", "enum": [ "human", "dog", "cat" ], "required": true }, "subspecies": { "dependsOn": [ "species" ] } } }
表单截图
这是两个在线工具,可以直接将 json 转成 json schema
http://yapi.demo.qunar.com/editor/ # 推荐 https://jsonschema.net/
我们只需要将 json-forms 嵌入到我们的代码中,就可以使用这个简单高效的工具了。
更多架构、PHP、GO相关踩坑实践技巧请关注我的公众号:PHP架构师
原文地址:https://my.oschina.net/u/222608/blog/1934514