{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "subField": {
            "type": "object",
            "properties": {
                "tag": {
                    "type": "string",
                    "minLength": 2
                }
            },
            "additionalProperties": false
        },
        "complexType": {
            "type": "object",
            "required": [
                "type"
            ],
            "oneOf": [
                {
                    "properties": {
                        "type": {
                            "enum": [
                                "value1"
                            ]
                        }
                    },
                    "required": [
                        "dataSets"
                    ]
                },
                {
                    "properties": {
                        "type": {
                            "enum": [
                                "value2"
                            ]
                        }
                    },
                    "required": [
                        "subFields"
                    ]
                }
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "value2",
                        "value1"
                    ]
                },
                "dataSets": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "code",
                            "subFields"
                        ],
                        "properties": {
                            "code": {
                                "type": "string"
                            },
                            "subFields": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/definitions/subField"
                                }
                            }
                        }
                    }
                },
                "subFields": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/subField"
                    }
                }
            },
            "dependencies": {
                "dataSets": {
                    "properties": {
                        "type": {
                            "enum": [
                                "value1"
                            ]
                        }
                    }
                },
                "subFields": {
                    "properties": {
                        "type": {
                            "enum": [
                                "value2"
                            ]
                        }
                    }
                }
            },
            "additionalProperties": false
        },
        "dataElement": {
            "type": "object",
            "oneOf": [
                {
                    "required": [
                        "code",
                        "defaultUsage",
                        "usages",
                        "name"
                    ]
                },
                {
                    "allOf": [
                        {
                            "not": {
                                "required": [
                                    "usages"
                                ]
                            }
                        },
                        {
                            "required": [
                                "code",
                                "format",
                                "name"
                            ]
                        }
                    ]
                }
            ],
            "properties": {
                "code": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                },
                "format": {
                    "type": "string"
                },
                "defaultUsage": {
                    "type": "string"
                },
                "usages": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/usage"
                    }
                },
                "complexType": {
                    "$ref": "#/definitions/complexType"
                }
            },
            "additionalProperties": false
        },
        "usage": {
            "type": "object",
            "required": [
                "name",
                "field"
            ],
            "properties": {
                "name": {
                    "type": "string"
                },
                "field": {
                    "$ref": "#/definitions/dataElement"
                }
            },
            "additionalProperties": false
        }
    },
    "type": "object",
    "properties": {
        "fields": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/dataElement"
            }
        }
    },
    "additionalProperties": false
}