{
  "openapi": "3.1.0",
  "info": {
    "title": "One News Page Open Search API",
    "version": "1.0.0",
    "description": "Anonymous, read-only discovery of published One News Page coverage. The endpoint URL is permanent and unversioned; new fields and optional parameters will be added compatibly. The version field in results identifies the response contract generation, not a versioned URL. Original publisher reporting remains subject to publisher rights."
  },
  "paths": {
    "/api/search": {
      "get": {
        "operationId": "searchOneNewsPage",
        "summary": "Search published One News Page news",
        "security": [],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "Up to 160 characters after normalization and eight search terms. Include at least one term containing two letters or numbers. All terms must occur in the public title and summary combined. Punctuation separates terms.",
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 160
            },
            "example": "climate"
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "story",
                "event",
                "briefing",
                "topic"
              ],
              "default": "all"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Single-type requests only, with a default of 15. Grouped response caps are 8 Stories, 3 Events, 3 Briefings and 2 Topics.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 30
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Inclusive public result date, starting at midnight UTC. Undated entries are excluded when a date bound is supplied.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Exclusive public result date, starting at midnight UTC. Must be later than from when both are supplied.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "format",
            "in": "query",
            "description": "JSON by default; Markdown is a compact representation of the same verified results. Error responses are always JSON.",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "markdown"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Results from the currently confirmed, admitted publication. Bounded result groups may be empty. Coverage indicates the reconciliation state.",
            "headers": {
              "Server-Timing": {
                "description": "Preview search and D1 durations in milliseconds.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              },
              "text/markdown": {
                "schema": {
                  "type": "string"
                },
                "description": "Human- and agent-readable results containing links to canonical ONP pages."
              }
            }
          },
          "400": {
            "description": "Invalid query or parameters. Each parameter can appear once.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Only GET is permitted (OPTIONS available for CORS preflight).",
            "headers": {
              "Allow": {
                "schema": {
                  "const": "GET"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The current confirmed publication or its live A/B snapshot is temporarily unavailable.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Approximate per-location rate limit exceeded. Respect Retry-After and back off.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "All search terms must match across the verified public title and summary. Results are bounded and may change as the news develops. `from` is inclusive and `to` exclusive in UTC. When `type=all` the group caps are fixed; `limit` is only valid for a single type. No API key required. No promise of full publisher-text redistribution."
      }
    }
  },
  "components": {
    "schemas": {
      "SearchResponse": {
        "type": "object",
        "required": [
          "version",
          "publisher",
          "query",
          "coverage",
          "groups"
        ],
        "additionalProperties": false,
        "properties": {
          "version": {
            "const": 1
          },
          "publisher": {
            "const": "One News Page"
          },
          "query": {
            "type": "string"
          },
          "coverage": {
            "type": "string",
            "enum": [
              "complete",
              "partial"
            ],
            "description": "Whether the requested types are reconciled. The result list is bounded in both states."
          },
          "groups": {
            "type": "object",
            "additionalProperties": false,
            "minProperties": 1,
            "properties": {
              "stories": {
                "$ref": "#/components/schemas/ResultGroup"
              },
              "events": {
                "$ref": "#/components/schemas/ResultGroup"
              },
              "briefings": {
                "$ref": "#/components/schemas/ResultGroup"
              },
              "topics": {
                "$ref": "#/components/schemas/ResultGroup"
              }
            }
          }
        }
      },
      "ResultGroup": {
        "type": "object",
        "required": [
          "items",
          "hasMore"
        ],
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 30,
            "items": {
              "$ref": "#/components/schemas/Result"
            }
          },
          "hasMore": {
            "type": "boolean",
            "description": "The bounded candidate pool contains more eligible matches than returned."
          }
        }
      },
      "Result": {
        "type": "object",
        "required": [
          "type",
          "path",
          "url",
          "title",
          "date",
          "dateBasis",
          "snippet"
        ],
        "additionalProperties": false,
        "properties": {
          "type": {
            "enum": [
              "story",
              "event",
              "briefing",
              "topic"
            ]
          },
          "path": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Absolute canonical ONP citation URL."
          },
          "title": {
            "type": "string"
          },
          "date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "dateBasis": {
            "enum": [
              "story_first_published",
              "event_first_published",
              "briefing_edition_published",
              "topic_latest_public_coverage",
              null
            ]
          },
          "snippet": {
            "type": [
              "string",
              "null"
            ],
            "description": "A plain-text excerpt with public summary evidence, when available."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "servers": [
    {
      "url": "https://www.onenewspage.com"
    }
  ]
}
