Browse Source

Validate structure correctly

pull/76/head
magicmilo 3 years ago
parent
commit
8c27ae6ffc
  1. 3
      app/helpers/json_schema_validation.rb
  2. 2230
      config/forms/schema/2021_2022.json
  3. 140
      config/forms/schema/generic.json
  4. 108
      config/forms/schema/test.json
  5. 18
      spec/fixtures/forms/test_form.json
  6. 3
      spec/fixtures/forms/test_validator.json

3
app/helpers/json_schema_validation.rb

@ -13,8 +13,7 @@ end
begin
# path = "config/forms/schema/generic.json"
path = "config/forms/schema/test.json"
path = "config/forms/schema/generic.json"
# path = "config/forms/schema/2021_2022.json"
file = File.open(path)

2230
config/forms/schema/2021_2022.json

File diff suppressed because it is too large Load Diff

140
config/forms/schema/generic.json

@ -21,69 +21,97 @@
"sections": {
"type": "object",
"patternProperties": {
"[a-z_\/#]+": {
"description": "",
"type": "object"
},
"properties": {
"label": {
"description": "",
"type": "string"
},
"subsections": {
"description": "",
"type": "object",
"patternProperties": {
"[a-z_\/#]+": {
"description": "",
"type": "object",
"required": ["label"],
"properties": {
"label": {
"description": "",
"type": "string",
"required": "true"
},
"pages": {
"type": "object",
"required": ["header"],
"patternProperties": {
"[a-z_]+": {
"description": "Section Name",
"type": "object",
"properties": {
"label": {
"description": "",
"type": "string"
},
"subsections": {
"type": "object",
"patternProperties": {
"[a-z_]+": {
"description": "SubSection Name",
"type": "object",
"required": ["label"],
"properties": {
"label": {
"description": "",
"type": "string"
},
"pages": {
"type": "object",
"[a-z_]+": {
"properties": {
"header": {
"description": "",
"type": "string"
},
"description": {
"description": "",
"type": "string"
},
"questions": {
"type": "object",
"patternProperties": {
"patternProperties": {
"[a-z_]+": {
"description": "Page Name",
"type": "object",
"required": ["header", "questions"],
"properties": {
"header": {
"description": "",
"type": "string"
},
"description": {
"description": "",
"type": "string"
},
"questions": {
"type": "object",
"[a-z_]+": {
"properties": {
"check_answer_label": {
"type": "string"
}
"patternProperties": {
"[a-z_]+": {
"description": "Question Name",
"type": "object",
"required": ["header", "type"],
"properties": {
"header": {
"description": "",
"type": "string"
},
"type": {
"description": "",
"type": "string"
}
},
"additionalProperties": {
"hint_text": {
"optional": "true",
"description": "",
"type": "string"
},
"answer_options": {
"optional": "true",
"description": "",
"type": "object"
},
"check_answer_label": {
"description": "",
"type": "string"
}
},
"minProperties": 1
}
}
},
"minProperties": 8
}
},
"minProperties": 8
"additionalProperties": {
"conditional_route_to": {
"description": "",
"type": "object"
}
},
"minProperties": 1
}
}
},
"minProperties": 8
}
}
}
},
"minProperties": 1
}
}
},
"minProperties": 8
}
}
}
},
"minProperties": 2
}
},
"minProperties": 1

108
config/forms/schema/test.json

@ -1,108 +0,0 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "https://example.com/product.schema.json",
"title": "Form",
"description": "A form",
"type": "object",
"required": ["form_type", "start_year", "end_year", "sections"],
"properties": {
"form_type": {
"description": "",
"type": "string"
},
"start_year": {
"description": "",
"type": "integer"
},
"end_year": {
"description": "",
"type": "integer"
},
"sections": {
"type": "object",
"patternProperties": {
"[a-z_]+": {
"description": "",
"type": "object",
"properties": {
"label": {
"description": "",
"type": "string"
},
"subsections": {
"type": "object",
"patternProperties": {
"[a-z_]+": {
"description": "",
"type": "object",
"required": ["label"],
"properties": {
"label": {
"description": "",
"type": "string"
},
"pages": {
"type": "object",
"patternProperties": {
"[a-z_]+": {
"description": "",
"type": "object",
"properties": {
"header": {
"description": "",
"type": "string"
},
"description": {
"description": "",
"type": "string"
},
"questions": {
"type": "object",
"patternProperties": {
"[a-z_]+": {
"description": "",
"type": "object",
"required": ["header"],
"properties": {
"check_answer_label": {
"description": "",
"type": "string"
},
"header": {
"description": "",
"type": "string"
},
"type": {
"description": "",
"type": "string"
},
"hint_text": {
"description": "",
"type": "string"
},
"answer_options": {
"description": "",
"type": "string"
}
}
}
}
}
},
"minProperties": 1
}
}
}
},
"minProperties": 1
}
}
}
},
"minProperties": 2
}
},
"minProperties": 1
}
}
}

18
spec/fixtures/forms/test_form.json vendored

@ -1,18 +0,0 @@
{
"form_type": "lettings",
"start_year": 2021,
"end_year": 2022,
"sections": {
"household": {
"label": "About the household",
"subsections": {
"household_characteristics": {
"label": "Household characteristics",
"pages": {
}
}
}
}
}
}

3
spec/fixtures/forms/test_validator.json vendored

@ -17,7 +17,8 @@
"header": "What is the tenant code?",
"type": "text"
}
}
},
"conditional_route_to": {"test": "Yes"}
}
},
"person_1_age": {

Loading…
Cancel
Save