{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://paulkov.github.io/dpone/schemas/gitops/airflow-rerun-plan.schema.json",
  "title": "dpone GitOps Airflow reproducible rerun plan contract",
  "type": "object",
  "required": [
    "schema",
    "status",
    "critical",
    "source_attempt",
    "selection",
    "resolved",
    "airflow_request",
    "retention_refs",
    "warnings",
    "blockers"
  ],
  "additionalProperties": false,
  "properties": {
    "schema": {
      "const": "dpone.airflow-rerun-plan.v1"
    },
    "status": {
      "enum": [
        "ready",
        "blocked"
      ]
    },
    "critical": {
      "type": "boolean"
    },
    "source_attempt": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "dag_id": {
          "type": "string"
        },
        "task_id": {
          "type": "string"
        },
        "run_id": {
          "type": "string"
        }
      }
    },
    "selection": {
      "type": "object",
      "required": [
        "bundle",
        "artifacts"
      ],
      "additionalProperties": false,
      "properties": {
        "bundle": {
          "enum": [
            "original",
            "latest"
          ]
        },
        "artifacts": {
          "enum": [
            "original",
            "latest"
          ]
        }
      }
    },
    "resolved": {
      "anyOf": [
        {
          "type": "object",
          "required": [
            "schema",
            "release_id",
            "deployment_id",
            "dag_spec",
            "workload_pack",
            "runtime_image_digest",
            "binding_set_ref",
            "connection_registry_ref",
            "credential_runtime_ref",
            "airflow_bundle"
          ],
          "additionalProperties": false,
          "properties": {
            "schema": {
              "const": "dpone.airflow-run-identity.v1"
            },
            "release_id": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "deployment_id": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "dag_spec": {
              "anyOf": [
                {
                  "type": "object",
                  "required": [
                    "id",
                    "sha256"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "sha256": {
                      "type": "string",
                      "pattern": "^sha256:[0-9a-f]{64}$"
                    }
                  }
                },
                {
                  "type": "null"
                }
              ]
            },
            "workload_pack": {
              "type": "object",
              "required": [
                "id",
                "sha256"
              ],
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "sha256": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                }
              }
            },
            "runtime_image_digest": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "binding_set_ref": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "connection_registry_ref": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "credential_runtime_ref": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "airflow_bundle": {
              "anyOf": [
                {
                  "type": "object",
                  "required": [
                    "backend",
                    "ref",
                    "versioned",
                    "version",
                    "snapshot_ref"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "backend": {
                      "type": "string",
                      "minLength": 1
                    },
                    "ref": {
                      "type": "string",
                      "minLength": 1,
                      "pattern": "^\\S+$",
                      "not": {
                        "pattern": "(?:[?&](?:token|password|signature|credential|x-amz-signature|x-goog-signature)=|://[^/]*@)"
                      }
                    },
                    "versioned": {
                      "type": "boolean"
                    },
                    "version": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "snapshot_ref": {
                      "anyOf": [
                        {
                          "type": "string",
                          "pattern": "^sha256:[0-9a-f]{64}$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "allOf": [
                    {
                      "if": {
                        "properties": {
                          "versioned": {
                            "const": true
                          }
                        }
                      },
                      "then": {
                        "properties": {
                          "version": {
                            "type": "string",
                            "minLength": 1
                          }
                        }
                      },
                      "else": {
                        "properties": {
                          "version": {
                            "type": "null"
                          }
                        }
                      }
                    }
                  ]
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "airflow_request": {
      "anyOf": [
        {
          "type": "object",
          "required": [
            "run_on_latest_version",
            "execution_mode"
          ],
          "additionalProperties": false,
          "properties": {
            "run_on_latest_version": {
              "type": "boolean"
            },
            "execution_mode": {
              "enum": [
                "clear_existing_run",
                "create_pinned_rerun"
              ]
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "retention_refs": {
      "type": "object",
      "required": [
        "release_ids",
        "deployment_ids"
      ],
      "additionalProperties": false,
      "properties": {
        "release_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "minItems": 0
        },
        "deployment_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "minItems": 0
        }
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "schema",
          "code",
          "stage",
          "severity",
          "message",
          "path"
        ],
        "additionalProperties": false,
        "properties": {
          "schema": {
            "const": "dpone.error.v1"
          },
          "code": {
            "type": "string",
            "minLength": 1
          },
          "stage": {
            "const": "airflow_rerun_plan"
          },
          "severity": {
            "enum": [
              "warning",
              "error"
            ]
          },
          "message": {
            "type": "string",
            "minLength": 1
          },
          "path": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "blockers": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "schema",
          "code",
          "stage",
          "severity",
          "message",
          "path"
        ],
        "additionalProperties": false,
        "properties": {
          "schema": {
            "const": "dpone.error.v1"
          },
          "code": {
            "type": "string",
            "minLength": 1
          },
          "stage": {
            "const": "airflow_rerun_plan"
          },
          "severity": {
            "enum": [
              "warning",
              "error"
            ]
          },
          "message": {
            "type": "string",
            "minLength": 1
          },
          "path": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "const": "ready"
          }
        }
      },
      "then": {
        "properties": {
          "resolved": {
            "type": "object",
            "required": [
              "schema",
              "release_id",
              "deployment_id",
              "dag_spec",
              "workload_pack",
              "runtime_image_digest",
              "binding_set_ref",
              "connection_registry_ref",
              "credential_runtime_ref",
              "airflow_bundle"
            ],
            "additionalProperties": false,
            "properties": {
              "schema": {
                "const": "dpone.airflow-run-identity.v1"
              },
              "release_id": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "deployment_id": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "dag_spec": {
                "anyOf": [
                  {
                    "type": "object",
                    "required": [
                      "id",
                      "sha256"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "id": {
                        "type": "string",
                        "minLength": 1
                      },
                      "sha256": {
                        "type": "string",
                        "pattern": "^sha256:[0-9a-f]{64}$"
                      }
                    }
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "workload_pack": {
                "type": "object",
                "required": [
                  "id",
                  "sha256"
                ],
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sha256": {
                    "type": "string",
                    "pattern": "^sha256:[0-9a-f]{64}$"
                  }
                }
              },
              "runtime_image_digest": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^sha256:[0-9a-f]{64}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "binding_set_ref": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^sha256:[0-9a-f]{64}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "connection_registry_ref": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^sha256:[0-9a-f]{64}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "credential_runtime_ref": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^sha256:[0-9a-f]{64}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "airflow_bundle": {
                "anyOf": [
                  {
                    "type": "object",
                    "required": [
                      "backend",
                      "ref",
                      "versioned",
                      "version",
                      "snapshot_ref"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "backend": {
                        "type": "string",
                        "minLength": 1
                      },
                      "ref": {
                        "type": "string",
                        "minLength": 1,
                        "pattern": "^\\S+$",
                        "not": {
                          "pattern": "(?:[?&](?:token|password|signature|credential|x-amz-signature|x-goog-signature)=|://[^/]*@)"
                        }
                      },
                      "versioned": {
                        "type": "boolean"
                      },
                      "version": {
                        "anyOf": [
                          {
                            "type": "string",
                            "minLength": 1
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "snapshot_ref": {
                        "anyOf": [
                          {
                            "type": "string",
                            "pattern": "^sha256:[0-9a-f]{64}$"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      }
                    },
                    "allOf": [
                      {
                        "if": {
                          "properties": {
                            "versioned": {
                              "const": true
                            }
                          }
                        },
                        "then": {
                          "properties": {
                            "version": {
                              "type": "string",
                              "minLength": 1
                            }
                          }
                        },
                        "else": {
                          "properties": {
                            "version": {
                              "type": "null"
                            }
                          }
                        }
                      }
                    ]
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          },
          "airflow_request": {
            "type": "object",
            "required": [
              "run_on_latest_version",
              "execution_mode"
            ],
            "additionalProperties": false,
            "properties": {
              "run_on_latest_version": {
                "type": "boolean"
              },
              "execution_mode": {
                "enum": [
                  "clear_existing_run",
                  "create_pinned_rerun"
                ]
              }
            }
          },
          "retention_refs": {
            "type": "object",
            "required": [
              "release_ids",
              "deployment_ids"
            ],
            "additionalProperties": false,
            "properties": {
              "release_ids": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                "minItems": 1
              },
              "deployment_ids": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                "minItems": 1
              }
            }
          }
        }
      }
    }
  ]
}
