|
|
|
@ -15,10 +15,9 @@ namespace :form_definition do
|
|
|
|
|
desc "Validate JSON against Generic Form Schema" |
|
|
|
|
|
|
|
|
|
task validate_all: :environment do |
|
|
|
|
puts Rails.root.to_s |
|
|
|
|
|
|
|
|
|
directories = ["config/forms", "spec/fixtures/forms"] |
|
|
|
|
paths = get_all_form_paths(directories) + ["config/forms/schema/generic.json"] |
|
|
|
|
paths = get_all_form_paths(directories) |
|
|
|
|
|
|
|
|
|
paths.each do |path| |
|
|
|
|
Rake::Task["form_definition:validate"].reenable |
|
|
|
@ -27,10 +26,26 @@ namespace :form_definition do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
task :validate, %i[path] => :environment do |_task, args| |
|
|
|
|
|
|
|
|
|
puts args |
|
|
|
|
|
|
|
|
|
path = "config/forms/schema/generic.json" |
|
|
|
|
file = File.open(path) |
|
|
|
|
schema = JSON.parse(file.read) |
|
|
|
|
meta_schema = JSON::Validator.validator_for_name("draft4").metaschema |
|
|
|
|
|
|
|
|
|
puts path |
|
|
|
|
|
|
|
|
|
if JSON::Validator.validate(meta_schema, schema) |
|
|
|
|
puts "schema valid" |
|
|
|
|
else |
|
|
|
|
puts "schema not valid" |
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
path = Rails.root.join(args.path) |
|
|
|
|
file = File.open(path) |
|
|
|
|
form_definition = JSON.parse(file.read) |
|
|
|
|
schema = JSON::Validator.validator_for_name("draft4").metaschema |
|
|
|
|
|
|
|
|
|
puts path |
|
|
|
|
puts JSON::Validator.fully_validate(schema, form_definition, strict: true) |
|
|
|
|