{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "http://dtls.nl/schemas/dmp-knowledge-model/",
    "type": "object",
    "title": "chapter",
    "description": "JSON file describing a single chapter in the knowledge model for DMP questionnaires",
    "definitions": {
        "chapterid": {
            "type": "integer",
            "minimum": 1,
            "maximum": 7
        },
        "questionid": {
            "type": "integer",
            "minimum": 1
        },
        "namespace": {
            "type": "string"
        },
        "expert": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "class": {
                    "type": "string",
                    "enum": [
                        "individual",
                        "organisation"
                    ],
                    "default": "organisation"
                }
            },
            "required": [
                "name"
            ]
        },
        "experts": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/expert"
            }
        },
        "questionpointer": {
            "type": "object",
            "properties": {
                "chapterid": {
                    "$ref": "#/definitions/chapterid"
                },
                "questionid": {
                    "$ref": "#/definitions/questionid"
                },
                "namespace": {
                    "$ref": "#/definitions/namespace"
                }
            },
            "required": [
                "chapterid",
                "questionid",
                "namespace"
            ],
            "additionalProperties": false
        },
        "dmpbookreference": {
            "type": "object",
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "dmpbook"
                    ]
                },
                "chapter": {
                    "type": "string"
                }
            },
            "required": [
                "type",
                "chapter"
            ],
            "additionalProperties": false
        },
        "urlreference": {
            "type": "object",
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "url"
                    ]
                },
                "url": {
                    "type": "string"
                },
                "anchor": {
                    "type": "string"
                }
            },
            "required": [
                "type",
                "weblink"
            ],
            "additionalProperties": false
        },
        "crossreference": {
            "type": "object",
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "xref"
                    ]
                },
                "chapterid": {
                    "$ref": "#/definitions/chapterid"
                },
                "questionid": {
                    "$ref": "#/definitions/questionid"
                },
                "namespace": {
                    "$ref": "#/definitions/namespace"
                }
            },
            "required": [
                "chapterid",
                "questionid"
            ],
            "additionalProperties": false
        },
        "reference": {
            "anyOf": [
                {
                    "$ref": "#/definitions/dmpbookreference"
                },
                {
                    "$ref": "#/definitions/urlreference"
                },
                {
                    "$ref": "#/definitions/crossreference"
                }
            ]
        },
        "references": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/reference"
            }
        },
        "answerid": {
            "type": "integer",
            "minimum": 0
        },
        "optionanswer": {
            "type": "object",
            "properties": {
                "id": {
                    "$ref": "#/definitions/answerid"
                },
                "label": {
                    "type": "string"
                },
                "advice": {
                    "type": "string"
                }
            },
            "required": [
                "id",
                "label"
            ],
            "additionalProperties": false
        },
        "optionanswers": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/optionanswer"
            }
        },
        "precondition": {
            "type": "object",
            "properties": {
                "namespace": {
                    "$ref": "#/definitions/namespace"
                },
                "questionid": {
                    "$ref": "#/definitions/questionid"
                },
                "answerid": {
                    "$ref": "#/definitions/answerid"
                }
            },
            "required": [
                "questionid"
            ],
            "additionalProperties": false
        },
        "question": {
            "type": "object",
            "properties": {
                "questionid": {
                    "$ref": "#/definitions/questionid"
                },
                "namespace": {
                    "$ref": "#/definitions/namespace"
                },
                "precondition": {
                    "$ref": "#/definitions/precondition"
                },
                "insertBefore": {
                    "$ref": "#/definitions/questionpointer"
                },
                "references": {
                    "$ref": "#/definitions/references"
                },
                "addReferences": {
                    "$ref": "#/definitions/references"
                },
                "experts": {
                    "$ref": "#/definitions/experts"
                },
                "addExperts": {
                    "$ref": "#/definitions/experts"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "option",
                        "list",
                        "string",
                        "text"
                    ]
                },
                "title": {
                    "type": "string"
                },
                "text": {
                    "type": "string"
                },
                "answers": {
                    "$ref": "#/definitions/optionanswers"
                },
                "addAnswers": {
                    "$ref": "#/definitions/optionanswers"
                }
            },
            "required": [
                "questionid"
            ],
            "additionalProperties": false
        },
        "optionquestion": {
            "type": "object",
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "option"
                    ]
                },
                "answers": {
                    "minItems": 1
                }
            }
        },
        "fieldquestion": {
            "type": "object",
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "list",
                        "string",
                        "text"
                    ]
                },
                "answers": {
                    "maxItems": 0
                }
            }
        }
    },
    "properties": {
        "chapterid": {
            "$ref": "#/definitions/chapterid"
        },
        "namespace": {
            "$ref": "#/definitions/namespace"
        },
        "formatversion": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1
        },
        "title": {
            "type": "string"
        },
        "text": {
            "type": "string"
        },
        "questions": {
            "type": "array",
            "items": {
                "allOf": [
                    {
                        "$ref": "#/definitions/question"
                    },
                    {
                        "anyOf": [
                            {
                                "$ref": "#/definitions/optionquestion"
                            },
                            {
                                "$ref": "#/definitions/fieldquestion"
                            }
                        ]
                    }
                ]
            }
        }
    },
    "required": [
        "chapterid",
        "namespace",
        "formatversion",
        "questions"
    ],
    "additionalProperties": false
}