{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "Schema for OGR_SCHEMA open option",
  "oneOf": [
    {
      "$ref": "#/definitions/dataset"
    }
  ],
  "definitions": {
    "schemaType": {
      "enum": [
        "Patch",
        "Full"
      ]
    },
    "dataset": {
      "type": "object",
      "properties": {
        "layers": {
          "type": "array",
          "description": "The list of layers contained in the schema",
          "items": {
            "$ref": "#/definitions/layer"
          }
        }
      },
      "required": [
        "layers"
      ],
      "additionalProperties": false
    },
    "layer": {
      "type": "object",
      "properties": {
        "name": {
          "description": "The name of the layer. Can be '*' to apply to any layer.",
          "type": "string"
        },
        "fidColumnName": {
          "description": "The name of the FID column",
          "type": "string"
        },
        "schemaType": {
          "description": "The type of schema operation: patch or full",
          "$ref": "#/definitions/schemaType"
        },
        "fields": {
          "description": "The list of field definitions",
          "type": "array",
          "items": {
            "$ref": "#/definitions/field"
          }
        },
        "geometryFields": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/geometryField"
          }
        }
      },
      "required": [
        "name",
        "fields"
      ],
      "additionalProperties": false
    },
    "field": {
      "description": "The field definition",
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "srcType": {
          "$ref": "#/definitions/fieldType"
        },
        "srcSubType": {
          "$ref": "#/definitions/fieldSubType"
        },
        "type": {
          "$ref": "#/definitions/fieldType"
        },
        "subType": {
          "$ref": "#/definitions/fieldSubType"
        },
        "width": {
          "type": "integer"
        },
        "precision": {
          "type": "integer"
        },
        "newName": {
          "description": "The new name of the field",
          "type": "string"
        },
        "nullable": {
          "description": "Whether the field is not nullable",
          "type": "boolean"
        },
        "uniqueConstraint": {
          "description": "Whether the field is unique",
          "type": "boolean"
        },
        "defaultValue": {
          "description": "The default value for the field",
          "type": [
            "string"
          ]
        },
        "alias": {
          "description": "Alias for the field",
          "type": "string"
        },
        "comment": {
          "description": "Comment for the field",
          "type": "string"
        },
        "domainName": {
          "description": "Domain for the field",
          "type": "string"
        },
        "timezone": {
          "description": "Time zone for date/time fields",
          "type": "string"
        }
      },
      "anyOf": [
        {
          "required": [
            "name"
          ]
        },
        {
          "anyOf": [
            {
              "required": [
                "srcType"
              ]
            },
            {
              "required": [
                "srcSubType"
              ]
            }
          ]
        }
      ],
      "additionalProperties": false
    },
    "fieldType": {
      "enum": [
        "Integer",
        "Integer64",
        "Real",
        "String",
        "Binary",
        "IntegerList",
        "Integer64List",
        "RealList",
        "StringList",
        "Date",
        "Time",
        "DateTime"
      ]
    },
    "fieldSubType": {
      "enum": [
        "None",
        "Boolean",
        "Int16",
        "Float32",
        "JSON",
        "UUID"
      ]
    },
    "geometryField": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "pattern": "^(Geometry|((Multi)?Point)|((Multi)?LineString)|((Multi)?Polygon)|GeometryCollection|((Multi)?Curve)|((Multi)?Surface)|CircularString|CompoundCurve|CurvePolygon|Tin|PolyhedralSurface|Triangle)[Z]?[M]?$"
        },
        "nullable": {
          "type": "boolean"
        },
        "coordinateSystem": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/definitions/coordinateSystem"
            }
          ]
        },
        "supportedSRSList": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "object",
                    "properties": {
                      "authority": {
                        "type": "string"
                      },
                      "code": {
                        "type": "string"
                      }
                    }
                  }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "wkt": {
                    "type": "string"
                  }
                },
                "additionalProperties": false
              }
            ]
          }
        },
        "xyCoordinateResolution": {
          "type": "number"
        },
        "zCoordinateResolution": {
          "type": "number"
        },
        "mCoordinateResolution": {
          "type": "number"
        },
        "coordinatePrecisionFormatSpecificOptions": {
          "type": "object"
        }
      },
      "required": [
        "name",
        "type"
      ],
      "additionalProperties": false
    },
    "coordinateSystem": {
      "type": "object",
      "properties": {
        "authid": {
          "type": "string",
          "description": "A SRS definition in the form <authority>:<code> (e.g. EPSG:4326)"
        },
        "wkt": {
          "type": "string"
        },
        "projjson": {
          "$ref": "https://proj.org/schemas/v0.5/projjson.schema.json"
        },
        "dataAxisToSRSAxisMapping": {
          "type": "array",
          "items": {
            "type": "number",
            "minItems": 2,
            "maxItems": 3
          }
        },
        "coordinateEpoch": {
          "type": "number"
        }
      },
      "additionalProperties": false
    }
  }
}
