|
|
|
@ -27,45 +27,358 @@ begin
|
|
|
|
|
|
|
|
|
|
schema = { |
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema", |
|
|
|
|
"$id": "https://example.com/product.schema.json", |
|
|
|
|
"title": "Form", |
|
|
|
|
"description": "A form", |
|
|
|
|
"$id": "http://example.com/example.json", |
|
|
|
|
"type": "object", |
|
|
|
|
"title": "The root schema", |
|
|
|
|
"description": "The root schema comprises the entire JSON document.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"form_type": "lettings", |
|
|
|
|
"start_year": 2021, |
|
|
|
|
"end_year": 2022, |
|
|
|
|
"sections": { |
|
|
|
|
"household": { |
|
|
|
|
"label": "About the household", |
|
|
|
|
"subsections": { |
|
|
|
|
"household_characteristics": { |
|
|
|
|
"label": "Household characteristics", |
|
|
|
|
"pages": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"questions": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"form_type", |
|
|
|
|
"start_year", |
|
|
|
|
"end_year", |
|
|
|
|
"sections" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"form_type": { |
|
|
|
|
"description": "", |
|
|
|
|
"type": "string" |
|
|
|
|
"$id": "#/properties/form_type", |
|
|
|
|
"type": "string", |
|
|
|
|
"title": "The form_type schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": "", |
|
|
|
|
"examples": [ |
|
|
|
|
"lettings" |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"start_year": { |
|
|
|
|
"description": "", |
|
|
|
|
"type": "int" |
|
|
|
|
"$id": "#/properties/start_year", |
|
|
|
|
"type": "integer", |
|
|
|
|
"title": "The start_year schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": 0, |
|
|
|
|
"examples": [ |
|
|
|
|
2021 |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"end_year": { |
|
|
|
|
"description": "", |
|
|
|
|
"type": "int" |
|
|
|
|
"$id": "#/properties/end_year", |
|
|
|
|
"type": "integer", |
|
|
|
|
"title": "The end_year schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": 0, |
|
|
|
|
"examples": [ |
|
|
|
|
2022 |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"sections": { |
|
|
|
|
"description": "", |
|
|
|
|
"$id": "#/properties/sections", |
|
|
|
|
"type": "object", |
|
|
|
|
"patternProperties": { |
|
|
|
|
"^[0-9]+$": { |
|
|
|
|
"description": "", |
|
|
|
|
"type": "string" |
|
|
|
|
}, |
|
|
|
|
"title": "The sections schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"household": { |
|
|
|
|
"label": "About the household", |
|
|
|
|
"subsections": { |
|
|
|
|
"household_characteristics": { |
|
|
|
|
"label": "Household characteristics", |
|
|
|
|
"pages": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"questions": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"household" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"household": { |
|
|
|
|
"$id": "#/properties/sections/properties/household", |
|
|
|
|
"type": "object", |
|
|
|
|
"title": "The household schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"label": "About the household", |
|
|
|
|
"subsections": { |
|
|
|
|
"household_characteristics": { |
|
|
|
|
"label": "Household characteristics", |
|
|
|
|
"pages": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"questions": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"label", |
|
|
|
|
"subsections" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"label": { |
|
|
|
|
"description": "", |
|
|
|
|
"type": "string" |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/label", |
|
|
|
|
"type": "string", |
|
|
|
|
"title": "The label schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": "", |
|
|
|
|
"examples": [ |
|
|
|
|
"About the household" |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"subsections": { |
|
|
|
|
"type": "object" |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections", |
|
|
|
|
"type": "object", |
|
|
|
|
"title": "The subsections schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"household_characteristics": { |
|
|
|
|
"label": "Household characteristics", |
|
|
|
|
"pages": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"questions": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"household_characteristics" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"household_characteristics": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics", |
|
|
|
|
"type": "object", |
|
|
|
|
"title": "The household_characteristics schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"label": "Household characteristics", |
|
|
|
|
"pages": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"questions": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"label", |
|
|
|
|
"pages" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"label": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics/properties/label", |
|
|
|
|
"type": "string", |
|
|
|
|
"title": "The label schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": "", |
|
|
|
|
"examples": [ |
|
|
|
|
"Household characteristics" |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"pages": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics/properties/pages", |
|
|
|
|
"type": "object", |
|
|
|
|
"title": "The pages schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"tenant_code": { |
|
|
|
|
"questions": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"tenant_code" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics/properties/pages/properties/tenant_code", |
|
|
|
|
"type": "object", |
|
|
|
|
"title": "The tenant_code schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"questions": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"questions" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"questions": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics/properties/pages/properties/tenant_code/properties/questions", |
|
|
|
|
"type": "object", |
|
|
|
|
"title": "The questions schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"tenant_code": { |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"tenant_code" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"tenant_code": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics/properties/pages/properties/tenant_code/properties/questions/properties/tenant_code", |
|
|
|
|
"type": "object", |
|
|
|
|
"title": "The tenant_code schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": {}, |
|
|
|
|
"examples": [ |
|
|
|
|
{ |
|
|
|
|
"check_answer_label": "Tenant code", |
|
|
|
|
"header": "What is the tenant code?", |
|
|
|
|
"type": "text" |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"required": [ |
|
|
|
|
"check_answer_label", |
|
|
|
|
"header", |
|
|
|
|
"type" |
|
|
|
|
], |
|
|
|
|
"properties": { |
|
|
|
|
"check_answer_label": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics/properties/pages/properties/tenant_code/properties/questions/properties/tenant_code/properties/check_answer_label", |
|
|
|
|
"type": "string", |
|
|
|
|
"title": "The check_answer_label schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": "", |
|
|
|
|
"examples": [ |
|
|
|
|
"Tenant code" |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"header": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics/properties/pages/properties/tenant_code/properties/questions/properties/tenant_code/properties/header", |
|
|
|
|
"type": "string", |
|
|
|
|
"title": "The header schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": "", |
|
|
|
|
"examples": [ |
|
|
|
|
"What is the tenant code?" |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"type": { |
|
|
|
|
"$id": "#/properties/sections/properties/household/properties/subsections/properties/household_characteristics/properties/pages/properties/tenant_code/properties/questions/properties/tenant_code/properties/type", |
|
|
|
|
"type": "string", |
|
|
|
|
"title": "The type schema", |
|
|
|
|
"description": "An explanation about the purpose of this instance.", |
|
|
|
|
"default": "", |
|
|
|
|
"examples": [ |
|
|
|
|
"text" |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"additionalProperties": true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
metaschema = JSON::Validator.validator_for_name("draft4").metaschema |
|
|
|
|
# => true |
|
|
|
|
|
|
|
|
|
if JSON::Validator.validate(metaschema, schema) |
|
|
|
|
puts "schema valid" |
|
|
|
|
else |
|
|
|
|