json - 从 Ruby on Rails 模型(类)生成 JSON 模式

标签 json ruby jsonschema

有用于从 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/

相关文章:

java - 正则表达式在 Java 中转义 Json 值中的双引号

json - 如何解析/反序列化动态 JSON

javascript - 如何在 Rails 中使用带有 anchor 的 Ajax 链接

json - 如何在代码中定义包含定义的Json Schema

java - JSON 架构引用

Ruby On Rails 和 VIM

ruby-on-rails - Rails 友好 ID : slug is not generated on model. 新或 model.import

JSON 架构 : Can we do an either/or (string/int) for type?

python - JSON 架构 : Validate that exactly one property is present

javascript - Electron 快速启动应用程序不工作