{
  "openapi": "3.1.0",
  "info": {
    "title": "Open ACFR read API",
    "version": "1.0.0",
    "description": "Read-only access to data extracted from state and local government Annual Comprehensive Financial Reports. Every value links its source PDF page. Data license: CC BY 4.0.",
    "license": { "name": "CC-BY-4.0", "url": "https://creativecommons.org/licenses/by/4.0/" }
  },
  "servers": [{ "url": "https://open-acfr-grok-fb82.vercel.app" }],
  "paths": {
    "/api/entities": {
      "get": {
        "summary": "Identifier registry (LEI, FIPS, Census GEOID, fiscal year end, source PDF)",
        "parameters": [
          { "name": "state", "in": "query", "schema": { "type": "string", "pattern": "^[A-Za-z]{2}$" }, "description": "USPS state code" },
          { "name": "type", "in": "query", "schema": { "type": "string" }, "description": "state, city, county, school_district, ..." },
          { "name": "id", "in": "query", "schema": { "type": "string" } },
          { "name": "lei", "in": "query", "schema": { "type": "string", "enum": ["1"] }, "description": "Only entities with an LEI" }
        ],
        "responses": { "200": { "description": "JSON object with an entities array" } }
      }
    },
    "/api/states": { "get": { "summary": "50-state catalog with footed totals and LEIs", "responses": { "200": { "description": "JSON" } } } },
    "/api/search": {
      "get": {
        "summary": "Search line items and passages",
        "parameters": [
          { "name": "q", "in": "query", "schema": { "type": "string" } },
          { "name": "state", "in": "query", "schema": { "type": "string" } },
          { "name": "section", "in": "query", "schema": { "type": "string", "enum": ["introductory", "mda", "basic", "notes", "rsi", "supplementary", "statistical", "auditor"] } },
          { "name": "statement", "in": "query", "schema": { "type": "string" } },
          { "name": "concept", "in": "query", "schema": { "type": "string" } },
          { "name": "topic", "in": "query", "schema": { "type": "string" } },
          { "name": "kind", "in": "query", "schema": { "type": "string", "enum": ["line", "passage", "all"] } },
          { "name": "balanced", "in": "query", "schema": { "type": "string", "enum": ["1"] } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "maximum": 500 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer" } }
        ],
        "responses": { "200": { "description": "JSON with results" } }
      }
    },
    "/api/pages": {
      "get": {
        "summary": "Full-text search over every page of every report",
        "parameters": [
          { "name": "q", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "type", "in": "query", "schema": { "type": "string" } },
          { "name": "entity", "in": "query", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer" } },
          { "name": "offset", "in": "query", "schema": { "type": "integer" } }
        ],
        "responses": { "200": { "description": "JSON with hits" } }
      }
    },
    "/api/compare": {
      "get": {
        "summary": "One concept across states",
        "parameters": [{ "name": "concept", "in": "query", "schema": { "type": "string" } }],
        "responses": { "200": { "description": "JSON" } }
      }
    },
    "/api/export": {
      "get": {
        "summary": "CSV of up to 20,000 matching line items",
        "parameters": [
          { "name": "state", "in": "query", "schema": { "type": "string" } },
          { "name": "concept", "in": "query", "schema": { "type": "string" } },
          { "name": "statement", "in": "query", "schema": { "type": "string" } },
          { "name": "section", "in": "query", "schema": { "type": "string" } },
          { "name": "q", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "text/csv" } }
      }
    },
    "/api/ask": {
      "post": {
        "summary": "Plain-language question answered from the data with SQL and PDF page links",
        "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "question": { "type": "string" } } } } } },
        "responses": { "200": { "description": "JSON" } }
      }
    }
  }
}
