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 begin
# path = "config/forms/schema/generic.json" path = "config/forms/schema/generic.json"
path = "config/forms/schema/test.json"
# path = "config/forms/schema/2021_2022.json" # path = "config/forms/schema/2021_2022.json"
file = File.open(path) 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": { "sections": {
"type": "object", "type": "object",
"patternProperties": { "patternProperties": {
"[a-z_\/#]+": { "[a-z_]+": {
"description": "", "description": "Section Name",
"type": "object" "type": "object",
}, "properties": {
"properties": { "label": {
"label": { "description": "",
"description": "", "type": "string"
"type": "string" },
}, "subsections": {
"subsections": { "type": "object",
"description": "", "patternProperties": {
"type": "object", "[a-z_]+": {
"patternProperties": { "description": "SubSection Name",
"[a-z_\/#]+": { "type": "object",
"description": "", "required": ["label"],
"type": "object", "properties": {
"required": ["label"], "label": {
"properties": { "description": "",
"label": { "type": "string"
"description": "", },
"type": "string", "pages": {
"required": "true"
},
"pages": {
"type": "object",
"required": ["header"],
"patternProperties": {
"type": "object", "type": "object",
"[a-z_]+": { "patternProperties": {
"properties": { "[a-z_]+": {
"header": { "description": "Page Name",
"description": "", "type": "object",
"type": "string" "required": ["header", "questions"],
}, "properties": {
"description": { "header": {
"description": "", "description": "",
"type": "string" "type": "string"
}, },
"questions": { "description": {
"type": "object", "description": "",
"patternProperties": { "type": "string"
},
"questions": {
"type": "object", "type": "object",
"[a-z_]+": { "patternProperties": {
"properties": { "[a-z_]+": {
"check_answer_label": { "description": "Question Name",
"type": "string" "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 "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?", "header": "What is the tenant code?",
"type": "text" "type": "text"
} }
} },
"conditional_route_to": {"test": "Yes"}
} }
}, },
"person_1_age": { "person_1_age": {

Loading…
Cancel
Save