{
  "$defs": {
    "TemplateValue": {
      "oneOf": [
        {
          "additionalProperties": false,
          "properties": {
            "fromArtifact": {
              "additionalProperties": false,
              "properties": {
                "apiVersion": {
                  "pattern": "^[^/]+/[^/]+$",
                  "type": "string"
                },
                "dryFallback": {
                  "$ref": "#/$defs/TemplateValue",
                  "description": "Type-correct speculative value used only during dry resolution when the reference is unavailable."
                },
                "kind": {
                  "pattern": "^[A-Z][A-Za-z0-9]*$",
                  "type": "string"
                },
                "name": {
                  "pattern": "^[a-z0-9][a-z0-9-]*$",
                  "type": "string"
                },
                "pointer": {
                  "default": "",
                  "description": "JSON Pointer relative to the complete artifact resource; empty selects the whole resource.",
                  "pattern": "^(?:$|/(?:[^~]|~[01])*)$",
                  "type": "string"
                },
                "unit": {
                  "description": "Logical name of the unit that provides the referenced value.",
                  "pattern": "^[a-z0-9][a-z0-9-]*(?:/[a-z0-9][a-z0-9-]*)*$",
                  "type": "string"
                }
              },
              "required": [
                "unit",
                "name",
                "apiVersion",
                "kind"
              ],
              "type": "object"
            }
          },
          "required": [
            "fromArtifact"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "fromEnvironment": {
              "additionalProperties": false,
              "properties": {
                "pointer": {
                  "description": "JSON Pointer relative to the target Environment resource.",
                  "pattern": "^(?:$|/(?:[^~]|~[01])*)$",
                  "type": "string"
                },
                "unit": {
                  "description": "Logical name of the unit that provides the referenced value.",
                  "pattern": "^[a-z0-9][a-z0-9-]*(?:/[a-z0-9][a-z0-9-]*)*$",
                  "type": "string"
                }
              },
              "required": [],
              "type": "object"
            }
          },
          "required": [
            "fromEnvironment"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "fromPromotion": {
              "additionalProperties": false,
              "properties": {
                "dryFallback": {
                  "$ref": "#/$defs/TemplateValue",
                  "description": "Type-correct speculative value used only during dry resolution when the reference is unavailable."
                },
                "pointer": {
                  "description": "JSON Pointer relative to the promoted unit's public spec; omit it to use the containing field path, or set it to an empty string to select the whole spec.",
                  "pattern": "^(?:$|/(?:[^~]|~[01])*)$",
                  "type": "string"
                },
                "unit": {
                  "description": "Promoted source unit name; omit it to use the target unit name.",
                  "pattern": "^[a-z0-9][a-z0-9-]*(?:/[a-z0-9][a-z0-9-]*)*$",
                  "type": "string"
                }
              },
              "required": [],
              "type": "object"
            }
          },
          "required": [
            "fromPromotion"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "fromReceipt": {
              "additionalProperties": false,
              "properties": {
                "dryFallback": {
                  "$ref": "#/$defs/TemplateValue",
                  "description": "Type-correct speculative value used only during dry resolution when the reference is unavailable."
                },
                "pointer": {
                  "default": "",
                  "description": "JSON Pointer relative to the producer's typed receipt result; empty selects the whole result.",
                  "pattern": "^(?:$|/(?:[^~]|~[01])*)$",
                  "type": "string"
                },
                "unit": {
                  "description": "Logical name of the unit that provides the referenced value.",
                  "pattern": "^[a-z0-9][a-z0-9-]*(?:/[a-z0-9][a-z0-9-]*)*$",
                  "type": "string"
                }
              },
              "required": [
                "unit"
              ],
              "type": "object"
            }
          },
          "required": [
            "fromReceipt"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "fromParameter": {
              "additionalProperties": false,
              "properties": {
                "name": {
                  "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                  "type": "string"
                }
              },
              "required": [
                "name"
              ],
              "type": "object"
            }
          },
          "required": [
            "fromParameter"
          ],
          "type": "object"
        },
        {
          "type": "null"
        },
        {
          "type": "boolean"
        },
        {
          "type": "number"
        },
        {
          "type": "string"
        },
        {
          "items": {
            "$ref": "#/$defs/TemplateValue"
          },
          "type": "array"
        },
        {
          "additionalProperties": {
            "$ref": "#/$defs/TemplateValue"
          },
          "propertyNames": {
            "not": {
              "enum": [
                "fromArtifact",
                "fromEnvironment",
                "fromParameter",
                "fromPromotion",
                "fromReceipt"
              ]
            }
          },
          "type": "object"
        }
      ]
    }
  },
  "$id": "https://niklasrosenstein.github.io/gitopsctr/schemas/apis/gitopsctr.io/v1/StackTemplate/desired.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string"
    },
    "apiVersion": {
      "const": "gitopsctr.io/v1"
    },
    "kind": {
      "const": "StackTemplate"
    },
    "metadata": {
      "additionalProperties": false,
      "not": {
        "properties": {
          "labels": {
            "required": [
              "gitopsctr.io/partition"
            ]
          }
        },
        "required": [
          "ownerReferences",
          "labels"
        ]
      },
      "properties": {
        "deletion": {
          "additionalProperties": false,
          "properties": {
            "generation": {
              "minimum": 1,
              "type": "integer"
            },
            "resourceDigest": {
              "pattern": "^sha256:[0-9a-f]{64}$",
              "type": "string"
            }
          },
          "required": [
            "generation",
            "resourceDigest"
          ],
          "title": "DeletionMetadata",
          "type": "object"
        },
        "labels": {
          "additionalProperties": {
            "type": "string"
          },
          "properties": {
            "gitopsctr.io/partition": {
              "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
              "type": "string"
            }
          },
          "propertyNames": {
            "type": "string"
          },
          "type": "object"
        },
        "name": {
          "minLength": 1,
          "type": "string"
        },
        "ownerReferences": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "apiVersion": {
                "minLength": 1,
                "type": "string"
              },
              "kind": {
                "minLength": 1,
                "type": "string"
              },
              "name": {
                "minLength": 1,
                "type": "string"
              },
              "uid": {
                "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                "type": "string"
              }
            },
            "required": [
              "apiVersion",
              "kind",
              "name",
              "uid"
            ],
            "title": "DesiredOwnerReference",
            "type": "object"
          },
          "maxItems": 1,
          "minItems": 1,
          "type": "array"
        },
        "uid": {
          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
          "type": "string"
        }
      },
      "required": [
        "name",
        "uid"
      ],
      "type": "object"
    },
    "spec": {
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "acquisition": {
                "properties": {
                  "resolvedSource": {
                    "required": [
                      "fromGit"
                    ]
                  }
                },
                "required": [
                  "resolvedSource"
                ]
              }
            },
            "required": [
              "acquisition"
            ]
          },
          "then": {
            "properties": {
              "sourceContext": {
                "not": {
                  "type": "null"
                }
              }
            },
            "required": [
              "sourceContext"
            ]
          }
        }
      ],
      "anyOf": [
        {
          "properties": {
            "sourceContext": {
              "not": {
                "type": "null"
              }
            }
          },
          "required": [
            "sourceContext"
          ]
        },
        {
          "properties": {
            "unitTemplates": {
              "additionalProperties": {
                "properties": {
                  "spec": {
                    "not": {
                      "properties": {
                        "source": {
                          "anyOf": [
                            {
                              "properties": {
                                "path": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "path"
                              ]
                            },
                            {
                              "required": [
                                "fromParameter"
                              ]
                            },
                            {
                              "properties": {
                                "path": {
                                  "required": [
                                    "fromParameter"
                                  ],
                                  "type": "object"
                                }
                              },
                              "required": [
                                "path"
                              ]
                            }
                          ],
                          "type": "object"
                        }
                      },
                      "required": [
                        "source"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      ],
      "properties": {
        "acquisition": {
          "additionalProperties": false,
          "anyOf": [
            {
              "additionalProperties": false,
              "properties": {
                "documentDigest": {
                  "pattern": "^sha256:[0-9a-f]{64}$",
                  "type": "string"
                },
                "requestedSource": {
                  "additionalProperties": false,
                  "properties": {
                    "fromInput": {
                      "additionalProperties": false,
                      "title": "StackTemplateFromInput",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromInput"
                  ],
                  "title": "StackTemplateRequestedFromInput",
                  "type": "object"
                },
                "resolvedSource": {
                  "additionalProperties": false,
                  "properties": {
                    "fromInput": {
                      "additionalProperties": false,
                      "title": "StackTemplateFromInput",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromInput"
                  ],
                  "title": "StackTemplateResolvedFromInput",
                  "type": "object"
                }
              },
              "required": [
                "documentDigest",
                "requestedSource",
                "resolvedSource"
              ],
              "title": "StackTemplateInputAcquisition",
              "type": "object"
            },
            {
              "additionalProperties": false,
              "properties": {
                "documentDigest": {
                  "pattern": "^sha256:[0-9a-f]{64}$",
                  "type": "string"
                },
                "requestedSource": {
                  "additionalProperties": false,
                  "properties": {
                    "fromGit": {
                      "additionalProperties": false,
                      "properties": {
                        "documentDigest": {
                          "anyOf": [
                            {
                              "pattern": "^sha256:[0-9a-f]{64}$",
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "default": null
                        },
                        "path": {
                          "pattern": "^(?!/)(?!.*\\\\)(?!.*(?:^|/)(?:\\.{1,2})(?:/|$))[^/]+(?:/[^/]+)*$",
                          "type": "string"
                        },
                        "repository": {
                          "pattern": "^[^\\s\\x00]+$",
                          "type": "string"
                        },
                        "revision": {
                          "pattern": "^[A-Za-z0-9][A-Za-z0-9._/-]*$",
                          "type": "string"
                        }
                      },
                      "required": [
                        "repository",
                        "revision",
                        "path"
                      ],
                      "title": "StackTemplateGitRequest",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromGit"
                  ],
                  "title": "StackTemplateRequestedFromGit",
                  "type": "object"
                },
                "resolvedSource": {
                  "additionalProperties": false,
                  "properties": {
                    "fromGit": {
                      "additionalProperties": false,
                      "properties": {
                        "path": {
                          "pattern": "^(?!/)(?!.*\\\\)(?!.*(?:^|/)(?:\\.{1,2})(?:/|$))[^/]+(?:/[^/]+)*$",
                          "type": "string"
                        },
                        "repository": {
                          "pattern": "^[^\\s\\x00]+$",
                          "type": "string"
                        },
                        "revision": {
                          "pattern": "^[0-9a-f]{40}$",
                          "type": "string"
                        }
                      },
                      "required": [
                        "repository",
                        "revision",
                        "path"
                      ],
                      "title": "StackTemplateResolvedFromGit",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromGit"
                  ],
                  "title": "StackTemplateResolvedFromGitSource",
                  "type": "object"
                }
              },
              "required": [
                "documentDigest",
                "requestedSource",
                "resolvedSource"
              ],
              "title": "StackTemplateGitAcquisition",
              "type": "object"
            },
            {
              "additionalProperties": false,
              "properties": {
                "documentDigest": {
                  "pattern": "^sha256:[0-9a-f]{64}$",
                  "type": "string"
                },
                "requestedSource": {
                  "additionalProperties": false,
                  "properties": {
                    "fromPromotion": {
                      "additionalProperties": false,
                      "properties": {
                        "stack": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        }
                      },
                      "required": [
                        "stack"
                      ],
                      "title": "StackTemplatePromotionRequest",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromPromotion"
                  ],
                  "title": "StackTemplateRequestedFromPromotion",
                  "type": "object"
                },
                "resolvedSource": {
                  "additionalProperties": false,
                  "properties": {
                    "fromPromotion": {
                      "additionalProperties": false,
                      "properties": {
                        "desiredRef": {
                          "pattern": "^[A-Za-z0-9][A-Za-z0-9._/-]*$",
                          "type": "string"
                        },
                        "desiredRevision": {
                          "pattern": "^[0-9a-f]{40}$",
                          "type": "string"
                        },
                        "environment": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        },
                        "stack": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        },
                        "stackUid": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        },
                        "template": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        },
                        "templateContentDigest": {
                          "pattern": "^sha256:[0-9a-f]{64}$",
                          "type": "string"
                        },
                        "templateUid": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        }
                      },
                      "required": [
                        "environment",
                        "desiredRef",
                        "desiredRevision",
                        "stack",
                        "stackUid",
                        "template",
                        "templateUid",
                        "templateContentDigest"
                      ],
                      "title": "StackTemplateResolvedFromPromotion",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromPromotion"
                  ],
                  "title": "StackTemplateResolvedFromPromotionSource",
                  "type": "object"
                }
              },
              "required": [
                "documentDigest",
                "requestedSource",
                "resolvedSource"
              ],
              "title": "StackTemplatePromotionAcquisition",
              "type": "object"
            }
          ],
          "properties": {
            "documentDigest": {
              "pattern": "^sha256:[0-9a-f]{64}$",
              "type": "string"
            },
            "requestedSource": {
              "anyOf": [
                {
                  "additionalProperties": false,
                  "properties": {
                    "fromInput": {
                      "additionalProperties": false,
                      "title": "StackTemplateFromInput",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromInput"
                  ],
                  "title": "StackTemplateRequestedFromInput",
                  "type": "object"
                },
                {
                  "additionalProperties": false,
                  "properties": {
                    "fromGit": {
                      "additionalProperties": false,
                      "properties": {
                        "documentDigest": {
                          "anyOf": [
                            {
                              "pattern": "^sha256:[0-9a-f]{64}$",
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "default": null
                        },
                        "path": {
                          "pattern": "^(?!/)(?!.*\\\\)(?!.*(?:^|/)(?:\\.{1,2})(?:/|$))[^/]+(?:/[^/]+)*$",
                          "type": "string"
                        },
                        "repository": {
                          "pattern": "^[^\\s\\x00]+$",
                          "type": "string"
                        },
                        "revision": {
                          "pattern": "^[A-Za-z0-9][A-Za-z0-9._/-]*$",
                          "type": "string"
                        }
                      },
                      "required": [
                        "repository",
                        "revision",
                        "path"
                      ],
                      "title": "StackTemplateGitRequest",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromGit"
                  ],
                  "title": "StackTemplateRequestedFromGit",
                  "type": "object"
                },
                {
                  "additionalProperties": false,
                  "properties": {
                    "fromPromotion": {
                      "additionalProperties": false,
                      "properties": {
                        "stack": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        }
                      },
                      "required": [
                        "stack"
                      ],
                      "title": "StackTemplatePromotionRequest",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromPromotion"
                  ],
                  "title": "StackTemplateRequestedFromPromotion",
                  "type": "object"
                }
              ]
            },
            "resolvedSource": {
              "anyOf": [
                {
                  "additionalProperties": false,
                  "properties": {
                    "fromInput": {
                      "additionalProperties": false,
                      "title": "StackTemplateFromInput",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromInput"
                  ],
                  "title": "StackTemplateResolvedFromInput",
                  "type": "object"
                },
                {
                  "additionalProperties": false,
                  "properties": {
                    "fromGit": {
                      "additionalProperties": false,
                      "properties": {
                        "path": {
                          "pattern": "^(?!/)(?!.*\\\\)(?!.*(?:^|/)(?:\\.{1,2})(?:/|$))[^/]+(?:/[^/]+)*$",
                          "type": "string"
                        },
                        "repository": {
                          "pattern": "^[^\\s\\x00]+$",
                          "type": "string"
                        },
                        "revision": {
                          "pattern": "^[0-9a-f]{40}$",
                          "type": "string"
                        }
                      },
                      "required": [
                        "repository",
                        "revision",
                        "path"
                      ],
                      "title": "StackTemplateResolvedFromGit",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromGit"
                  ],
                  "title": "StackTemplateResolvedFromGitSource",
                  "type": "object"
                },
                {
                  "additionalProperties": false,
                  "properties": {
                    "fromPromotion": {
                      "additionalProperties": false,
                      "properties": {
                        "desiredRef": {
                          "pattern": "^[A-Za-z0-9][A-Za-z0-9._/-]*$",
                          "type": "string"
                        },
                        "desiredRevision": {
                          "pattern": "^[0-9a-f]{40}$",
                          "type": "string"
                        },
                        "environment": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        },
                        "stack": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        },
                        "stackUid": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        },
                        "template": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        },
                        "templateContentDigest": {
                          "pattern": "^sha256:[0-9a-f]{64}$",
                          "type": "string"
                        },
                        "templateUid": {
                          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                          "type": "string"
                        }
                      },
                      "required": [
                        "environment",
                        "desiredRef",
                        "desiredRevision",
                        "stack",
                        "stackUid",
                        "template",
                        "templateUid",
                        "templateContentDigest"
                      ],
                      "title": "StackTemplateResolvedFromPromotion",
                      "type": "object"
                    }
                  },
                  "required": [
                    "fromPromotion"
                  ],
                  "title": "StackTemplateResolvedFromPromotionSource",
                  "type": "object"
                }
              ]
            }
          },
          "required": [
            "documentDigest",
            "requestedSource",
            "resolvedSource"
          ],
          "title": "StackTemplateAcquisition",
          "type": "object"
        },
        "contentDigest": {
          "pattern": "^sha256:[0-9a-f]{64}$",
          "type": "string"
        },
        "parameters": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "name": {
                "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                "type": "string"
              },
              "type": {
                "enum": [
                  "string",
                  "integer",
                  "number",
                  "boolean",
                  "object",
                  "array"
                ]
              }
            },
            "required": [
              "name",
              "type"
            ],
            "title": "ParameterDeclaration",
            "type": "object"
          },
          "type": "array"
        },
        "sourceContext": {
          "anyOf": [
            {
              "additionalProperties": false,
              "properties": {
                "repository": {
                  "pattern": "^[^\\s\\x00]+$",
                  "type": "string"
                },
                "revision": {
                  "pattern": "^[0-9a-f]{40}$",
                  "type": "string"
                }
              },
              "required": [
                "repository",
                "revision"
              ],
              "title": "StackTemplateSourceContext",
              "type": "object"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "unitTemplates": {
          "additionalProperties": {
            "additionalProperties": false,
            "properties": {
              "apiVersion": {
                "pattern": "^[^/]+/[^/]+$",
                "type": "string"
              },
              "dependsOn": {
                "items": {
                  "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
                  "type": "string"
                },
                "type": "array"
              },
              "kind": {
                "pattern": "^[A-Z][A-Za-z0-9]*$",
                "type": "string"
              },
              "spec": {
                "additionalProperties": {
                  "$ref": "#/$defs/TemplateValue"
                },
                "propertyNames": {
                  "not": {
                    "enum": [
                      "fromArtifact",
                      "fromEnvironment",
                      "fromParameter",
                      "fromPromotion",
                      "fromReceipt"
                    ]
                  }
                },
                "type": "object"
              }
            },
            "required": [
              "apiVersion",
              "kind",
              "spec"
            ],
            "title": "StackTemplateUnitTemplate",
            "type": "object"
          },
          "propertyNames": {
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
            "type": "string"
          },
          "type": "object"
        }
      },
      "required": [
        "parameters",
        "unitTemplates",
        "contentDigest",
        "acquisition"
      ],
      "type": "object"
    }
  },
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "spec"
  ],
  "title": "StackTemplate (gitopsctr.io/v1)",
  "type": "object"
}
