{
  "openapi": "3.1.0",
  "info": {
    "title": "FabChat discovery API",
    "summary": "Versioned discovery surface. Product CRM/WhatsApp APIs are not public.",
    "description": "URL versioning: /api/v1. Breaking changes ship as /api/v2. Deprecated versions receive Deprecation and Sunset headers (RFC 8594) for at least 90 days. Partner access uses scopes fabchat.discovery.read and fabchat.partner, issued out of band — see https://fabchat.com.br/auth.md.",
    "version": "1.0.0",
    "contact": { "name": "FabChat", "url": "https://fabchat.com.br/contato" },
    "license": { "name": "Uso restrito" }
  },
  "servers": [{ "url": "https://fabchat.com.br", "description": "Production" }],
  "tags": [{ "name": "discovery" }, { "name": "oauth" }],
  "paths": {
    "/api/v1/status": {
      "get": {
        "operationId": "getDiscoveryStatus",
        "tags": ["discovery"],
        "summary": "Discovery health",
        "description": "Confirms the public discovery surface is up. Does not expose product data.",
        "security": [{ "oauth2": ["fabchat.discovery.read"] }, {}],
        "responses": {
          "200": {
            "description": "Discovery status",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/StatusResponse" } }
            }
          },
          "401": { "$ref": "#/components/responses/Problem" },
          "404": { "$ref": "#/components/responses/Problem" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/Problem" }
        }
      }
    },
    "/oauth/token": {
      "post": {
        "operationId": "postOAuthToken",
        "tags": ["oauth"],
        "summary": "OAuth token endpoint",
        "description": "RFC 6749 token endpoint. This host does not mint public tokens; it returns a JSON OAuth error pointing to partner provisioning.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": ["grant_type"],
                "properties": {
                  "grant_type": { "type": "string" },
                  "scope": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "400": {
            "description": "OAuth error (no public token issuance)",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/OAuthError" } }
            }
          },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth2": {
        "type": "oauth2",
        "description": "Scopes are declared for agents. Tokens are not issued on this host.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://fabchat.com.br/oauth/authorize",
            "tokenUrl": "https://fabchat.com.br/oauth/token",
            "scopes": {
              "fabchat.discovery.read": "Read public discovery documents (status, catalog, llms.txt).",
              "fabchat.partner": "Partner integration provisioned out of band by the FabChat team."
            }
          }
        }
      }
    },
    "schemas": {
      "Problem": {
        "type": "object",
        "required": ["type", "title", "status", "detail", "code"],
        "properties": {
          "type": { "type": "string", "format": "uri" },
          "title": { "type": "string" },
          "status": { "type": "integer" },
          "detail": { "type": "string" },
          "code": { "type": "string" },
          "instance": { "type": "string" }
        }
      },
      "StatusResponse": {
        "type": "object",
        "required": ["code", "status", "detail"],
        "properties": {
          "type": { "type": "string" },
          "title": { "type": "string" },
          "status": { "type": "integer" },
          "code": { "type": "string" },
          "detail": { "type": "string" },
          "documentation": { "type": "string", "format": "uri" },
          "openapi": { "type": "string", "format": "uri" }
        }
      },
      "OAuthError": {
        "type": "object",
        "required": ["error", "error_description"],
        "properties": {
          "error": { "type": "string" },
          "error_description": { "type": "string" },
          "error_uri": { "type": "string", "format": "uri" }
        }
      }
    },
    "responses": {
      "Problem": {
        "description": "RFC 9457 problem+json",
        "content": {
          "application/problem+json": { "schema": { "$ref": "#/components/schemas/Problem" } }
        }
      },
      "RateLimited": {
        "description": "Too many requests",
        "headers": {
          "Retry-After": { "schema": { "type": "integer" } },
          "RateLimit-Limit": { "schema": { "type": "string" } }
        },
        "content": {
          "application/problem+json": { "schema": { "$ref": "#/components/schemas/Problem" } }
        }
      }
    }
  }
}
