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

2
spec/fixtures/forms/test_validator.json vendored

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

Loading…
Cancel
Save