Skip to content
Snippets Groups Projects
Commit ae0c8bc2 authored by Alvaro Cabrera's avatar Alvaro Cabrera
Browse files

Apply requiredOnly option; fixes #81

parent 7921c11d
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -12,6 +12,7 @@ class OptionRegistry extends Registry<Option> { ...@@ -12,6 +12,7 @@ class OptionRegistry extends Registry<Option> {
this.data['failOnInvalidTypes'] = true; this.data['failOnInvalidTypes'] = true;
this.data['defaultInvalidTypeProduct'] = null; this.data['defaultInvalidTypeProduct'] = null;
this.data['useDefaultValue'] = false; this.data['useDefaultValue'] = false;
this.data['requiredOnly'] = false;
this.data['maxItems'] = null; this.data['maxItems'] = null;
this.data['maxLength'] = null; this.data['maxLength'] = null;
this.data['defaultMinItems'] = 0; this.data['defaultMinItems'] = 0;
......
...@@ -35,6 +35,16 @@ var objectType: FTypeGenerator = function objectType(value: IObjectSchema, path, ...@@ -35,6 +35,16 @@ var objectType: FTypeGenerator = function objectType(value: IObjectSchema, path,
throw new ParseError('missing properties for:\n' + JSON.stringify(value, null, ' '), path); throw new ParseError('missing properties for:\n' + JSON.stringify(value, null, ' '), path);
} }
if (option('requiredOnly') === true) {
requiredProperties.forEach(function(key) {
if (properties[key]) {
props[key] = properties[key];
}
});
return traverseCallback(props, path.concat(['properties']), resolve);
}
var min = Math.max(value.minProperties || 0, requiredProperties.length); var min = Math.max(value.minProperties || 0, requiredProperties.length);
var max = Math.max(value.maxProperties || random.number(min, min + 5)); var max = Math.max(value.maxProperties || random.number(min, min + 5));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment