{
  "openapi": "3.1.0",
  "info": {
    "title": "EconDash Economic Data API",
    "version": "1.0.0",
    "description": "Macroeconomic indicators and time series data via x402 and MPP payments. 753 indicators across 298 countries, including GDP, inflation, employment, trade, and more."
  },
  "servers": [
    { "url": "https://econdash.org/api/v1/m2m" }
  ],
  "paths": {
    "/indicators": {
      "get": {
        "operationId": "listIndicators",
        "summary": "List all economic indicators",
        "description": "Returns the full catalog of available economic indicators with codes, names, categories, units, and source information.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Array of indicator objects.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "code": { "type": "string", "example": "NY.GDP.MKTP.CD" },
                      "name": { "type": "string", "example": "GDP (current US$)" },
                      "category": { "type": "string", "example": "Economic Growth" },
                      "unit": { "type": "string", "example": "USD" },
                      "frequency": { "type": "string", "example": "yearly" },
                      "source": { "type": "string", "example": "World Bank" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required. Returns x402 and MPP payment challenges." }
        }
      }
    },
    "/indicators/by-slug/{slug}": {
      "get": {
        "operationId": "getIndicatorBySlug",
        "summary": "Get indicator metadata by URL slug",
        "description": "Looks up an economic indicator by its URL-friendly slug (e.g. gdp-current-us).",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "URL slug, e.g. gdp-current-us"
          }
        ],
        "responses": {
          "200": {
            "description": "Indicator metadata object.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": { "type": "string" },
                    "name": { "type": "string" },
                    "description": { "type": "string" },
                    "category": { "type": "string" },
                    "unit": { "type": "string" },
                    "frequency": { "type": "string" },
                    "source": { "type": "string" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/indicators/{code}": {
      "get": {
        "operationId": "getIndicator",
        "summary": "Get indicator metadata by code",
        "description": "Returns detailed metadata for a single economic indicator including its full name, description, unit, frequency, category, and source.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Indicator code, e.g. NY.GDP.MKTP.CD for GDP"
          }
        ],
        "responses": {
          "200": {
            "description": "Indicator metadata object.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": { "type": "string" },
                    "name": { "type": "string" },
                    "description": { "type": "string" },
                    "category": { "type": "string" },
                    "unit": { "type": "string" },
                    "frequency": { "type": "string" },
                    "source": { "type": "string" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/indicators/{code}/countries": {
      "get": {
        "operationId": "getIndicatorCountries",
        "summary": "List countries with data for an indicator",
        "description": "Returns which countries have data available for the given indicator code.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Indicator code, e.g. NY.GDP.MKTP.CD"
          }
        ],
        "responses": {
          "200": {
            "description": "Array of country objects.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "iso3": { "type": "string", "example": "USA" },
                      "name": { "type": "string", "example": "United States" },
                      "region": { "type": "string", "example": "North America" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/timeseries/{code}": {
      "get": {
        "operationId": "getTimeseries",
        "summary": "Get time series data for an indicator",
        "description": "Returns time series data points for a given indicator, optionally filtered by country and date range.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Indicator code, e.g. FP.CPI.TOTL.ZG for inflation"
          },
          {
            "name": "country",
            "in": "query",
            "schema": { "type": "string" },
            "description": "ISO 3166-1 alpha-3 country code, e.g. USA, DEU, JPN"
          },
          {
            "name": "from",
            "in": "query",
            "schema": { "type": "string", "format": "date" },
            "description": "Start date in YYYY-MM-DD format"
          },
          {
            "name": "to",
            "in": "query",
            "schema": { "type": "string", "format": "date" },
            "description": "End date in YYYY-MM-DD format"
          }
        ],
        "responses": {
          "200": {
            "description": "Time series data points.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "date": { "type": "string", "format": "date" },
                      "value": { "type": "number" },
                      "country": { "type": "string" },
                      "indicator": { "type": "string" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/timeseries/{code}/top-countries": {
      "get": {
        "operationId": "getTopCountries",
        "summary": "Get top N countries by indicator value",
        "description": "Returns the top N countries ranked by the most recent value of the given indicator.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Indicator code, e.g. NY.GDP.MKTP.CD"
          },
          {
            "name": "n",
            "in": "query",
            "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 10 },
            "description": "Number of top countries to return (1-50)"
          }
        ],
        "responses": {
          "200": {
            "description": "Array of top country objects with values.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "iso3": { "type": "string" },
                      "name": { "type": "string" },
                      "value": { "type": "number" },
                      "date": { "type": "string", "format": "date" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/countries": {
      "get": {
        "operationId": "listCountries",
        "summary": "List all available countries",
        "description": "Returns a list of all countries and regions with available economic data.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Array of country objects.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "iso3": { "type": "string", "example": "USA" },
                      "name": { "type": "string", "example": "United States" },
                      "region": { "type": "string", "example": "North America" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/countries/{iso3}": {
      "get": {
        "operationId": "getCountry",
        "summary": "Get all economic data for a country",
        "description": "Returns the complete set of available indicators and their latest values for a specific country.",
        "parameters": [
          {
            "name": "iso3",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "ISO 3166-1 alpha-3 country code, e.g. DEU, CHN, BRA"
          }
        ],
        "responses": {
          "200": {
            "description": "Country overview with indicators and latest values.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "iso3": { "type": "string" },
                    "name": { "type": "string" },
                    "region": { "type": "string" },
                    "indicators": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "code": { "type": "string" },
                          "name": { "type": "string" },
                          "latestValue": { "type": "number" },
                          "latestDate": { "type": "string" }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/countries/{iso3}/indicators": {
      "get": {
        "operationId": "getCountryIndicators",
        "summary": "List indicators available for a country",
        "description": "Returns the indicators that have data for the given ISO3 country code, with latest values.",
        "parameters": [
          {
            "name": "iso3",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "ISO 3166-1 alpha-3 country code, e.g. DEU"
          }
        ],
        "responses": {
          "200": {
            "description": "Array of indicator objects with latest values for the country.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "code": { "type": "string" },
                      "name": { "type": "string" },
                      "latestValue": { "type": "number" },
                      "latestDate": { "type": "string", "format": "date" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/categories": {
      "get": {
        "operationId": "listCategories",
        "summary": "List all indicator categories",
        "description": "Returns the list of indicator categories used to organize the economic data catalog.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Array of category objects.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name": { "type": "string", "example": "Economic Growth" },
                      "indicatorCount": { "type": "integer", "example": 42 }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/stats": {
      "get": {
        "operationId": "getStats",
        "summary": "Get database statistics",
        "description": "Returns summary statistics: total indicators, countries, data points, and last update timestamps.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Database statistics object.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "totalIndicators": { "type": "integer" },
                    "totalCountries": { "type": "integer" },
                    "totalDataPoints": { "type": "integer" },
                    "lastSync": { "type": "string" },
                    "lastFetch": { "type": "string" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/news": {
      "get": {
        "operationId": "listNews",
        "summary": "List news items",
        "description": "Returns news items, optionally filtered by indicator code, category, or country.",
        "parameters": [
          {
            "name": "indicator",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by indicator code"
          },
          {
            "name": "category",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by category name"
          },
          {
            "name": "country",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by ISO3 country code"
          }
        ],
        "responses": {
          "200": {
            "description": "Array of news items.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "integer" },
                      "title": { "type": "string" },
                      "publishedAt": { "type": "string", "format": "date-time" },
                      "source": { "type": "string" },
                      "url": { "type": "string", "format": "uri" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/news/{news_id}": {
      "get": {
        "operationId": "getNews",
        "summary": "Get a single news item by ID",
        "description": "Returns full details for a specific news item.",
        "parameters": [
          {
            "name": "news_id",
            "in": "path",
            "required": true,
            "schema": { "type": "integer" },
            "description": "News item ID"
          }
        ],
        "responses": {
          "200": {
            "description": "News item with full content.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "integer" },
                    "title": { "type": "string" },
                    "content": { "type": "string" },
                    "publishedAt": { "type": "string", "format": "date-time" },
                    "source": { "type": "string" },
                    "url": { "type": "string", "format": "uri" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/sources": {
      "get": {
        "operationId": "listSources",
        "summary": "List data sources",
        "description": "Returns the list of data sources (World Bank, FRED, OECD, etc.) that feed the economic data catalog.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Array of data source objects.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "integer" },
                      "name": { "type": "string", "example": "World Bank" },
                      "description": { "type": "string", "example": "World Development Indicators" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    },
    "/news-sources": {
      "get": {
        "operationId": "listNewsSources",
        "summary": "List RSS news sources",
        "description": "Returns the RSS news sources used to aggregate economic news.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Array of news source objects.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "integer" },
                      "name": { "type": "string", "example": "Reuters" },
                      "url": { "type": "string", "format": "uri", "example": "https://www.reuters.com" }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required." }
        }
      }
    }
  }
}
