从 rails 模型 (class) 上的 Ruby 生成 JSON 模式

Generating a JSON schema from a Ruby on rails model (class)

有用于从 Ruby 实例(例如 jbuilder)生成 json 的 gem 和用于从 json 模式构建 Ruby 模型的 gem。有没有做相反的事情?也就是说,从现有模型生成 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