json-schema icon indicating copy to clipboard operation
json-schema copied to clipboard

Provide a tool to generate a base schema from an example JSON document.

Open hoxworth opened this issue 10 years ago • 10 comments

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 avatar Sep 05 '14 17:09 hoxworth

@hoxworth Are you actively working on this feature or posting it as a proposed idea for someone to work on?

loganfrederick avatar Oct 08 '14 20:10 loganfrederick

Posting as a proposed feature - definitely not working on it at the moment. Would be a great feature to have, however!

hoxworth avatar Oct 08 '14 20:10 hoxworth

Should that be a part of this gem, or a separate tool?

iainbeeston avatar Oct 09 '14 08:10 iainbeeston

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.

hoxworth avatar Oct 26 '14 04:10 hoxworth

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)=

iainbeeston avatar Oct 26 '14 06:10 iainbeeston

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!)

pd avatar Nov 01 '14 15:11 pd

I don't know of one, but it would be useful (for property testing)

iainbeeston avatar Nov 01 '14 16:11 iainbeeston

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. =)

pd avatar Nov 01 '14 20:11 pd

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!

jphastings avatar Nov 03 '14 15:11 jphastings

@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.

loganfrederick avatar Jul 26 '15 23:07 loganfrederick