Browse Source

basic intial operation

pull/76/head
magicmilo 3 years ago
parent
commit
a0d73baf6a
  1. 24
      app/helpers/json_schema_validation.rb
  2. 2
      spec/fixtures/forms/test_validator.json

24
app/helpers/json_schema_validation.rb

@ -26,7 +26,7 @@ require "json"
begin
schema = {
"$schema": "https://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema",
"$id": "https://example.com/product.schema.json",
"title": "Form",
"description": "A form",
@ -47,27 +47,29 @@ begin
"sections": {
"description": "",
"type": "object",
"properties": {
"page_name": {
"patternProperties": {
"^[0-9]+$": {
"description": "",
"type": "string"
},
"label": {
"description": "",
"type": "string"
}
}
}
}
}
# file = File.open("config/forms/2021_2022.json")
file = File.open("spec/fixtures/forms/test_validator.json")
puts data = JSON.parse(file.read)
path = "spec/fixtures/forms/test_validator.json"
# path = "config/forms/2021_2022.json"
file = File.open(path)
data = JSON.parse(file.read)
puts JSON::Validator.validate(schema, data)
if JSON::Validator.validate!(schema, data)
puts "Success"
else
puts "Validation failed"
end
puts JSON::Validator.fully_validate(schema, data, :strict => true)
begin
JSON::Validator.validate!(schema, data)

2
spec/fixtures/forms/test_validator.json vendored

@ -1,5 +1,7 @@
{
"form_type": "lettings",
"start_year": 2021,
"end_year": 2022,
"sections": {
"household": {
"label": "About the household",

Loading…
Cancel
Save