commonjs-utils icon indicating copy to clipboard operation
commonjs-utils copied to clipboard

Only "object" type valid if multiple types permitted

Open manuels opened this issue 14 years ago • 1 comments

Hi,

if you allow multiple types for a property like properties: { myProp: { type: [ "string", "integer", "object" ] } } this works fine, but as soon as you add myProp.properties = {...} or myProp.schema.additionalProperties = false only "objects" are permitted for myProp and not any "string" or "integer".

This should fix this issue:

diff --git a/lib/json-schema.js b/lib/json-schema.js index f4fc07d..f13acc3 100644 --- a/lib/json-schema.js +++ b/lib/json-schema.js @@ -134,7 +134,7 @@ var validate = exports._validate = function(/Any/instance,/Object/schema,/*B if(schema.maxItems && value.length > schema.maxItems){ addError("There must be a maximum of " + schema.maxItems + " in the array"); }

  •                           }else if(schema.properties || schema.additionalProperties){
    
  •                           }else if(typeof value == 'object' && (schema.properties || schema.additionalProperties) ){
                                    errors.concat(checkObj(value, schema.properties, path, schema.additionalProperties));
                            }
                            if(schema.pattern && typeof value == 'string' && !value.match(schema.pattern)){
    

manuels avatar May 26 '10 12:05 manuels

Bloody markup! Do you get It or should I send you this information eg. via email?

Mainly it's this }else if(schema.properties || schema.additionalProperties){ // old }else if(typeof value == 'object' && (schema.properties || schema.additionalProperties) ){ //new

manuels avatar May 26 '10 12:05 manuels