README_V3.md in schemacop-3.0.0.rc3 vs README_V3.md in schemacop-3.0.0.rc4

- old
+ new

@@ -88,11 +88,11 @@ information why the validation failed. Example: ```ruby - Schemacop::Schema3.new do + Schemacop::Schema3.new :hash do int! end # => Schemacop::Exceptions::InvalidSchemaError: Child nodes must have a name. ``` @@ -378,11 +378,11 @@ ``` ### Array Type: `:array`\ -DSL: `arr` +DSL: `ary` The array type represents a ruby `Array`. It consists of one or multiple values, which can be validated using arbitrary nodes. #### Options @@ -585,12 +585,13 @@ #### Options * `additional_properties` This option specifies whether additional, unspecified properties are allowed - (`true`) or not (`false`). By default, this is `true` if no properties are - specified and `false` if you have specified at least one property. + (`true`) or not (`false`). By default, this is `false`, i.e. you need to + explicitly set it to `true` if you want to allow arbitrary additional properties, + or use the `add` DSL method (see below) to specify additional properties. * `property_names` This option allows to specify a regexp pattern (as string) which validates the keys of any properties that are not specified in the hash. This option only makes sense if `additional_properties` is enabled. See below for more information. @@ -669,9 +670,64 @@ schema = Schemacop::Schema3.new :hash do int! :foo end schema.validate!(foo: 42, 'foo' => 43) # => Schemacop::Exceptions::ValidationError: /: Has 1 ambiguous properties: [:foo]. +``` + +In addition to the normal node options (which vary from type to type, check +the respective nodes for details), properties also support the `as` option. + +With this, you can "rename" properties in the output: + +```ruby +schema = Schemacop::Schema3.new :hash do + int! :foo, as: :bar +end + +schema.validate!({foo: 42}) # => {"bar"=>42} +``` + +Please note that if you specify a node with the same property name multiple +times, or use the `as` option to rename a node to the same name of another +node, the last specified node will be used: + +```ruby +schema = Schemacop::Schema3.new :hash do + int? :foo + str? :foo +end + +schema.validate!({foo: 1}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "string". +schema.validate!({foo: 'bar'}) # => {"foo"=>"bar"} +``` + +As well as: + +```ruby +schema = Schemacop::Schema3.new :hash do + int? :foo + int? :bar, as: :foo +end + +schema.validate!({foo: 1}) # => {"foo"=>1} +schema.validate!({foo: 1, bar: 2}) # => {"foo"=>2} +schema.validate!({bar: 2}) # => {"foo"=>2} +``` + +If you want to specify a node which may be one of multiple types, use the `one_of` +node (see further down for more details): + +```ruby +schema = Schemacop::Schema3.new :hash do + one_of! :foo do + int + str + end +end + +schema.validate!({foo: 1}) # => {"foo"=>1} +schema.validate!({foo: 'bar'}) # => {"foo"=>"bar"} ``` ##### Pattern properties In addition to symbols, property keys can also be a regular expression. Here,