Browse Source

reinclude metaschema validation

pull/91/head
magicmilo 3 years ago
parent
commit
622cb906dc
  1. 5
      README.md
  2. 21
      lib/tasks/form_definition.rake

5
README.md

@ -163,7 +163,10 @@ Assumptions made by the format:
## JSON Form Validation against Schema
To validate the form JSON against the schema you can run:
`rake form_definition:validate["config/forms/2021_22.json"]`
`rake form_definition:validate["config/forms/2021_2022.json"]`
n.b. You may have to escape square brackets in zsh
`rake form_definition:validate\["config/forms/2021_2022.json"\]`
This will validate the given form definition against the schema in `config/forms/schema/generic.json`.

21
lib/tasks/form_definition.rake

@ -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)

Loading…
Cancel
Save