natesilva/jayschema — pull request #7 by bitmage (2013-03-16 18:03:00+00:00)
Title: Support 'function' data type

Now I know what you're gonna say. Functions aren't valid json. Bear with me.

JSON schemas are really useful, and shouldn't be limited to just strict JSON cases. If you add in the capability to detect functions, you've now got support for all javascript types and therefore have broadened the usefulness.

This doesn't interfere with any of the existing capabilities, as you can see. The tests all still pass, and I've added a few more. There a couple possible cases to consider:

1. The user of the library doesn't have functions in their target JSON, or their schema. Great, everything will work as according to spec.
2. The user of the library has functions in their target JSON, but not in the schema. Type checks still work as normal, so if you're expecting an object and you get a function, the schema validation will fail. This is actually an *increase* in accuracy, since with the previous implementation this 'function' would have been detected as an 'object' and the test would pass.
3. The user has functions in their schema, but not in the JSON. This should be the same as the previous case. Type checking still works as normal.

What do you say? Can we have our cake and eat it too?