json - 给定方法和类型的 JSON 规范作为输入,如何生成 Ruby 代码?
问题描述
这是类型和方法的定义
精简版
{
"name": "Abi",
"type": "EnumOfTypes",
"enum_types": [
{
"name": "Contract",
"type": "Struct",
"struct_fields": [
{
"name": "value",
"type": "Ref",
"ref_name": "abi.AbiContract",
"summary": null,
"description": null
}
],
"summary": null,
"description": null
},
{
"name": "Json",
"type": "Struct",
"struct_fields": [
{
"name": "value",
"type": "String",
"summary": null,
"description": null
}
],
"summary": null,
"description": null
},
粘贴箱:
JSON 文档经常更改。目前 Ruby 的类、类型、方法……都是手工编写的,并且也是手工更新的。
我已经尝试了 1-2 个 Ruby 代码生成器,但它们都没有工作。是否有一个体面的 Ruby 代码生成器能够处理这个文档并且生成足够高效和简单的代码?代码应该没有任何额外的依赖或复杂的不必要的类、结构......
或者,简而言之,我如何自己编写一个简单的生成器?困难在于 Ruby 是动态类型语言。
解决方案
推荐阅读
- python - 基于列的numpy过滤矩阵
- postgresql - 无法连接服务器,超时过期到 Postgres RDS
- javascript - 为什么 react 不更新 setState 中的样式?
- full-text-search - 狮身人面像搜索结果页面未显示小节
- php - 不断收到此消息: preg_replace(): Compilation failed: quantifier does not follow a repeatable item at offset 2
- printing-web-page - 我应该如何修改网站以在当前浏览器中打印
- javascript - 如何在 Vue 3 中以编程方式创建组件实例?
- javascript - 如何从 index.html 自定义元素标签接收数组作为@Input?
- tcl - TCL如何去掉部分文件名
- java - 反应式编程 - Webflux Webfilter 行为不正常