{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://owlie.com/docs/schemas/connectors/definitions/scim.schema.json",
  "title": "Owlie SCIM connector definition",
  "description": "The definition.json of a scim connector (engine major 1). Owlie derives the connector's manifest from it. A value the definition makes install-editable is a bare { \"$oxl\": \"config.<name>\" } naming a field declared under config.properties; each install keeps its own copy, seeded from the field's default.",
  "type": "object",
  "required": ["engine", "baseUrl"],
  "additionalProperties": false,
  "properties": {
    "engine": {
      "type": "integer",
      "const": 1
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "icon": {
      "type": "string",
      "minLength": 1
    },
    "config": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "properties": {
          "type": "object",
          "additionalProperties": {
            "type": "object"
          }
        }
      }
    },
    "baseUrl": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "object",
          "required": ["$oxl"],
          "additionalProperties": false,
          "properties": {
            "$oxl": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      ],
      "title": "Base URL"
    },
    "auth": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "bearer": {
          "type": "object",
          "additionalProperties": false
        },
        "basic": {
          "type": "object",
          "additionalProperties": false
        },
        "oauth2-client-credentials": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "tokenUrl": {
              "type": "string",
              "minLength": 1
            },
            "scope": {
              "type": "string"
            },
            "audience": {
              "type": "string"
            }
          }
        },
        "custom-header": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "headerName": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      }
    },
    "http": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "contentType": {
          "enum": ["application/scim+json", "application/json"],
          "default": "application/scim+json"
        },
        "headers": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        }
      }
    },
    "pagination": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "style": {
          "enum": ["startIndex-count", "offset-limit", "cursor", "none"],
          "default": "startIndex-count"
        },
        "pageSize": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000,
          "default": 100
        },
        "startIndexParam": {
          "type": "string",
          "default": "startIndex"
        },
        "countParam": {
          "type": "string",
          "default": "count"
        },
        "offsetParam": {
          "type": "string",
          "default": "offset"
        },
        "limitParam": {
          "type": "string",
          "default": "limit"
        },
        "cursorParam": {
          "type": "string",
          "default": "cursor"
        },
        "nextCursorPath": {
          "type": "string",
          "default": "nextCursor"
        },
        "emptyFirstCursor": {
          "type": "boolean",
          "default": false
        }
      }
    },
    "filtering": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "attributes": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            {
              "type": "object",
              "required": ["$oxl"],
              "additionalProperties": false,
              "properties": {
                "$oxl": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          ]
        },
        "incremental": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": false
            },
            "lastModifiedPath": {
              "type": "string",
              "default": "meta.lastModified"
            },
            "operator": {
              "enum": ["gt", "ge"],
              "default": "gt"
            }
          }
        }
      }
    },
    "patch": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "supported": {
          "type": "boolean",
          "default": true
        },
        "selectorPaths": {
          "type": "boolean",
          "default": true
        },
        "opCase": {
          "enum": ["lower", "title"],
          "default": "lower"
        },
        "valueStyle": {
          "enum": ["path-value", "object"],
          "default": "path-value"
        }
      }
    },
    "users": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "endpoint": {
          "type": "string",
          "default": "/Users"
        },
        "idPath": {
          "type": "string",
          "default": "id"
        },
        "fields": {
          "anyOf": [
            {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "required": ["path"],
                "additionalProperties": false,
                "properties": {
                  "path": {
                    "type": "string",
                    "minLength": 1,
                    "title": "SCIM path"
                  },
                  "type": {
                    "enum": ["string", "boolean", "number", "datetime"],
                    "default": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "identifier": {
                    "type": "boolean"
                  },
                  "required": {
                    "type": "boolean"
                  },
                  "sensitive": {
                    "type": "boolean"
                  },
                  "readOnly": {
                    "type": "boolean"
                  },
                  "writeOnly": {
                    "type": "boolean"
                  },
                  "createOnly": {
                    "type": "boolean"
                  },
                  "reference": {
                    "type": "object",
                    "required": ["attribute"],
                    "additionalProperties": false,
                    "properties": {
                      "attribute": {
                        "type": "string",
                        "minLength": 1
                      }
                    }
                  },
                  "elementExtras": {
                    "type": "object"
                  },
                  "baseline": {
                    "type": "string",
                    "minLength": 1,
                    "title": "Provisioning baseline (OXL over identity)"
                  }
                }
              }
            },
            {
              "type": "object",
              "required": ["$oxl"],
              "additionalProperties": false,
              "properties": {
                "$oxl": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          ]
        },
        "activeAttribute": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "path": {
              "type": "string",
              "default": "active"
            },
            "enabledValue": {
              "default": true
            },
            "disabledValue": {
              "default": false
            }
          }
        }
      }
    },
    "groups": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true
        },
        "endpoint": {
          "type": "string",
          "default": "/Groups"
        },
        "idPath": {
          "type": "string",
          "default": "id"
        },
        "fields": {
          "anyOf": [
            {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "required": ["path"],
                "additionalProperties": false,
                "properties": {
                  "path": {
                    "type": "string",
                    "minLength": 1,
                    "title": "SCIM path"
                  },
                  "type": {
                    "enum": ["string", "boolean", "number", "datetime"],
                    "default": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "identifier": {
                    "type": "boolean"
                  },
                  "required": {
                    "type": "boolean"
                  },
                  "sensitive": {
                    "type": "boolean"
                  },
                  "readOnly": {
                    "type": "boolean"
                  },
                  "writeOnly": {
                    "type": "boolean"
                  },
                  "createOnly": {
                    "type": "boolean"
                  },
                  "reference": {
                    "type": "object",
                    "required": ["attribute"],
                    "additionalProperties": false,
                    "properties": {
                      "attribute": {
                        "type": "string",
                        "minLength": 1
                      }
                    }
                  },
                  "elementExtras": {
                    "type": "object"
                  },
                  "baseline": {
                    "type": "string",
                    "minLength": 1,
                    "title": "Provisioning baseline (OXL over identity)"
                  }
                }
              }
            },
            {
              "type": "object",
              "required": ["$oxl"],
              "additionalProperties": false,
              "properties": {
                "$oxl": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          ]
        },
        "manage": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "create": {
              "type": "boolean",
              "default": false
            },
            "update": {
              "type": "boolean",
              "default": false
            },
            "delete": {
              "type": "boolean",
              "default": false
            }
          }
        },
        "membership": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "mode": {
              "enum": ["patchMembers", "replaceGroupMembers"],
              "default": "patchMembers"
            },
            "addStyle": {
              "enum": ["path-value", "object", "bare-array"],
              "default": "path-value"
            },
            "membersPath": {
              "type": "string",
              "default": "members"
            },
            "memberValue": {
              "enum": ["id", "userName", "externalId"],
              "default": "id"
            },
            "readMembers": {
              "enum": ["included", "fetchGroup", "userFilter"],
              "default": "fetchGroup"
            },
            "userFilterPath": {
              "type": "string",
              "default": "groups.value"
            },
            "listExcludedAttributes": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "errors": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "conflictStatus": {
          "type": "integer",
          "minimum": 100,
          "maximum": 599,
          "default": 409
        },
        "notFoundStatus": {
          "type": "integer",
          "minimum": 100,
          "maximum": 599,
          "default": 404
        },
        "rateLimitStatus": {
          "type": "integer",
          "minimum": 100,
          "maximum": 599,
          "default": 429
        },
        "idempotency": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "assignExistingMember": {
              "enum": ["success", "fail"],
              "default": "success"
            },
            "revokeMissingMember": {
              "enum": ["success", "fail"],
              "default": "success"
            },
            "deleteMissingUser": {
              "enum": ["success", "fail"],
              "default": "success"
            }
          }
        }
      }
    }
  }
}
