json-schema
json-schema copied to clipboard
Provide a tool to generate a base schema from an example JSON document.
This sort of feature has been requested in the past; adding it here for documentation sake. The idea is to produce a basic schema that a user could then further refine from an example JSON doc. For example:
{
"age" : 5,
"smell" : "bad"
}
Could generate the following schema:
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"type" : "object",
"properties" : {
"age" : {
"type" : "integer"
},
"smell" : {
"type" : "string"
}
}
}
@hoxworth Are you actively working on this feature or posting it as a proposed idea for someone to work on?
Posting as a proposed feature - definitely not working on it at the moment. Would be a great feature to have, however!
Should that be a part of this gem, or a separate tool?
Either or, to be honest. I had planned to eventually add this as a binary installed along with the gem, but am not opposed to making it a separate tool so as to not conflate the purpose of this library.
If anyone else is looking for a feature like this in the meantime, check out http://jsonschema.net/ (not a very descriptive url, but it generates schemas from an example JSON file)=
Tangentially, has anyone found a tool to do the opposite? eg, given a schema, generate random JSON values that would satisfy it? It'd be handy for fuzzing tests. Definitely non-trivial, though (satisfying pattern
, or dependencies
, etc would probably be tricky!)
I don't know of one, but it would be useful (for property testing)
Coincidentally, when I joined #ruby-json-schema @ freenode today, a new person was idling; checked if their nick was also what they used on Github and found @jphastings' genny project which is (could/will be) exactly what I was asking about. =)
Oh hey! Yeah, I wanted a library to do just that (for Swaggerific) and figured I'd just build it. Feature requests welcome at blinkboxbooks/genny!
@hoxworth It looks like a couple years ago somebody did put one together: https://github.com/maxlinc/json-schema-generator
Hasn't been touched in two years, so it might be worth poking at to see if it's broken/should be updated.