Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

require "json-schema"
require "json"
# "form_type": "lettings",
3 years ago
#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|
Dir.glob("#{directory}/*.json").each do |form_path|
form_paths.push(form_path)
end
end
form_paths
end
begin
3 years ago
path = "config/forms/schema/generic.json"
# path = "config/forms/schema/2021_2022.json"
3 years ago
file = File.open(path)
schema = JSON.parse(file.read)
3 years ago
metaschema = JSON::Validator.validator_for_name("draft4").metaschema
3 years ago
if JSON::Validator.validate(metaschema, schema)
3 years ago
puts "schema valid"
3 years ago
else
3 years ago
puts "schema not valid"
return
3 years ago
end
path = "spec/fixtures/forms/test_validator.json"
# path = "config/forms/2021_2022.json"
3 years ago
directories = ["config/forms", "spec/fixtures/forms"]
3 years ago
get_all_form_paths(directories).each do |path|
puts path
file = File.open(path)
data = JSON.parse(file.read)
3 years ago
puts JSON::Validator.validate(schema, data)
3 years ago
puts JSON::Validator.fully_validate(schema, data, :strict => true)
3 years ago
begin
JSON::Validator.validate!(schema, data)
rescue JSON::Schema::ValidationError => e
e.message
end
end
end