{
  "openapi": "3.0.3",
  "info": {
    "title": "Target API",
    "version": "1.0.0",
    "description": "This API allows managing targets.",
    "contact": {
      "name": "Support",
      "email": "info@epilot.cloud",
      "url": "https://help.epilot.cloud"
    }
  },
  "tags": [
    {
      "name": "Target",
      "description": "Target operations"
    },
    {
      "name": "target_schema",
      "x-displayName": "Target",
      "description": "<SchemaDefinition schemaRef=\"#/components/schemas/Target\" />\n"
    }
  ],
  "x-tagGroups": [
    {
      "name": "APIs",
      "tags": [
        "Target"
      ]
    },
    {
      "name": "Schemas",
      "tags": [
        "target_schema"
      ]
    }
  ],
  "security": [
    {
      "EpilotAuth": []
    },
    {
      "EpilotOrg": []
    }
  ],
  "servers": [
    {
      "url": "https://target.sls.epilot.io"
    }
  ],
  "paths": {
    "/v1/target": {
      "post": {
        "operationId": "createTarget",
        "summary": "createTarget",
        "description": "Create a new target entity",
        "tags": [
          "Target"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/TargetCreateRequest"
        },
        "responses": {
          "201": {
            "$ref": "#/components/responses/TargetResponse"
          },
          "400": {
            "$ref": "#/components/responses/ClientErrorResponse"
          },
          "500": {
            "$ref": "#/components/responses/ServerErrorResponse"
          }
        }
      }
    },
    "/v1/target/{targetId}": {
      "get": {
        "operationId": "getTarget",
        "summary": "getTarget",
        "description": "Read a specific target entity by a given id",
        "tags": [
          "Target"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/TargetIdPathParam"
          },
          {
            "$ref": "#/components/parameters/HydrateQueryParam"
          },
          {
            "$ref": "#/components/parameters/StrictQueryParam"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/TargetResponse"
          },
          "400": {
            "$ref": "#/components/responses/ClientErrorResponse"
          },
          "500": {
            "$ref": "#/components/responses/ServerErrorResponse"
          }
        }
      },
      "delete": {
        "operationId": "deleteTarget",
        "summary": "deleteTarget",
        "description": "Delete a specific target entity by a given id",
        "tags": [
          "Target"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/TargetIdPathParam"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/TargetResponse"
          },
          "400": {
            "$ref": "#/components/responses/ClientErrorResponse"
          },
          "500": {
            "$ref": "#/components/responses/ServerErrorResponse"
          }
        }
      },
      "patch": {
        "operationId": "patchTarget",
        "summary": "patchTarget",
        "description": "Partially update a specific target entity's properties by a given id and a given payload",
        "tags": [
          "Target"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/TargetIdPathParam"
          }
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/TargetPatchRequest"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/TargetResponse"
          },
          "400": {
            "$ref": "#/components/responses/ClientErrorResponse"
          },
          "500": {
            "$ref": "#/components/responses/ServerErrorResponse"
          }
        }
      },
      "put": {
        "operationId": "updateTarget",
        "summary": "updateTarget",
        "description": "Completly replace a specific target entity's properties by a given id and a given payload",
        "tags": [
          "Target"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/TargetIdPathParam"
          }
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/TargetUpdateRequest"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/TargetResponse"
          },
          "400": {
            "$ref": "#/components/responses/ClientErrorResponse"
          },
          "500": {
            "$ref": "#/components/responses/ServerErrorResponse"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "EpilotAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization header with epilot OAuth2 bearer token",
        "bearerFormat": "JWT"
      },
      "EpilotOrg": {
        "description": "Overrides the target organization to allow shared tenantaccess",
        "name": "x-epilot-org-id",
        "in": "header",
        "type": "apiKey"
      }
    },
    "schemas": {
      "BaseError": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "example": 404
          },
          "message": {
            "type": "string",
            "example": "Entity not found"
          }
        },
        "required": [
          "status",
          "message"
        ]
      },
      "ServerError": {
        "$ref": "#/components/schemas/BaseError"
      },
      "ClientError": {
        "$ref": "#/components/schemas/BaseError"
      },
      "BaseUUID": {
        "type": "string",
        "format": "uuid",
        "example": "123e4567-e89b-12d3-a456-426614174000"
      },
      "BaseTags": {
        "type": "array",
        "nullable": true,
        "items": {
          "type": "string"
        }
      },
      "BasePurpose": {
        "type": "array",
        "nullable": true,
        "items": {
          "type": "string"
        }
      },
      "BaseRelation": {
        "type": "object",
        "properties": {
          "$relation": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "entity_id": {
                  "$ref": "#/components/schemas/BaseUUID"
                },
                "_tags": {
                  "$ref": "#/components/schemas/BaseTags"
                }
              }
            }
          }
        }
      },
      "BaseEntityOwner": {
        "description": "The user / organization owning this entity.\n\nNote: Owner implicitly has access to the entity regardless of ACLs.\n",
        "type": "object",
        "properties": {
          "org_id": {
            "type": "string",
            "example": "123"
          },
          "user_id": {
            "type": "string",
            "example": "123"
          }
        },
        "required": [
          "org_id"
        ]
      },
      "BaseEntityAcl": {
        "type": "object",
        "description": "Access control list (ACL) for an entity. Defines sharing access to external orgs or users.",
        "properties": {
          "view": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "org:456"
            }
          },
          "edit": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "org:456"
            }
          },
          "delete": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "org:456"
            }
          }
        }
      },
      "BaseSystemFields": {
        "type": "object",
        "properties": {
          "_tags": {
            "$ref": "#/components/schemas/BaseTags"
          },
          "_purpose": {
            "$ref": "#/components/schemas/BasePurpose"
          },
          "_files": {
            "$ref": "#/components/schemas/BaseRelation"
          },
          "_manifest": {
            "type": "array",
            "description": "Manifest ID used to create/update the entity",
            "items": {
              "type": "string",
              "format": "uuid",
              "example": "123e4567-e89b-12d3-a456-426614174000"
            }
          },
          "__additional": {
            "type": "object",
            "description": "Additional fields that are not part of the schema",
            "additionalProperties": true,
            "nullable": true,
            "example": {}
          }
        }
      },
      "BaseSystemReadonlyFields": {
        "type": "object",
        "properties": {
          "_id": {
            "$ref": "#/components/schemas/BaseUUID"
          },
          "_schema": {
            "readOnly": true,
            "type": "string"
          },
          "_org": {
            "type": "string",
            "description": "Organization Id the entity belongs to",
            "readOnly": true
          },
          "_tags": {
            "$ref": "#/components/schemas/BaseTags"
          },
          "_files": {
            "$ref": "#/components/schemas/BaseRelation"
          },
          "_owners": {
            "type": "array",
            "readOnly": true,
            "items": {
              "$ref": "#/components/schemas/BaseEntityOwner"
            }
          },
          "_title": {
            "readOnly": true,
            "type": "string"
          },
          "_created_at": {
            "readOnly": true,
            "type": "string",
            "format": "date-time"
          },
          "_updated_at": {
            "readOnly": true,
            "type": "string",
            "format": "date-time"
          },
          "_acl": {
            "$ref": "#/components/schemas/BaseEntityAcl"
          }
        }
      },
      "BaseSystemFieldsRequired": {
        "type": "object",
        "required": [
          "_schema",
          "_org"
        ]
      },
      "BaseTarget": {
        "type": "object",
        "properties": {
          "_schema": {
            "type": "string",
            "enum": [
              "target"
            ]
          },
          "name": {
            "type": "string",
            "description": "The description for the target"
          },
          "description": {
            "type": "string",
            "description": "The description of the target"
          },
          "entity_schema": {
            "type": "string",
            "description": "The schema of the target entities"
          },
          "entity_filters": {
            "type": "object",
            "description": "The filters on the targeted schema",
            "properties": {
              "filter": {
                "type": "object",
                "properties": {
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "key": {
                          "type": "string",
                          "description": "The key of the filter"
                        },
                        "operator": {
                          "type": "string",
                          "description": "The operator of the filter"
                        },
                        "value": {
                          "oneOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "array",
                              "items": {
                                "type": "string",
                                "additionalProperties": true
                              }
                            }
                          ]
                        }
                      }
                    },
                    "description": "The list of applied filters on targeted schema"
                  },
                  "combination": {
                    "type": "string",
                    "description": "The combination of the filters"
                  }
                }
              }
            }
          }
        }
      },
      "BaseTargetRequired": {
        "type": "object",
        "required": [
          "name"
        ]
      },
      "Target": {
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseSystemReadonlyFields"
          },
          {
            "$ref": "#/components/schemas/BaseTarget"
          },
          {
            "$ref": "#/components/schemas/BaseTargetRequired"
          },
          {
            "$ref": "#/components/schemas/BaseSystemFields"
          },
          {
            "$ref": "#/components/schemas/BaseSystemFieldsRequired"
          }
        ]
      },
      "TargetCreate": {
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseTarget"
          },
          {
            "$ref": "#/components/schemas/BaseSystemFields"
          },
          {
            "$ref": "#/components/schemas/BaseTargetRequired"
          }
        ]
      },
      "TargetPatch": {
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseTarget"
          },
          {
            "$ref": "#/components/schemas/BaseSystemFields"
          }
        ]
      }
    },
    "parameters": {
      "HydrateQueryParam": {
        "name": "hydrate",
        "in": "query",
        "required": false,
        "description": "Hydrates entities in relations when passed true",
        "schema": {
          "type": "boolean",
          "default": false
        }
      },
      "StrictQueryParam": {
        "name": "strict",
        "in": "query",
        "required": false,
        "description": "When passed true, the response will contain only fields that match the schema, with non-matching fields included in `__additional`",
        "schema": {
          "type": "boolean",
          "default": false
        }
      },
      "TargetIdPathParam": {
        "name": "targetId",
        "description": "The target id",
        "in": "path",
        "required": true,
        "schema": {
          "$ref": "#/components/schemas/BaseUUID"
        }
      }
    },
    "requestBodies": {
      "TargetCreateRequest": {
        "description": "Target to create",
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/TargetCreate"
            }
          }
        }
      },
      "TargetPatchRequest": {
        "description": "Target to patch",
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/TargetPatch"
            }
          }
        }
      },
      "TargetUpdateRequest": {
        "description": "Target to update",
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/TargetCreate"
            }
          }
        }
      }
    },
    "responses": {
      "ClientErrorResponse": {
        "description": "Any error based on client data errors",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ClientError"
            }
          }
        }
      },
      "ServerErrorResponse": {
        "description": "Any error based on the server-side",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ServerError"
            }
          }
        }
      },
      "TargetResponse": {
        "description": "Target entity response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Target"
            }
          }
        }
      }
    }
  }
}
