{
  "openapi": "3.1.0",
  "info": {
    "title": "Apinator Data Plane Server API",
    "version": "1.0.0-breaking",
    "description": "Canonical machine-readable contract for SDK implementers. RFC 7807 errors and canonical path-only signing are required."
  },
  "servers": [
    {
      "url": "https://ws-{region}.apinator.io",
      "variables": {
        "region": {
          "default": "us"
        }
      }
    },
    {
      "url": "http://localhost:8081"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "health",
        "responses": {
          "200": {
            "description": "Healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "ok"
                    }
                  },
                  "additionalProperties": false
                }
              }
            }
          }
        }
      }
    },
    "/apps/{app_id}/events": {
      "post": {
        "summary": "Publish event",
        "operationId": "publishEvent",
        "security": [
          {
            "RealtimeHMAC": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/AppIDParam"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublishEventRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Problem"
          },
          "401": {
            "$ref": "#/components/responses/Problem"
          },
          "403": {
            "$ref": "#/components/responses/Problem"
          },
          "404": {
            "$ref": "#/components/responses/Problem"
          },
          "409": {
            "$ref": "#/components/responses/Problem"
          },
          "422": {
            "$ref": "#/components/responses/Problem"
          },
          "429": {
            "$ref": "#/components/responses/Problem"
          },
          "500": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/apps/{app_id}/auth": {
      "post": {
        "summary": "Authorize channel subscription",
        "operationId": "authorizeChannel",
        "security": [
          {
            "RealtimeHMAC": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/AppIDParam"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChannelAuthRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChannelAuthResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Problem"
          },
          "401": {
            "$ref": "#/components/responses/Problem"
          },
          "403": {
            "$ref": "#/components/responses/Problem"
          },
          "404": {
            "$ref": "#/components/responses/Problem"
          },
          "422": {
            "$ref": "#/components/responses/Problem"
          },
          "429": {
            "$ref": "#/components/responses/Problem"
          },
          "500": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/apps/{app_id}/channels": {
      "get": {
        "summary": "List channels",
        "operationId": "listChannels",
        "security": [
          {
            "RealtimeHMAC": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/AppIDParam"
          },
          {
            "$ref": "#/components/parameters/FilterByPrefixParam"
          }
        ],
        "responses": {
          "200": {
            "description": "Channel list",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChannelListResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Problem"
          },
          "401": {
            "$ref": "#/components/responses/Problem"
          },
          "403": {
            "$ref": "#/components/responses/Problem"
          },
          "404": {
            "$ref": "#/components/responses/Problem"
          },
          "429": {
            "$ref": "#/components/responses/Problem"
          },
          "500": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/apps/{app_id}/channels/{channel_name}": {
      "get": {
        "summary": "Get channel",
        "operationId": "getChannel",
        "security": [
          {
            "RealtimeHMAC": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/AppIDParam"
          },
          {
            "$ref": "#/components/parameters/ChannelNameParam"
          }
        ],
        "responses": {
          "200": {
            "description": "Channel details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChannelInfo"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Problem"
          },
          "401": {
            "$ref": "#/components/responses/Problem"
          },
          "403": {
            "$ref": "#/components/responses/Problem"
          },
          "404": {
            "$ref": "#/components/responses/Problem"
          },
          "429": {
            "$ref": "#/components/responses/Problem"
          },
          "500": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ProblemDetails": {
        "type": "object",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string",
            "format": "uri-reference"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "instance": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "ChannelInfo": {
        "type": "object",
        "required": [
          "name",
          "subscription_count"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "subscription_count": {
            "type": "integer",
            "minimum": 0
          }
        },
        "additionalProperties": true
      },
      "ChannelListResponse": {
        "type": "object",
        "required": [
          "channels"
        ],
        "properties": {
          "channels": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChannelInfo"
            }
          }
        },
        "additionalProperties": false
      },
      "PublishEventRequest": {
        "type": "object",
        "required": [
          "name",
          "data"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "data": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "channels": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "socket_id": {
            "type": "string"
          }
        },
        "additionalProperties": false,
        "description": "Provide either `channel` or `channels`."
      },
      "ChannelAuthRequest": {
        "type": "object",
        "required": [
          "socket_id",
          "channel_name"
        ],
        "properties": {
          "socket_id": {
            "type": "string"
          },
          "channel_name": {
            "type": "string"
          },
          "channel_data": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "ChannelAuthResponse": {
        "type": "object",
        "required": [
          "auth"
        ],
        "properties": {
          "auth": {
            "type": "string"
          },
          "channel_data": {
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    },
    "responses": {
      "Problem": {
        "description": "RFC 7807 problem details",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ProblemDetails"
            }
          }
        }
      }
    },
    "securitySchemes": {
      "RealtimeHMAC": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Realtime-Signature",
        "description": "HMAC auth uses X-Realtime-Key, X-Realtime-Timestamp, and X-Realtime-Signature headers. Signature input must use request path without query string."
      }
    },
    "parameters": {
      "AppIDParam": {
        "name": "app_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        },
        "description": "Application ID"
      },
      "ChannelNameParam": {
        "name": "channel_name",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "Channel name"
      },
      "FilterByPrefixParam": {
        "name": "filter_by_prefix",
        "in": "query",
        "required": false,
        "schema": {
          "type": "string"
        },
        "description": "Optional channel name prefix filter. Legacy `prefix` is removed and rejected."
      }
    }
  }
}
