From f844f9273e263ab84ec7026463ce216cb872fd46 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Tue, 9 Nov 2021 14:34:17 +0000 Subject: [PATCH] outline --- app/helpers/json_schema_validation.rb | 30 ++----------- config/forms/schema/generic.json | 63 +++++++++++++++++++++++++-- spec/fixtures/forms/test_form.json | 2 + 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/app/helpers/json_schema_validation.rb b/app/helpers/json_schema_validation.rb index 5435f02e6..dd0655d3b 100644 --- a/app/helpers/json_schema_validation.rb +++ b/app/helpers/json_schema_validation.rb @@ -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) diff --git a/config/forms/schema/generic.json b/config/forms/schema/generic.json index 024990b8b..b9502c0e1 100644 --- a/config/forms/schema/generic.json +++ b/config/forms/schema/generic.json @@ -1,5 +1,5 @@ { - "$schema": "http://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", @@ -16,8 +16,7 @@ }, "end_year": { "description": "", - "type": "integer", - "required": "false" + "type": "integer" }, "sections": { "description": "", @@ -32,7 +31,63 @@ "type": "string" }, "subsections": { - "type": "object" + "description": "", + "type": "object", + "patternProperties": { + "^[0-9]+$": { + "description": "", + "type": "string" + }, + "label": { + "description": "", + "type": "string" + }, + "subsections": { + "description": "", + "type": "object", + "patternProperties": { + "^[0-9]+$": { + "description": "", + "type": "string" + }, + "label": { + "description": "", + "type": "string" + }, + "pages": { + "description": "", + "type": "object", + "patternProperties": { + "^[0-9]+$": { + "description": "", + "type": "string" + } + }, + "questions": { + "description": "", + "type": "object", + "patternProperties": { + "^[0-9]+$": { + "description": "", + "type": "string" + }, + "conditional_for": { + "type": "object", + "properties": "" + } + } + }, + "conditional_route_to": { + "type": "object", + "properties": "" + }, + "default_next_page": { + "type" : "string" + } + } + } + } + } } } } diff --git a/spec/fixtures/forms/test_form.json b/spec/fixtures/forms/test_form.json index 2bcd34aaa..0d26827fa 100644 --- a/spec/fixtures/forms/test_form.json +++ b/spec/fixtures/forms/test_form.json @@ -1,5 +1,7 @@ { "form_type": "lettings", + "start_year": 2021, + "end_year": 2022, "sections": { "household": { "label": "About the household",