{
  "$comment": "This file is autogenerated, do not modify it by hand.",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Catalog query language",
  "description": "A Catalog-specific query language used in the `rawq` query parameter of the Catalog APIs.",
  "anyOf": [
    {
      "$ref": "#/definitions/FieldPredicate"
    },
    {
      "$ref": "#/definitions/AndOperator"
    },
    {
      "$ref": "#/definitions/OrOperator"
    },
    {
      "$ref": "#/definitions/RelatedNode"
    }
  ],
  "examples": [
    {
      "and": [
        {
          "metadata.name": {
            "eq": "crud-service"
          }
        },
        {
          "metadata.tags": {
            "not_contains": "dev"
          }
        },
        {
          "or": [
            {
              "metadata.labels.replicas": {
                "gt": 1
              }
            },
            {
              "spec.container": {
                "exists": false
              }
            }
          ]
        },
        {
          "related": {
            "as": "source",
            "type": "urn:mia-platform-catalog:mia-platform.eu:v1alpha1:RelationshipType:part-of.mia-platform.eu",
            "where": {
              "ref": "urn:mia-platform-catalog:console.mia-platform.eu:v1alpha1:Project:my-project"
            }
          }
        }
      ]
    }
  ],
  "definitions": {
    "AndOperator": {
      "description": "A logical `AND` on an array of one or more query predicates, thus selecting the objects that satisfy all the predicates.",
      "type": "object",
      "properties": {
        "and": {
          "type": "array",
          "items": {
            "$ref": "#"
          },
          "maxItems": 20
        }
      },
      "additionalProperties": false,
      "required": [
        "and"
      ]
    },
    "FieldOperator": {
      "oneOf": [
        {
          "description": "The `eq` operator selects objects where the value of the specified field is equal to the specified value.\n\nThe operator is only applicable to fields holding a primitive value. The field may hold an array value only if it's nullable and `value` is `null`.",
          "type": "object",
          "properties": {
            "eq": {
              "$ref": "#/definitions/QueryValue"
            }
          },
          "additionalProperties": false,
          "required": [
            "eq"
          ]
        },
        {
          "description": "The `not_eq` operator selects objects where the specified field exists, and the value of the specified field is different from the specified value (even if the value is `null`).\n\nThe operator is only applicable to fields holding a primitive value. The field may hold an array value only if it's nullable and `value` is `null`.",
          "type": "object",
          "properties": {
            "not_eq": {
              "$ref": "#/definitions/QueryValue"
            }
          },
          "additionalProperties": false,
          "required": [
            "not_eq"
          ]
        },
        {
          "description": "The `contains` operator selects objects where the specified field holds an array containing the specified value.\n\nThe operator is only applicable to fields holding an homogeneous array of primitives value. The specified field can be nullable.",
          "type": "object",
          "properties": {
            "contains": {
              "$ref": "#/definitions/QueryValue"
            }
          },
          "additionalProperties": false,
          "required": [
            "contains"
          ]
        },
        {
          "description": "The `not_contains` operator selects objects where the specified field holds an array not containing the specified value.\n\nThe operator is only applicable to fields holding an homogeneous array of primitives value. The specified field can be nullable`.",
          "type": "object",
          "properties": {
            "not_contains": {
              "$ref": "#/definitions/QueryValue"
            }
          },
          "additionalProperties": false,
          "required": [
            "not_contains"
          ]
        },
        {
          "description": "The `gt` operator selects objects where the value of the specified field is greater than (i.e., `>`) the specified value.\n\nThe operator is only applicable to fields holding a numeric value.",
          "type": "object",
          "properties": {
            "gt": {
              "type": "number",
              "format": "double"
            }
          },
          "additionalProperties": false,
          "required": [
            "gt"
          ]
        },
        {
          "description": "The `gte` operator selects objects where the value of the specified field is greater than or equal to (i.e., `>=`) the specified value.\n\nThe operator is only applicable to fields holding a numeric value.",
          "type": "object",
          "properties": {
            "gte": {
              "type": "number",
              "format": "double"
            }
          },
          "additionalProperties": false,
          "required": [
            "gte"
          ]
        },
        {
          "description": "The `lt` operator selects objects where the value of the specified field is less than (i.e., `<`) the specified value.\n\nThe operator is only applicable to fields holding a numeric value.",
          "type": "object",
          "properties": {
            "lt": {
              "type": "number",
              "format": "double"
            }
          },
          "additionalProperties": false,
          "required": [
            "lt"
          ]
        },
        {
          "description": "The `lte` operator selects objects where the value of the specified field is less than or equal to (i.e., `<=`) the specified value.\n\nThe operator is only applicable to fields holding a numeric value.",
          "type": "object",
          "properties": {
            "lte": {
              "type": "number",
              "format": "double"
            }
          },
          "additionalProperties": false,
          "required": [
            "lte"
          ]
        },
        {
          "description": "The `matches` operator selects objects where the value of the specified field matches the specified pattern.\n\nThe operator is only applicable to fields holding a string value (with the exception of the `metadata.tags` field which supports the `matches` operator).",
          "type": "object",
          "properties": {
            "matches": {
              "description": "A valid regular expression literal consisting of a pattern enclosed between slashes, optionally followed by the `i` flag.",
              "type": "string",
              "examples": [
                "/^foo/i"
              ],
              "maxLength": 256
            }
          },
          "additionalProperties": false,
          "required": [
            "matches"
          ]
        },
        {
          "description": "The `exists` operator selects objects that contain or do not contain the specified field. A field with the value of `null` is considered as existing.",
          "type": "object",
          "properties": {
            "exists": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "required": [
            "exists"
          ]
        }
      ]
    },
    "FieldPredicate": {
      "description": "An expression that returns a boolean indicating whether an object matches a specified query. It must be in the form `{ \"<field>\": { \"<operator>\": \"<value>\" } }`.\n\nThe filterable fields are:\n\n- `metadata.name`,\n- `metadata.title`,\n- `metadata.tags`,\n- `metadata.labels.*`, and\n- any field under `spec` declared as selectable for that specific type. \n\nQueryable fields can only have primitives or homogeneous arrays of primitives as values.",
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/FieldOperator"
      },
      "examples": [
        {
          "metadata.name": {
            "eq": "crud-service"
          }
        }
      ],
      "maxProperties": 1,
      "minProperties": 1
    },
    "OrOperator": {
      "description": "A logical `OR` on an array of one or more query predicates, thus selecting the objects that satisfy at least one of the predicates.",
      "type": "object",
      "properties": {
        "or": {
          "type": "array",
          "items": {
            "$ref": "#"
          },
          "maxItems": 20
        }
      },
      "additionalProperties": false,
      "required": [
        "or"
      ]
    },
    "QueryValue": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "integer",
          "format": "int64"
        },
        {
          "type": "number",
          "format": "double"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ]
    },
    "RelatedNode": {
      "description": "An operator to select objects that are connected to a specified item through a relationship of a given type.",
      "type": "object",
      "properties": {
        "related": {
          "$ref": "#/definitions/RelatedOperator"
        }
      },
      "required": [
        "related"
      ]
    },
    "RelatedOperator": {
      "type": "object",
      "properties": {
        "as": {
          "description": "Role of the current item in the relationship.",
          "allOf": [
            {
              "$ref": "#/definitions/RelationshipRole"
            }
          ]
        },
        "type": {
          "description": "The full Catalog URN of the relationship type.",
          "type": "string",
          "pattern": "^urn:mia-platform-catalog:mia-platform.eu:v1alpha1:RelationshipType:[a-z0-9]([a-z0-9.-]*[a-z0-9])?$"
        },
        "where": {
          "description": "Match criteria for the other end of the relationship.",
          "allOf": [
            {
              "$ref": "#/definitions/RelatedWhere"
            }
          ]
        }
      },
      "required": [
        "type",
        "as",
        "where"
      ]
    },
    "RelatedWhere": {
      "description": "The match criteria for the other end of a `related` operator.",
      "type": "object",
      "properties": {
        "ref": {
          "description": "The full URN of the other end of the relationship.",
          "type": "string",
          "pattern": "^urn:mia-platform-catalog:([a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*):(v[0-9]+(?:alpha[0-9]+|beta[0-9]+)?):([a-zA-Z][a-zA-Z0-9]*):([a-z0-9](?:[a-z0-9.-]*[a-z0-9])?)$"
        }
      },
      "required": [
        "ref"
      ]
    },
    "RelationshipRole": {
      "description": "The role of the current item in a relationship.\n\nThe semantics of `as` are:\n- `\"source\"` matches objects that **are the source** in a relationship of the given type whose target is the item identified by `where.ref`\n- `\"target\"` matches objects that **are the target** in a relationship of the given type whose source is the item identified by `where.ref`",
      "type": "string",
      "enum": [
        "source",
        "target"
      ]
    }
  }
}
