Hello,
Please add a Kwalify::Yaml::dump() method that emits YAML conforming
to Kwalify style (see below) because the Kwalify::Yaml::Parser is
unable to parse standard YAML (see below) which does not necessarily
indent the bodies of mappings.
This will allow arbitrary data to be validated dynamically:
schema = Kwalify::Yaml.load_file('schema.yaml')
validator = Kwalify::Validator.new(schema)
parser = Kwalify::Yaml::Parser.new(validator)
yaml = Kwalify::Yaml.dump(some_complex_object) # <== dump!
data = parser.parse(yaml) # <== validate!
I am currently working around this issue with an ugly hack:
# XXX: kwalify requires mapping bodies to be indented
yaml = Psych.dump(some_complex_object, indentation: 4).
gsub(/^(\s*)- (?=\S.*:)/, '\1 - ')
data = parser.parse(yaml) # <== validate!
Thanks for your consideration.
Kwalify style requires the bodies of mappings to be indented:
player:
- given: Sammy
family: Sosa
- given: Ken
family: Griffey
- given: Mark
family: McGwire
In contrast, standard YAML does not have such a requirement:
player:
- given: Sammy
family: Sosa
- given: Ken
family: Griffey
- given: Mark
family: McGwire
I found a better solution:
require 'json'
yaml = JSON.pretty_generate(some_complex_object) # machine-generate
data = parser.parse(yaml) # parse & validate
It is explained in more detail here:
http;//snk.tuxfamily.org/log/yaml-json-validation-kwalify-ruby19.html
Cheers.