playlyfe / themis

A blazing fast JSON Schema v4 validator!
Other
60 stars 7 forks source link

Anonymous schema #12

Open moll opened 9 years ago

moll commented 9 years ago

Hey,

When I create a simple anonymous schema (without an explicit "id"), I've got to call its validate function with a fake "0" as the schema name. Could this implementation detail be hidden to just allow calling the function with an object and without a name?

var validate = Themis.validator(schema)
validate({}, "0")

Thanks!

kumarharsh commented 9 years ago

Hi. The issue is that the validator function can work with both a schema object, and an array of schemas. It's is a minor inconvenience though :)

moll commented 9 years ago

Mkay, then validator could return different types of validate functions depending on whether given an array or not, right?

atrniv commented 9 years ago

@moll, I think returning different types of validate functions makes sense. You can open a pull request for the same and I'll merge it.

kumarharsh commented 9 years ago

Actually I was working on this (the first proposal, of allowing the retrieval of a lone schema), but seems like it's not going to be as trivial as I first presumed... especially, as the _schemas object keeps changing, and the sub-schemas are added to the original schema list passed by the user.