{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opendapi.org/spec/0-0-1/opendapi.config.json",
  "$defs": {
    "model_allowlist": {
      "type": "array",
      "items": {
        "type": "string",
        "description": "A regex pattern to allowlist models to document by their name, or filepath (using path: prefix)",
        "examples": ["^users$", "^businesses", ".*_staging$", "path:\/marts\/", "path:prisma\/"],
        "minLength": 1
      },
      "description": "List of regex patterns to allowlist models in the integration. Empty means all models are allowlisted"
    },
    "playbook": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "add_source_datastore",
              "description": "Add a source datastore to the dataset DAPI"
            },
            "datastore_urn": {
              "type": "string",
              "description": "The URN of the source datastore to add to the dataset DAPI",
              "examples": ["my_company.datastores.mysql"]
            },
            "namespace": {
              "type": ["string", "null"],
              "description": "The database or schema of the source datastore to add to the dataset DAPI",
              "examples": ["my_database.public", "my_schema"]
            },
            "identifier_prefix": {
              "type": ["string", "null"],
              "description": "The prefix to add to the table_name to identify the dataset in the source datastore",
              "examples": ["production_", "staging_"]
            }
          },
          "required": ["type", "datastore_urn"],
          "description": "Add a source datastore to the dataset DAPI"
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "add_sink_datastore",
              "description": "Add a sink datastore to the dataset DAPI"
            },
            "datastore_urn": {
              "type": "string",
              "description": "The URN of the sink datastore to add to the dataset DAPI",
              "examples": ["my_company.datastores.snowflake"]
            },
            "namespace": {
              "type": ["string", "null"],
              "description": "The database or schema of the sink datastore to add to the dataset DAPI",
              "examples": ["my_database.public", "my_schema"]
            },
            "identifier_prefix": {
              "type": ["string", "null"],
              "description": "The prefix to add to the table_name to identify the dataset in the sink datastore",
              "examples": ["production_", "staging_"]
            }
          },
          "required": ["type", "datastore_urn"],
          "description": "Add a sink datastore to the dataset DAPI"
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "add_owner_team",
              "description": "Add a team to the dataset DAPI based on a rule"
            },
            "model_allowlist": {
              "$ref": "#/$defs/model_allowlist",
              "description": "List of regex patterns to assign to this team. Empty means all models are allowlisted"
            },
            "team_urn": {
              "type": "string",
              "description": "The URN of the team to add to the dataset DAPI",
              "examples": ["my_company.teams.data_engineering"]
            }
          },
          "required": ["type", "team_urn"],
          "description": "Add a team to the dataset DAPI based on a regex pattern of model name"
        }
      ]
    },
    "activerecord": {
      "type": "object",
      "properties": {
        "type": {
          "const": "activerecord"
        },
        "applications": {
          "type": "object",
          "properties": {
            "include_all": {
              "type": "boolean",
              "default": true,
              "description": "Automatically add all applications by finding the schema.rb files"
            },
            "overrides": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "application_path": {
                    "type": "string",
                    "description": "The path to the application relative to this configuration file",
                    "examples": ["/path/to/my_rails_app"]
                  },
                  "schema_rb_path": {
                    "type": "string",
                    "description": "The path to the schema.rb file relative to the application",
                    "default": "db/schema.rb"
                  },
                  "playbooks": {
                    "type": "array",
                    "items": {
                      "$ref": "#/$defs/playbook"
                    },
                    "description": "List of playbooks to run for this application"
                  },
                  "model_allowlist": {
                    "$ref": "#/$defs/model_allowlist",
                    "description": "List of regex patterns to allowlist Activerecord models. Empty means all models are allowlisted"
                  }
                },
                "required": ["application_path"],
                "description": "Allowlist and/or override configurations for specific applications"
              }
            }
          },
          "required": ["include_all"],
          "description": "Identify Activerecord applications and their schema.rb files"
        }
      },
      "required": ["type", "applications"],
      "description": "ActiveRecord database integration"
    },
    "dbt": {
      "type": "object",
      "properties": {
        "type": {
          "const": "dbt"
        },
        "projects": {
          "type": "object",
          "properties":{
            "include_all": {
              "type": "boolean",
              "default": true,
              "description": "Automatically add all dbt projects by finding the dbt_project.yml files"
            },
            "overrides": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "project_path": {
                    "type": "string",
                    "description": "The path to the dbt project relative to this configuration file",
                    "examples": ["/path/to/my_dbt_project"]
                  },
                  "artifacts_dir": {
                    "type": "string",
                    "description": "The directory path to the dbt artifacts relative to the project_path",
                    "default": "target"
                  },
                  "playbooks": {
                    "type": "array",
                    "items": {
                      "$ref": "#/$defs/playbook"
                    },
                    "description": "List of playbooks to run for this dbt project"
                  },
                  "model_allowlist": {
                    "$ref": "#/$defs/model_allowlist",
                    "description": "List of regex patterns to allowlist DBT models. Empty means all models are allowlisted"
                  }
                },
                "required": ["project_path"],
                "description": "Allowlist and/or Override specific configurations for dbt projects"
              }
            }
          },
          "required": ["include_all"],
          "description": "Identify dbt projects and their artifacts"
        }
      },
      "required": ["type", "projects"],
      "description": "DBT database integration"
    },
    "pynamodb": {
      "type": "object",
      "properties": {
        "type": {
          "const": "pynamodb"
        },
        "services": {
          "type": "object",
          "properties": {
            "include_all": {
              "const": false,
              "default": false,
              "description": "Not supported. Please specify the services you want to include in the overrides field."
            },
            "overrides": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "service_path": {
                    "type": "string",
                    "description": "The path to the service relative to this configuration file",
                    "examples": ["/path/to/my_python_service"]
                  },
                  "is_opendapi_lib_installed": {
                    "type": "boolean",
                    "description": "Ensure that the opendapi library is installed in the service as a dev dependency. If not, the integration will fail.",
                    "default": false
                  },
                  "base_model_classes": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "description": "The base class for the service, fully qualified with module path. e.g. pynamodb.models.Model",
                      "example": "pynamodb.models.Model"
                    },
                    "minItems": 1,
                    "description": "List of base classes"
                  },
                  "playbooks": {
                    "type": "array",
                    "items": {
                      "$ref": "#/$defs/playbook"
                    },
                    "description": "List of playbooks to run for this service"
                  },
                  "model_allowlist": {
                    "$ref": "#/$defs/model_allowlist",
                    "description": "List of regex patterns to allowlist PynamoDB models. Empty means all models are allowlisted"
                  }
                },
                "required": ["service_path", "base_model_classes", "is_opendapi_lib_installed"],
                "description": "Configurations for specific services. include_all is not supported"
              }
            }
          },
          "required": ["overrides"],
          "description": "Identify PynamoDB services and their base classes"
        }
      },
      "required": ["type", "services"],
      "description": "PynamoDB database integration"
    },
    "sqlalchemy": {
      "type": "object",
      "properties": {
        "type": {
          "const": "sqlalchemy"
        },
        "services": {
          "type": "object",
          "properties": {
            "include_all": {
              "const": false,
              "default": false,
              "description": "Not supported. Please specify the services you want to include in the overrides field."
            },
            "overrides": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "service_path": {
                    "type": "string",
                    "description": "The path to the service relative to this configuration file",
                    "examples": ["/path/to/my_python_service"]
                  },
                  "is_opendapi_lib_installed": {
                    "const": true,
                    "description": "Ensure that the opendapi library is installed in the service as a dev dependency. If not, the integration will fail.",
                    "default": false
                  },
                  "metadata_objects": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "description": "The metadata object for the SQLAlchemy models, fully qualified with module path. e.g. my_service.models.metadata_object",
                      "example": "my_service.models.metadata_object"
                    },
                    "minItems": 1,
                    "description": "List of Metadata objects to use to derive all the SqlAlchemy models"
                  },
                  "playbooks": {
                    "type": "array",
                    "items": {
                      "$ref": "#/$defs/playbook"
                    },
                    "description": "List of playbooks to run for this service"
                  },
                  "model_allowlist": {
                    "$ref": "#/$defs/model_allowlist",
                    "description": "List of regex patterns to allowlist SqlAlchemy models. Empty means all models are allowlisted"
                  }
                },
                "required": ["service_path", "metadata_objects", "is_opendapi_lib_installed"],
                "description": "Configurations for specific services. include_all is not supported"
              }
            }
          },
          "required": ["overrides"],
          "description": "Identify PynamoDB services and their base classes"
        }
      },
      "required": ["type", "services"],
      "description": "PynamoDB database integration"
    },
    "sequelize": {
      "type": "object",
      "properties": {
        "type": {
          "const": "sequelize"
        },
        "packages": {
          "type": "object",
          "properties": {
            "include_all": {
              "type": "boolean",
              "default": true,
              "description": "Automatically add all packages and their models by finding the package.json files"
            },
            "overrides": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "package_path": {
                    "type": "string",
                    "description": "The path to the package relative to this configuration file",
                    "examples": ["/path/to/my_package"]
                  },
                  "playbooks": {
                    "type": "array",
                    "items": {
                      "$ref": "#/$defs/playbook"
                    },
                    "description": "List of playbooks to run for this package"
                  },
                  "model_allowlist": {
                    "$ref": "#/$defs/model_allowlist",
                    "description": "List of regex patterns to allowlist sequelize models. Empty means all models are allowlisted"
                  }
                },
                "required": ["package_path"],
                "description": "Allowlist and/or override configurations for specific applications"
              }
            }
          },
          "required": ["include_all"],
          "description": "Identify JS packages with sequelize"
        }
      },
      "required": ["type", "packages"],
      "description": "Sequelize integration"
    },
    "typeorm": {
      "type": "object",
      "properties": {
        "type": {
          "const": "typeorm"
        },
        "packages": {
          "type": "object",
          "properties": {
            "include_all": {
              "type": "boolean",
              "default": true,
              "description": "Automatically add all packages and their models by finding the package.json files"
            },
            "overrides": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "package_path": {
                    "type": "string",
                    "description": "The path to the package relative to this configuration file",
                    "examples": ["/path/to/my_package"]
                  },
                  "playbooks": {
                    "type": "array",
                    "items": {
                      "$ref": "#/$defs/playbook"
                    },
                    "description": "List of playbooks to run for this package"
                  },
                  "model_allowlist": {
                    "$ref": "#/$defs/model_allowlist",
                    "description": "List of regex patterns to allowlist typeorm models. Empty means all models are allowlisted"
                  }
                },
                "required": ["package_path"],
                "description": "Allowlist and/or override configurations for specific applications"
              }
            }
          },
          "required": ["include_all"],
          "description": "Identify TS packages with TypeORM"
        }
      },
      "required": ["type", "packages"],
      "description": "Sequelize integration"
    },
    "prisma": {
      "type": "object",
      "properties": {
        "type": {
          "const": "prisma"
        },
        "applications": {
          "type": "object",
          "properties": {
            "include_all": {
              "type": "boolean",
              "default": true,
              "description": "Automatically add all applications by finding the schema.prisma files"
            },
            "overrides": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "application_path": {
                    "type": "string",
                    "description": "The path to the application relative to this configuration file",
                    "examples": ["/path/to/my_app"]
                  },
                  "schema_path": {
                    "type": "string",
                    "description": "The path to the schema.prisma file relative to the application",
                    "default": "schema.prisma"
                  },
                  "playbooks": {
                    "type": "array",
                    "items": {
                      "$ref": "#/$defs/playbook"
                    },
                    "description": "List of playbooks to run for this application"
                  },
                  "model_allowlist": {
                    "$ref": "#/$defs/model_allowlist",
                    "description": "List of regex patterns to allowlist prisma models. Empty means all models are allowlisted"
                  }
                },
                "required": ["application_path"],
                "description": "Allowlist and/or override configurations for specific applications"
              }
            }
          },
          "required": ["include_all"],
          "description": "Identify Activerecord applications and their schema.parse files"
        }
      },
      "required": ["type", "applications"],
      "description": "Prisma ORM integration"
    }
  },
  "type": "object",
  "properties": {
    "schema": {
      "type": "string",
      "format": "uri",
      "default": "https://opendapi.org/spec/0-0-1/opendapi.config.json",
      "description": "The URI schema version for this data",
      "examples": ["https://opendapi.org/spec/0-0-1/opendapi.config.json"]
    },
    "organization": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "The name of the organization",
          "examples": ["Woven"]
        },
        "email_domain": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z]{2,}$",
          "description": "The email domain for the organization",
          "examples": ["wovencollab.com", "google.co"]
        }
      },
      "required": ["name", "email_domain"]
    },
    "repository": {
      "type": "object",
      "properties": {
        "urn": {
          "type": "string",
          "pattern": "^([\\w-]+\\.)+[\\w-]+$",
          "description": "Unique key for this repository. Must be unique within the organization",
          "examples": ["my_company.my_repo"]
        },
        "mainline_branch": {
          "type": "string",
          "description": "The mainline branch of the repository",
          "default": "main",
          "examples": ["main", "master"]
        }
      },
      "required": ["urn", "mainline_branch"],
      "description": "Github Repository settings",
      "title": "Git Repository settings"
    },
    "dapis": {
      "type": "object",
      "properties": {
          "integrations": {
              "type": "array",
              "items": {
                "oneOf": [
                  { "$ref": "#/$defs/activerecord" },
                  { "$ref": "#/$defs/dbt"},
                  { "$ref": "#/$defs/pynamodb"},
                  { "$ref": "#/$defs/sqlalchemy"},
                  { "$ref": "#/$defs/sequelize"},
                  { "$ref": "#/$defs/typeorm"},
                  { "$ref": "#/$defs/prisma"}
                ]
              },
              "minItems": 1,
              "description": "List of fields in this data."
          }
      },
      "description": "Integrations and settings for the DAPI file",
      "title": ".dapi.yaml setup configurations"
    }
  },
  "required": ["schema", "organization", "dapis", "repository"],
  "description": "Configures this github repo for use with the OpenDAPI specification",
  "title": "OpenDAPI configuration specification"
}
