From a0d73baf6ab4b7ad9a35d66e49b3f3e750a995e8 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Fri, 5 Nov 2021 16:58:44 +0000 Subject: [PATCH] basic intial operation --- app/helpers/json_schema_validation.rb | 24 +++++++++++++----------- spec/fixtures/forms/test_validator.json | 2 ++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/helpers/json_schema_validation.rb b/app/helpers/json_schema_validation.rb index 777ffc39a..dcb0c20a4 100644 --- a/app/helpers/json_schema_validation.rb +++ b/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) diff --git a/spec/fixtures/forms/test_validator.json b/spec/fixtures/forms/test_validator.json index 2ac97e26d..0539a719b 100644 --- a/spec/fixtures/forms/test_validator.json +++ b/spec/fixtures/forms/test_validator.json @@ -1,5 +1,7 @@ { "form_type": "lettings", + "start_year": 2021, + "end_year": 2022, "sections": { "household": { "label": "About the household",