|
|
|
@ -1,29 +1,6 @@
|
|
|
|
|
require "json-schema" |
|
|
|
|
require "json" |
|
|
|
|
|
|
|
|
|
# "form_type": "lettings", |
|
|
|
|
#start_year": 2021, |
|
|
|
|
#end_year": 2022, |
|
|
|
|
#sections": { |
|
|
|
|
# about_this_log": { |
|
|
|
|
# label": "About this log", |
|
|
|
|
# subsections": { |
|
|
|
|
# about_this_log": { |
|
|
|
|
# label": "About this log", |
|
|
|
|
# pages": { |
|
|
|
|
# "tenant_code": { |
|
|
|
|
# header": "", |
|
|
|
|
# description": "", |
|
|
|
|
# questions": { |
|
|
|
|
# tenant_code": { |
|
|
|
|
# check_answer_label": "Tenant code", |
|
|
|
|
# header": "What is the tenant code?", |
|
|
|
|
# hint_text": "", |
|
|
|
|
# type": "text" |
|
|
|
|
# } |
|
|
|
|
# } |
|
|
|
|
# } |
|
|
|
|
|
|
|
|
|
def get_all_form_paths(directories) |
|
|
|
|
form_paths = [] |
|
|
|
|
directories.each do |directory| |
|
|
|
@ -43,6 +20,8 @@ begin
|
|
|
|
|
schema = JSON.parse(file.read) |
|
|
|
|
metaschema = JSON::Validator.validator_for_name("draft4").metaschema |
|
|
|
|
|
|
|
|
|
puts path |
|
|
|
|
|
|
|
|
|
if JSON::Validator.validate(metaschema, schema) |
|
|
|
|
puts "schema valid" |
|
|
|
|
else |
|
|
|
@ -50,9 +29,6 @@ begin
|
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
path = "spec/fixtures/forms/test_validator.json" |
|
|
|
|
# path = "config/forms/2021_2022.json" |
|
|
|
|
|
|
|
|
|
directories = ["config/forms", "spec/fixtures/forms"] |
|
|
|
|
|
|
|
|
|
get_all_form_paths(directories).each do |path| |
|
|
|
@ -60,7 +36,7 @@ begin
|
|
|
|
|
file = File.open(path) |
|
|
|
|
data = JSON.parse(file.read) |
|
|
|
|
|
|
|
|
|
puts JSON::Validator.validate(schema, data) |
|
|
|
|
puts JSON::Validator.validate(schema, data, :strict => true) |
|
|
|
|
|
|
|
|
|
puts JSON::Validator.fully_validate(schema, data, :strict => true) |
|
|
|
|
|
|
|
|
|