Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export a rails model to json schema?

I am looking to optimize how we build forms for some of our models and ideally I would like to build them from json-schema.

Is there a gem or the like which would allow me to export a model definition to json-schema?

Bonus: With validations.

Bonus: While modelling association relationships.

like image 612
unomi Avatar asked Jun 18 '10 10:06

unomi


People also ask

What is the difference between JSON and JSON schema?

JSON (JavaScript Object Notation) is a simple and lightweight text-based data format. JSON Schema is an IETF standard providing a format for what JSON data is required for a given application and how to interact with it.

How do you reference a JSON schema?

In a JSON schema, a $ref keyword is a JSON Pointer to a schema, or a type or property in a schema. A JSON pointer takes the form of A # B in which: A is the relative path from the current schema to a target schema. If A is empty, the reference is to a type or property in the same schema, an in-schema reference.


2 Answers

I am working on a gem that creates models based on a JSON Schema: jsonmodel

And I am also working on support for formtastic in a separate gem: jsonmodel-formtastic

Please note that both are a work in progress, but it would be nice to get feedback :-)

like image 122
Papipo Avatar answered Nov 01 '22 14:11

Papipo


Formtastic: http://github.com/justinfrench/formtastic has a mechanism for building forms from the models. Maybe you could base your code on theirs.

Check in lib/formtastic.rb line 474 or so.

Railscast for formtastic: http://railscasts.com/episodes/184-formtastic-part-1

like image 32
nkassis Avatar answered Nov 01 '22 12:11

nkassis