有用于从 Ruby 实例(例如 jbuilder)生成 json 的 gems 和用于从 json 模式构建 Ruby 模型的 gems。有没有做相反的事情?也就是说,从现有模型生成 json schema?
我想从一个模型开始:
class Example
{ firstName: string,
lastName: string,
id: integer }
end
到模式
{
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"id": {
"type": "integer",
}
}
}
这个问题大约在 6 年前提出,但从未回答:How can I export a rails model to json schema?
最佳答案
我不知道它是否足以满足您的需求,但有一个 gem 可以做类似的事情:https://github.com/salesking/json_schema_builder
关于json - 从 Ruby on Rails 模型(类)生成 JSON 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39298184/