{
  "openapi": "3.1.0",
  "info": {
    "title": "Comunidad App Public API",
    "version": "1.0.0",
    "summary": "Public APIs for the Comunidad App marketing site: contact, MCP, and OAuth.",
    "description": "Machine-readable API for AI agents and integrators. Use OAuth 2.0 with the documented scopes. Product accounts at gestor.comunidadapp.es are a separate authenticated application and are not part of this surface.",
    "contact": {
      "name": "Comunidad App",
      "email": "hola@comunidadapp.es",
      "url": "https://comunidadapp.es/contacto/"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://comunidadapp.es/aviso-legal/"
    }
  },
  "jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
  "servers": [
    {
      "url": "https://comunidadapp.es",
      "description": "Production"
    },
    {
      "url": "https://new.comunidadapp.es",
      "description": "Sandbox / staging"
    }
  ],
  "tags": [
    {
      "name": "Contact",
      "description": "Send a message to the Comunidad App team"
    },
    {
      "name": "MCP",
      "description": "Model Context Protocol endpoint"
    },
    {
      "name": "OAuth",
      "description": "OAuth 2.0 authorization server"
    },
    {
      "name": "Discovery",
      "description": "Agent-readable discovery documents"
    }
  ],
  "security": [
    {
      "oauth2": [
        "docs:read"
      ]
    }
  ],
  "paths": {
    "/api/contact": {
      "post": {
        "tags": [
          "Contact"
        ],
        "operationId": "createContactInquiry",
        "summary": "Send a contact message",
        "description": "Creates a sales, demo, or support inquiry. Browser clients send a Turnstile token. Agents should call with a Bearer access token that includes `contact:write` (Turnstile is then skipped).",
        "security": [
          {
            "oauth2": [
              "contact:write"
            ]
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactRequest"
              },
              "examples": {
                "agent": {
                  "summary": "Agent inquiry",
                  "value": {
                    "name": "Ana García",
                    "email": "ana@example.com",
                    "message": "Quiero una demo del panel gestor para 12 comunidades.",
                    "locale": "es",
                    "privacy": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Message accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing OAuth token when Bearer was sent",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Turnstile verification failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Content-Type must be application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Email delivery failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "options": {
        "tags": [
          "Contact"
        ],
        "operationId": "corsContact",
        "summary": "CORS preflight for contact",
        "security": [],
        "responses": {
          "204": {
            "description": "No content"
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "tags": [
          "MCP"
        ],
        "operationId": "mcpJsonRpc",
        "summary": "MCP Streamable HTTP endpoint",
        "description": "JSON-RPC MCP server (`contact_comunidadapp` tool and contact-form MCP App UI). Authentication is optional; `mcp:invoke` is the least-privilege scope if a token is presented.",
        "security": [
          {
            "oauth2": [
              "mcp:invoke"
            ]
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JsonRpcRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcResponse"
                }
              }
            }
          },
          "204": {
            "description": "Notification acknowledged"
          }
        }
      }
    },
    "/oauth/register": {
      "post": {
        "tags": [
          "OAuth"
        ],
        "operationId": "registerOauthClient",
        "summary": "Dynamic client registration (RFC 7591)",
        "description": "Register an OAuth client and receive `client_id` / `client_secret` API credentials.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClientRegistrationRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Client created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClientRegistrationResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid client metadata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/oauth/token": {
      "post": {
        "tags": [
          "OAuth"
        ],
        "operationId": "issueOauthToken",
        "summary": "Token endpoint",
        "description": "Supports `client_credentials`, `authorization_code` (PKCE S256), and `refresh_token`. Prefer `application/x-www-form-urlencoded`.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/TokenRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Access token issued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid grant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid client",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/oauth/authorize": {
      "get": {
        "tags": [
          "OAuth"
        ],
        "operationId": "authorizeOauth",
        "summary": "Authorization endpoint (authorization code + PKCE)",
        "security": [],
        "parameters": [
          {
            "name": "response_type",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "code"
              ]
            }
          },
          {
            "name": "client_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "redirect_uri",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            }
          },
          {
            "name": "scope",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge_method",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "S256"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Consent page HTML"
          },
          "302": {
            "description": "Redirect back to the client"
          }
        }
      }
    },
    "/oauth/revoke": {
      "post": {
        "tags": [
          "OAuth"
        ],
        "operationId": "revokeOauthToken",
        "summary": "Token revocation (RFC 7009)",
        "security": [],
        "responses": {
          "200": {
            "description": "Revocation accepted"
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "operationId": "getOpenApi",
        "summary": "OpenAPI 3.1 specification",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/.well-known/oauth-authorization-server": {
      "get": {
        "tags": [
          "OAuth",
          "Discovery"
        ],
        "operationId": "getOauthAuthorizationServer",
        "summary": "OAuth 2.0 authorization server metadata (RFC 8414)",
        "security": [],
        "responses": {
          "200": {
            "description": "Authorization server metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/.well-known/oauth-protected-resource": {
      "get": {
        "tags": [
          "OAuth",
          "Discovery"
        ],
        "operationId": "getOauthProtectedResource",
        "summary": "OAuth 2.0 protected resource metadata (RFC 9728)",
        "security": [],
        "responses": {
          "200": {
            "description": "Protected resource metadata including scopes_supported",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth 2.0 with named scopes. Agents should register at POST /oauth/register, then request a token with the least-privilege scope they need.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://comunidadapp.es/oauth/authorize",
            "tokenUrl": "https://comunidadapp.es/oauth/token",
            "refreshUrl": "https://comunidadapp.es/oauth/token",
            "scopes": {
              "contact:write": "Submit a contact inquiry to the Comunidad App team",
              "mcp:invoke": "Invoke tools on the Comunidad App MCP server",
              "docs:read": "Read public product documentation, pricing, and discovery documents"
            }
          },
          "clientCredentials": {
            "tokenUrl": "https://comunidadapp.es/oauth/token",
            "scopes": {
              "contact:write": "Submit a contact inquiry to the Comunidad App team",
              "mcp:invoke": "Invoke tools on the Comunidad App MCP server",
              "docs:read": "Read public product documentation, pricing, and discovery documents"
            }
          }
        }
      }
    },
    "schemas": {
      "ContactRequest": {
        "type": "object",
        "required": [
          "name",
          "email",
          "message",
          "privacy"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "message": {
            "type": "string",
            "maxLength": 5000
          },
          "locale": {
            "type": "string",
            "enum": [
              "es",
              "en",
              "ca",
              "ru",
              "eu",
              "gl"
            ],
            "default": "es"
          },
          "privacy": {
            "type": "boolean",
            "description": "Must be true (privacy policy accepted)"
          },
          "turnstileToken": {
            "type": "string",
            "description": "Required for unauthenticated browser clients when Turnstile is enabled"
          },
          "website": {
            "type": "string",
            "description": "Honeypot; leave empty"
          }
        }
      },
      "ContactResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "error": {
            "type": "string"
          }
        }
      },
      "JsonRpcRequest": {
        "type": "object",
        "required": [
          "jsonrpc",
          "method"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "enum": [
              "2.0"
            ]
          },
          "id": {},
          "method": {
            "type": "string"
          },
          "params": {
            "type": "object"
          }
        }
      },
      "JsonRpcResponse": {
        "type": "object"
      },
      "ClientRegistrationRequest": {
        "type": "object",
        "properties": {
          "client_name": {
            "type": "string"
          },
          "redirect_uris": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "grant_types": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "authorization_code",
                "client_credentials",
                "refresh_token"
              ]
            }
          },
          "token_endpoint_auth_method": {
            "type": "string",
            "enum": [
              "client_secret_basic",
              "client_secret_post",
              "none"
            ]
          },
          "scope": {
            "type": "string",
            "description": "Space-delimited. Supported: contact:write, mcp:invoke, docs:read"
          }
        }
      },
      "ClientRegistrationResponse": {
        "type": "object",
        "required": [
          "client_id"
        ],
        "properties": {
          "client_id": {
            "type": "string"
          },
          "client_secret": {
            "type": "string"
          },
          "client_id_issued_at": {
            "type": "integer"
          },
          "client_secret_expires_at": {
            "type": "integer"
          },
          "client_name": {
            "type": "string"
          },
          "redirect_uris": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "grant_types": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "token_endpoint_auth_method": {
            "type": "string"
          },
          "scope": {
            "type": "string"
          }
        }
      },
      "TokenRequest": {
        "type": "object",
        "required": [
          "grant_type"
        ],
        "properties": {
          "grant_type": {
            "type": "string",
            "enum": [
              "client_credentials",
              "authorization_code",
              "refresh_token"
            ]
          },
          "client_id": {
            "type": "string"
          },
          "client_secret": {
            "type": "string"
          },
          "scope": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "redirect_uri": {
            "type": "string"
          },
          "code_verifier": {
            "type": "string"
          },
          "refresh_token": {
            "type": "string"
          }
        }
      },
      "TokenResponse": {
        "type": "object",
        "required": [
          "access_token",
          "token_type",
          "expires_in"
        ],
        "properties": {
          "access_token": {
            "type": "string"
          },
          "token_type": {
            "type": "string",
            "enum": [
              "Bearer"
            ]
          },
          "expires_in": {
            "type": "integer"
          },
          "scope": {
            "type": "string"
          },
          "refresh_token": {
            "type": "string"
          },
          "resource": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "error_description": {
            "type": "string"
          },
          "ok": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
