use codegen to generate doument validation function. 

this is significantly faster then old code for non trivial schema.