openapi: 3.1.0
info:
  title: SurfaceLens API
  version: 1.0.0-preview.1
  summary: One shared model of the airside, with spatial, temporal and what-if queries.
  description: |
    SurfaceLens maps each airport data feed into one shared schema and gives each
    application one scoped connection to it. This document is the source of truth for
    the v1 API. It is a preview design: no operation is served yet. Each operation
    carries `x-release`, the preview release that will first serve it.
  contact:
    name: SurfaceLens platform team
  license:
    name: Proprietary
    identifier: LicenseRef-SurfaceLens
servers:
  - url: https://api.surfacelens.app/v1
    description: Edge. Served from Cloudflare's network and routed to the airport's home region.
  - url: https://{node}/v1
    description: On-premise gateway node installed at the airport. Same API, same keys.
    variables:
      node:
        default: surfacelens.vtbs.internal
        description: Host name assigned to the node by the airport's network team.
  - url: https://sandbox-node.surfacelens.app/v1
    description: Sandbox on-premise node, for testing failover with test keys.
security:
  - apiKey: []
tags:
  - name: Airports
    description: Airports your key can read, and the airfield model of each one.
  - name: Entities
    description: The current or historical state of aircraft, flights, vehicles, people, stands and runways.
  - name: Observations
    description: The log of facts reported by feeds, from which entity state is derived.
  - name: Events
    description: A live or replayed stream of changes to the shared model.
  - name: Feeds
    description: Sources of data, how they map into the shared schema, and their health.
  - name: Scenarios
    description: What-if simulations of an airport day, compared against a baseline.
  - name: Webhooks
    description: HTTPS callbacks for low-rate operational events.
  - name: Applications
    description: Applications, their permissions, and their API keys.
  - name: Gateway
    description: The state of the node that served the request.
  - name: Partner observations
    description: Submit and read inspection reports and aircraft positions, and find aircraft near a point, under the draft observation gateway contract.

paths:
  /airports:
    get:
      operationId: listAirports
      tags: [Airports]
      summary: List airports
      description: Returns the airports the calling key is permitted to read, in ICAO order.
      x-release: preview-1
      x-scopes: [airports:read]
      x-sample: { path: /airports }
      parameters:
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
      responses:
        '200':
          description: A page of airports.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema:
                type: object
                required: [object, data, next_cursor]
                properties:
                  object: { const: list }
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Airport' }
                  next_cursor: { $ref: '#/components/schemas/NextCursor' }
              examples:
                default:
                  value:
                    object: list
                    data:
                      - id: VTBS
                        object: airport
                        iata: BKK
                        name: Suvarnabhumi Airport
                        timezone: Asia/Bangkok
                        reference_point: { lat: 13.69, lon: 100.7501 }
                        elevation_ft: 5
                        home_region: apac
                        airfield_version: 2026-10-30.2
                        onprem_node: https://surfacelens.vtbs.internal/v1
                        environment: test
                    next_cursor: null
        default: { $ref: '#/components/responses/Error' }

  /airports/{airport}:
    get:
      operationId: getAirport
      tags: [Airports]
      summary: Retrieve an airport
      description: Returns one airport, including its home region and the base URL of its on-premise node, if it has one.
      x-release: preview-1
      x-scopes: [airports:read]
      x-sample: { path: /airports/VTBS }
      parameters:
        - $ref: '#/components/parameters/Airport'
      responses:
        '200':
          description: The airport.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Airport' }
              examples:
                default:
                  value:
                    id: VTBS
                    object: airport
                    iata: BKK
                    name: Suvarnabhumi Airport
                    timezone: Asia/Bangkok
                    reference_point: { lat: 13.69, lon: 100.7501 }
                    elevation_ft: 5
                    home_region: apac
                    airfield_version: 2026-10-30.2
                    onprem_node: https://surfacelens.vtbs.internal/v1
                    environment: test
        default: { $ref: '#/components/responses/Error' }

  /airports/{airport}/airfield:
    get:
      operationId: getAirfield
      tags: [Airports]
      summary: Retrieve the airfield model
      description: |
        Returns the airfield as a GeoJSON FeatureCollection: runways, taxiways, aprons,
        stands and named areas. Each feature's `id` is the entity ID you use everywhere
        else in the API. Coordinates follow GeoJSON order, longitude first.
      x-release: preview-1
      x-scopes: [airports:read]
      x-sample: { path: '/airports/VTBS/airfield?feature_types=runway,stand' }
      parameters:
        - $ref: '#/components/parameters/Airport'
        - $ref: '#/components/parameters/At'
        - name: feature_types
          in: query
          description: Comma-separated feature types to include. Omit for all.
          schema:
            type: array
            items: { $ref: '#/components/schemas/AirfieldFeatureType' }
          style: form
          explode: false
          example: [runway, stand]
      responses:
        '200':
          description: The airfield model in force at `at`.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
            ETag:
              description: Changes when the airfield version changes. Send it back in `If-None-Match` to receive `304`.
              schema: { type: string }
          content:
            application/geo+json:
              schema: { $ref: '#/components/schemas/Airfield' }
              examples:
                default:
                  summary: Two of 412 features shown.
                  value:
                    type: FeatureCollection
                    airport: VTBS
                    version: 2026-10-30.2
                    at: '2026-11-23T02:58:41Z'
                    features:
                      - type: Feature
                        id: runway:02R-20L
                        geometry:
                          type: LineString
                          coordinates: [[100.73897, 13.67185], [100.74912, 13.70501]]
                        properties:
                          feature_type: runway
                          designators: [02R, 20L]
                          length_m: 3700
                          width_m: 60
                          status: open
                      - type: Feature
                        id: stand:C2
                        geometry:
                          type: Point
                          coordinates: [100.75388, 13.69214]
                        properties:
                          feature_type: stand
                          name: C2
                          contact: true
                          max_wingspan_m: 65
                          status: open
        '304':
          description: The airfield has not changed since the version in `If-None-Match`.
        default: { $ref: '#/components/responses/Error' }

  /airports/{airport}/entities:
    get:
      operationId: listEntities
      tags: [Entities]
      summary: List entities
      description: |
        Returns entities at one instant. Filter by type, and by distance from a point
        with `near` and `radius`. With `near`, results are ordered by distance and each
        entity carries `distance_m`; otherwise they are ordered by ID.
      x-release: preview-1
      x-scopes: [entities:read]
      x-sample: { path: '/airports/VTBS/entities?type=aircraft&near=13.69214,100.75388&radius=600' }
      parameters:
        - $ref: '#/components/parameters/Airport'
        - name: type
          in: query
          description: Comma-separated entity types to include. Omit for all types the key may read.
          schema:
            type: array
            items: { $ref: '#/components/schemas/EntityType' }
          style: form
          explode: false
        - name: near
          in: query
          description: A point as `lat,lon` in WGS 84 decimal degrees. Requires `radius`.
          schema: { type: string, pattern: '^-?\d{1,2}(\.\d+)?,-?\d{1,3}(\.\d+)?$' }
          example: 13.69214,100.75388
        - name: radius
          in: query
          description: Distance from `near` in metres, from 1 to 20000. Requires `near`.
          schema: { type: number, minimum: 1, maximum: 20000 }
          example: 600
        - $ref: '#/components/parameters/At'
        - $ref: '#/components/parameters/KnownAt'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
      responses:
        '200':
          description: A page of entities at `at`.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/EntityPage' }
              examples:
                default:
                  value:
                    object: list
                    airport: VTBS
                    at: '2026-11-23T02:58:41Z'
                    revision: 48213377
                    data:
                      - id: aircraft:8851a4
                        object: entity
                        type: aircraft
                        label: HS-THB
                        position: { lat: 13.69212, lon: 100.75391 }
                        distance_m: 3.6
                        attributes:
                          registration: HS-THB
                          icao24: 8851a4
                          aircraft_type: A359
                          callsign: THA403
                          flight: flight:TG403-20261123
                          stand: stand:C2
                          movement: parked
                          heading_deg: 312
                          ground_speed_kt: 0
                        observed_at: '2026-11-23T02:58:39.800Z'
                        provenance:
                          position: obs_7Kc2Lq9vT0ma
                          stand: obs_2Rn8Wd4yF6pe
                          flight: obs_5Hv1Xb7sM3jk
                      - id: aircraft:76cd51
                        object: entity
                        type: aircraft
                        label: 9V-SMF
                        position: { lat: 13.69331, lon: 100.75302 }
                        distance_m: 160.2
                        attributes:
                          registration: 9V-SMF
                          icao24: 76cd51
                          aircraft_type: A359
                          callsign: SIA709
                          flight: flight:SQ709-20261123
                          stand: stand:C4
                          movement: taxi
                          heading_deg: 221
                          ground_speed_kt: 9
                        observed_at: '2026-11-23T02:58:40.600Z'
                        provenance:
                          position: obs_9Pd4Nc2wQ8ra
                          stand: obs_1Tg6Vh3kZ5mb
                          flight: obs_4Ls8Jq0eY2xc
                    next_cursor: null
        default: { $ref: '#/components/responses/Error' }

  /airports/{airport}/entities/search:
    post:
      operationId: searchEntities
      tags: [Entities]
      summary: Search entities by area
      description: |
        Returns entities inside an area at one instant. The area is a circle, a GeoJSON
        polygon, or an airfield feature such as a runway or apron. Use this operation
        when the area is too large for a query string. It reads data and is safe to retry.
      x-release: preview-1
      x-scopes: [entities:read]
      x-sample: { path: /airports/VTBS/entities/search }
      parameters:
        - $ref: '#/components/parameters/Airport'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/EntitySearch' }
            examples:
              default:
                summary: Every vehicle and person inside the runway 02R-20L strip.
                value:
                  within: { feature: runway:02R-20L, buffer_m: 75 }
                  types: [vehicle, person]
                  at: '2026-11-23T02:58:41Z'
      responses:
        '200':
          description: A page of entities inside the area.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/EntityPage' }
              examples:
                default:
                  value:
                    object: list
                    airport: VTBS
                    at: '2026-11-23T02:58:41Z'
                    revision: 48213377
                    data:
                      - id: vehicle:FM-07
                        object: entity
                        type: vehicle
                        label: Follow-me 07
                        position: { lat: 13.68342, lon: 100.74251 }
                        attributes:
                          vehicle_type: follow_me
                          operator: AOT
                          movement: moving
                          heading_deg: 18
                          ground_speed_kt: 22
                          runway_clearance: runway:02R-20L
                        observed_at: '2026-11-23T02:58:40.100Z'
                        provenance:
                          position: obs_8Fe3Mr6tB1qa
                          runway_clearance: obs_3Gu7Kp1nD9wz
                    next_cursor: null
        default: { $ref: '#/components/responses/Error' }

  /airports/{airport}/entities/{entity}:
    get:
      operationId: getEntity
      tags: [Entities]
      summary: Retrieve an entity
      description: Returns one entity's state at `at`, or now if `at` is omitted.
      x-release: preview-1
      x-scopes: [entities:read]
      x-sample: { path: '/airports/VTBS/entities/stand:C2' }
      parameters:
        - $ref: '#/components/parameters/Airport'
        - $ref: '#/components/parameters/Entity'
        - $ref: '#/components/parameters/At'
        - $ref: '#/components/parameters/KnownAt'
      responses:
        '200':
          description: The entity.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Entity' }
              examples:
                default:
                  value:
                    id: stand:C2
                    object: entity
                    type: stand
                    label: C2
                    position: { lat: 13.69214, lon: 100.75388 }
                    attributes:
                      status: open
                      occupied_by: aircraft:8851a4
                      allocated_to: flight:TG403-20261123
                      allocation_from: '2026-11-23T01:20:00Z'
                      allocation_until: '2026-11-23T03:25:00Z'
                      next_allocation: flight:EK385-20261123
                    observed_at: '2026-11-23T02:41:07Z'
                    provenance:
                      occupied_by: obs_2Rn8Wd4yF6pe
                      allocated_to: obs_6Wm2Ct8hR4sd
                      next_allocation: obs_0Yb5Qz7gL3ne
        default: { $ref: '#/components/responses/Error' }

  /airports/{airport}/observations:
    get:
      operationId: listObservations
      tags: [Observations]
      summary: List observations
      description: |
        Returns observations whose `observed_at` falls in `[from, to)`, oldest first.
        The window may span at most 24 hours. Filter by entity, feed or kind.
      x-release: preview-1
      x-scopes: [observations:read]
      x-sample: { path: '/airports/VTBS/observations?entity=aircraft:8851a4&kind=position&from=2026-11-23T02:58:00Z&to=2026-11-23T02:59:00Z&limit=2' }
      parameters:
        - $ref: '#/components/parameters/Airport'
        - name: from
          in: query
          required: true
          description: Inclusive start of the window, RFC 3339 in UTC.
          schema: { $ref: '#/components/schemas/Timestamp' }
        - name: to
          in: query
          required: true
          description: Exclusive end of the window, at most 24 hours after `from`.
          schema: { $ref: '#/components/schemas/Timestamp' }
        - name: entity
          in: query
          description: Only observations about this entity.
          schema: { $ref: '#/components/schemas/EntityId' }
        - name: feed
          in: query
          description: Only observations from this feed.
          schema: { $ref: '#/components/schemas/FeedId' }
        - name: kind
          in: query
          description: Comma-separated observation kinds.
          schema:
            type: array
            items: { $ref: '#/components/schemas/ObservationKind' }
          style: form
          explode: false
        - $ref: '#/components/parameters/KnownAt'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
      responses:
        '200':
          description: A page of observations.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema:
                type: object
                required: [object, airport, data, next_cursor]
                properties:
                  object: { const: list }
                  airport: { $ref: '#/components/schemas/AirportId' }
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Observation' }
                  next_cursor: { $ref: '#/components/schemas/NextCursor' }
              examples:
                default:
                  value:
                    object: list
                    airport: VTBS
                    data:
                      - id: obs_3Vn6Hy1cP8ta
                        object: observation
                        entity: aircraft:8851a4
                        feed: feed_2c9f7d1e4a
                        kind: position
                        observed_at: '2026-11-23T02:58:00.400Z'
                        received_at: '2026-11-23T02:58:00.712Z'
                        revision: 48211902
                        source_id: 8851a4-1763866680400
                        data: { lat: 13.69212, lon: 100.75391, heading_deg: 312, ground_speed_kt: 0, on_ground: true }
                      - id: obs_6Qa9Lw3rJ2vb
                        object: observation
                        entity: aircraft:8851a4
                        feed: feed_2c9f7d1e4a
                        kind: position
                        observed_at: '2026-11-23T02:58:05.400Z'
                        received_at: '2026-11-23T02:58:05.689Z'
                        revision: 48211957
                        source_id: 8851a4-1763866685400
                        data: { lat: 13.69212, lon: 100.75391, heading_deg: 312, ground_speed_kt: 0, on_ground: true }
                    next_cursor: c_bc9f2e7a41d03b6e
        default: { $ref: '#/components/responses/Error' }

  /airports/{airport}/observations/{observation}:
    get:
      operationId: getObservation
      tags: [Observations]
      summary: Retrieve an observation
      description: Returns one observation, including the raw record it was mapped from. Use it to trace an attribute back to its source through `provenance`.
      x-release: preview-1
      x-scopes: [observations:read]
      x-sample: { path: /airports/VTBS/observations/obs_2Rn8Wd4yF6pe }
      parameters:
        - $ref: '#/components/parameters/Airport'
        - name: observation
          in: path
          required: true
          description: The observation ID.
          schema: { $ref: '#/components/schemas/ObservationId' }
      responses:
        '200':
          description: The observation.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Observation' }
              examples:
                default:
                  value:
                    id: obs_2Rn8Wd4yF6pe
                    object: observation
                    entity: aircraft:8851a4
                    feed: feed_51d0a9e6f2
                    kind: allocation
                    observed_at: '2026-11-23T01:36:12Z'
                    received_at: '2026-11-23T01:36:12.284Z'
                    revision: 47960115
                    source_id: RMS-20261123-C2-0412
                    data: { stand: stand:C2, on_block_at: '2026-11-23T01:36:12Z' }
                    record:
                      mapping_version: 4
                      body: { AllocId: RMS-20261123-C2-0412, Stand: C2, Reg: HS-THB, Event: ONBLK, Time: '2026-11-23T08:36:12+07:00' }
        default: { $ref: '#/components/responses/Error' }

  /airports/{airport}/events:
    get:
      operationId: streamEvents
      tags: [Events]
      summary: Stream changes
      description: |
        Opens a server-sent events stream of changes to the shared model. Without `from`,
        the stream starts with a snapshot of matching entities and then follows live changes.
        With `from`, it replays history from that instant at `speed` times real time and,
        if `until` is omitted, continues live once it catches up.

        Each event's `id` is `epoch:revision`. Reconnect with `Last-Event-ID` to resume
        without gaps, on the edge or on the on-premise node.
      x-release: preview-1
      x-scopes: [events:read]
      x-sample: { path: '/airports/VTBS/events?types=aircraft,vehicle' }
      parameters:
        - $ref: '#/components/parameters/Airport'
        - name: types
          in: query
          description: Comma-separated entity types to include.
          schema:
            type: array
            items: { $ref: '#/components/schemas/EntityType' }
          style: form
          explode: false
        - name: bbox
          in: query
          description: Only changes to entities inside this box, as `min_lon,min_lat,max_lon,max_lat`.
          schema: { type: string }
          example: 100.7480,13.6880,100.7580,13.6960
        - name: from
          in: query
          description: Replay from this instant. Omit to start live.
          schema: { $ref: '#/components/schemas/Timestamp' }
        - name: until
          in: query
          description: End a replay at this instant and close the stream.
          schema: { $ref: '#/components/schemas/Timestamp' }
        - name: speed
          in: query
          description: Replay speed as a multiple of real time, from 1 to 60. Ignored for live streams.
          schema: { type: number, minimum: 1, maximum: 60, default: 1 }
        - name: order
          in: query
          description: 'For replays. `observed` sends changes in `observed_at` order, using everything received so far. `received` sends them in the order they arrived, leaving out anything received after the instant being replayed.'
          schema: { type: string, enum: [observed, received], default: observed }
        - name: snapshot
          in: query
          description: Send the state of every matching entity as `entity.snapshot` events before the first change.
          schema: { type: boolean, default: true }
        - name: Last-Event-ID
          in: header
          description: 'Resume after this event, as `epoch:revision`. Takes precedence over `from`.'
          schema: { type: string }
      responses:
        '200':
          description: An open event stream. A comment line is sent every 15 seconds to keep idle connections open.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            text/event-stream:
              schema: { $ref: '#/components/schemas/ChangeEvent' }
              examples:
                default:
                  value: |
                    id: 7:48213377
                    event: entity.snapshot
                    data: {"revision":48213377,"entity":{"id":"aircraft:8851a4","type":"aircraft","label":"HS-THB","position":{"lat":13.69212,"lon":100.75391},"attributes":{"movement":"parked","stand":"stand:C2"}}}

                    id: 7:48213377
                    event: snapshot.complete
                    data: {"revision":48213377,"count":214}

                    id: 7:48213421
                    event: entity.updated
                    data: {"revision":48213421,"entity":"aircraft:8851a4","changed":{"movement":"pushback","ground_speed_kt":2},"observation":"obs_1Mz5Rf8kW3ta","observed_at":"2026-11-23T02:58:44.900Z"}
        default: { $ref: '#/components/responses/Error' }
      x-codeSamples:
        - lang: curl
          source: |
            curl -N https://api.surfacelens.app/v1/airports/VTBS/events?types=aircraft,vehicle \
              -H "Authorization: Bearer $SURFACELENS_KEY"
        - lang: TypeScript
          source: |
            const res = await fetch(
              "https://api.surfacelens.app/v1/airports/VTBS/events?types=aircraft,vehicle",
              { headers: { Authorization: `Bearer ${process.env.SURFACELENS_KEY}` } },
            );

            const lines = res.body!.pipeThrough(new TextDecoderStream());
            let buffer = "";
            for await (const chunk of lines) {
              buffer += chunk;
              let end;
              while ((end = buffer.indexOf("\n\n")) >= 0) {
                const frame = buffer.slice(0, end);
                buffer = buffer.slice(end + 2);
                const event = /^event: (.+)$/m.exec(frame)?.[1];
                const data = /^data: (.+)$/m.exec(frame)?.[1];
                if (event && data) console.log(event, JSON.parse(data));
              }
            }
        - lang: Python
          source: |
            import json, os, httpx

            url = "https://api.surfacelens.app/v1/airports/VTBS/events"
            headers = {"Authorization": f"Bearer {os.environ['SURFACELENS_KEY']}"}

            with httpx.stream("GET", url, params={"types": "aircraft,vehicle"},
                              headers=headers, timeout=None) as res:
                event = None
                for line in res.iter_lines():
                    if line.startswith("event: "):
                        event = line[7:]
                    elif line.startswith("data: "):
                        print(event, json.loads(line[6:]))

  /feeds:
    post:
      operationId: createFeed
      tags: [Feeds]
      summary: Register a feed
      description: |
        Registers a data source for one airport. A new feed is `draft`: set and test its
        mapping, then activate it. Records pushed to a draft feed are refused with `conflict`.
      x-release: preview-1
      x-scopes: [feeds:write]
      x-sample: { path: /feeds }
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/FeedCreate' }
            examples:
              default:
                value:
                  airport: VTBS
                  name: AODB flight schedule
                  kind: flight_schedule
                  transport: push
                  priority: 50
      responses:
        '201':
          description: The feed was created.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Feed' }
              examples:
                default:
                  value:
                    id: feed_8b41e07c35
                    object: feed
                    airport: VTBS
                    name: AODB flight schedule
                    kind: flight_schedule
                    transport: push
                    priority: 50
                    status: draft
                    mapping_version: null
                    created_at: '2026-11-23T02:10:04Z'
                    ingest_url: https://api.surfacelens.app/v1/feeds/feed_8b41e07c35/records
        default: { $ref: '#/components/responses/Error' }
    get:
      operationId: listFeeds
      tags: [Feeds]
      summary: List feeds
      description: Returns the feeds your key can see, newest first.
      x-release: preview-1
      x-scopes: [feeds:read]
      x-sample: { path: '/feeds?airport=VTBS' }
      parameters:
        - name: airport
          in: query
          description: Only feeds for this airport.
          schema: { $ref: '#/components/schemas/AirportId' }
        - name: status
          in: query
          description: Only feeds in this status.
          schema: { $ref: '#/components/schemas/FeedStatus' }
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
      responses:
        '200':
          description: A page of feeds.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema:
                type: object
                required: [object, data, next_cursor]
                properties:
                  object: { const: list }
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Feed' }
                  next_cursor: { $ref: '#/components/schemas/NextCursor' }
              examples:
                default:
                  summary: Two of five feeds shown.
                  value:
                    object: list
                    data:
                      - id: feed_8b41e07c35
                        object: feed
                        airport: VTBS
                        name: AODB flight schedule
                        kind: flight_schedule
                        transport: push
                        priority: 50
                        status: active
                        mapping_version: 1
                        created_at: '2026-11-23T02:10:04Z'
                        ingest_url: https://api.surfacelens.app/v1/feeds/feed_8b41e07c35/records
                      - id: feed_2c9f7d1e4a
                        object: feed
                        airport: VTBS
                        name: ADS-B and multilateration
                        kind: surface_track
                        transport: push
                        priority: 80
                        status: active
                        mapping_version: 7
                        created_at: '2026-09-02T06:44:51Z'
                        ingest_url: https://api.surfacelens.app/v1/feeds/feed_2c9f7d1e4a/records
                    next_cursor: c_51f0a3d9e2b6c8a4
        default: { $ref: '#/components/responses/Error' }

  /feeds/{feed}:
    get:
      operationId: getFeed
      tags: [Feeds]
      summary: Retrieve a feed
      description: Returns one feed.
      x-release: preview-1
      x-scopes: [feeds:read]
      x-sample: { path: /feeds/feed_8b41e07c35 }
      parameters:
        - $ref: '#/components/parameters/Feed'
      responses:
        '200':
          description: The feed.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Feed' }
              examples:
                default:
                  value:
                    id: feed_8b41e07c35
                    object: feed
                    airport: VTBS
                    name: AODB flight schedule
                    kind: flight_schedule
                    transport: push
                    priority: 50
                    status: draft
                    mapping_version: 1
                    created_at: '2026-11-23T02:10:04Z'
                    ingest_url: https://api.surfacelens.app/v1/feeds/feed_8b41e07c35/records
        default: { $ref: '#/components/responses/Error' }
    patch:
      operationId: updateFeed
      tags: [Feeds]
      summary: Update a feed
      description: |
        Changes a feed's name, priority or status. Set `status` to `active` to let the
        feed change the shared model, or `paused` to stop it without losing its mapping.
        A feed can only be activated once it has a mapping.
      x-release: preview-1
      x-scopes: [feeds:write]
      x-sample: { path: /feeds/feed_8b41e07c35 }
      parameters:
        - $ref: '#/components/parameters/Feed'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/FeedUpdate' }
            examples:
              default:
                value:
                  status: active
      responses:
        '200':
          description: The updated feed.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Feed' }
              examples:
                default:
                  value:
                    id: feed_8b41e07c35
                    object: feed
                    airport: VTBS
                    name: AODB flight schedule
                    kind: flight_schedule
                    transport: push
                    priority: 50
                    status: active
                    mapping_version: 1
                    created_at: '2026-11-23T02:10:04Z'
                    ingest_url: https://api.surfacelens.app/v1/feeds/feed_8b41e07c35/records
        default: { $ref: '#/components/responses/Error' }

  /feeds/{feed}/mapping:
    put:
      operationId: putMapping
      tags: [Feeds]
      summary: Set the mapping
      description: |
        Replaces the feed's mapping and returns the new version. A mapping turns one
        source record into one or more observations about one entity. Records already
        received keep the mapping version they were mapped with.
      x-release: preview-1
      x-scopes: [feeds:write]
      x-sample: { path: /feeds/feed_8b41e07c35/mapping }
      parameters:
        - $ref: '#/components/parameters/Feed'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/MappingInput' }
            examples:
              default:
                value:
                  record_id: $.MsgId
                  observed_at: { from: $.LastUpdate, as: timestamp }
                  entity: { type: flight, key: $.FlightId }
                  emit:
                    - kind: schedule
                      data:
                        airline: $.Airline
                        number: $.FltNo
                        direction: { from: $.Dir, as: { map: { A: arrival, D: departure } } }
                        origin: $.Orig
                        destination: $.Dest
                        scheduled_at: { from: $.STD, as: timestamp }
                        estimated_at: { from: $.ETD, as: timestamp }
                    - kind: allocation
                      data:
                        aircraft: { ref: aircraft, by: registration, from: $.Reg }
                        stand: { ref: stand, from: $.Stand }
      responses:
        '200':
          description: The stored mapping.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Mapping' }
              examples:
                default:
                  value:
                    object: mapping
                    feed: feed_8b41e07c35
                    version: 1
                    created_at: '2026-11-23T02:14:30Z'
                    record_id: $.MsgId
                    observed_at: { from: $.LastUpdate, as: timestamp }
                    entity: { type: flight, key: $.FlightId }
                    emit:
                      - kind: schedule
                        data:
                          airline: $.Airline
                          number: $.FltNo
                          direction: { from: $.Dir, as: { map: { A: arrival, D: departure } } }
                          origin: $.Orig
                          destination: $.Dest
                          scheduled_at: { from: $.STD, as: timestamp }
                          estimated_at: { from: $.ETD, as: timestamp }
                      - kind: allocation
                        data:
                          aircraft: { ref: aircraft, by: registration, from: $.Reg }
                          stand: { ref: stand, from: $.Stand }
        default: { $ref: '#/components/responses/Error' }

  /feeds/{feed}/mapping/test:
    post:
      operationId: testMapping
      tags: [Feeds]
      summary: Test a mapping
      description: |
        Runs sample records through a mapping without storing anything. Pass `mapping`
        to test a draft, or omit it to test the feed's current mapping. Each record
        returns either the observations it would produce or the errors that stop it.
      x-release: preview-1
      x-scopes: [feeds:write]
      x-sample: { path: /feeds/feed_8b41e07c35/mapping/test }
      parameters:
        - $ref: '#/components/parameters/Feed'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [records]
              properties:
                mapping:
                  $ref: '#/components/schemas/MappingInput'
                  description: A draft mapping. Omit to use the stored mapping.
                records:
                  type: array
                  minItems: 1
                  maxItems: 50
                  description: Source records, exactly as the feed sends them.
                  items: { type: object }
            examples:
              default:
                value:
                  records:
                    - MsgId: AODB-7781243
                      FlightId: TG403-20261123
                      Airline: TG
                      FltNo: '403'
                      Dir: D
                      Orig: VTBS
                      Dest: WSSS
                      STD: '2026-11-23T10:25:00+07:00'
                      ETD: '2026-11-23T10:35:00+07:00'
                      Reg: HS-THB
                      Stand: C2
                      LastUpdate: '2026-11-23T09:40:12+07:00'
      responses:
        '200':
          description: The result for each record, in request order.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema:
                type: object
                required: [object, mapping_version, results]
                properties:
                  object: { const: mapping_test }
                  mapping_version:
                    type: [integer, 'null']
                    description: The stored version tested, or null for a draft.
                  results:
                    type: array
                    items: { $ref: '#/components/schemas/MappingTestResult' }
              examples:
                default:
                  value:
                    object: mapping_test
                    mapping_version: 1
                    results:
                      - index: 0
                        ok: true
                        entity: flight:TG403-20261123
                        observations:
                          - kind: schedule
                            observed_at: '2026-11-23T02:40:12Z'
                            data:
                              airline: TG
                              number: '403'
                              direction: departure
                              origin: VTBS
                              destination: WSSS
                              scheduled_at: '2026-11-23T03:25:00Z'
                              estimated_at: '2026-11-23T03:35:00Z'
                          - kind: allocation
                            observed_at: '2026-11-23T02:40:12Z'
                            data: { aircraft: aircraft:8851a4, stand: stand:C2 }
                        errors: []
        default: { $ref: '#/components/responses/Error' }

  /feeds/{feed}/records:
    post:
      operationId: ingestRecords
      tags: [Feeds]
      summary: Push records
      description: |
        Accepts up to 500 source records in the feed's own format. Each record is mapped
        and admitted independently; one bad record does not stop the others. A record whose
        `record_id` was already admitted with the same content returns `duplicate`, so
        retrying a whole batch is safe. Records may arrive in any order: `observed_at`,
        not arrival order, places them in time.
      x-release: preview-1
      x-scopes: [records:write]
      x-sample: { path: /feeds/feed_8b41e07c35/records }
      parameters:
        - $ref: '#/components/parameters/Feed'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [records]
              properties:
                records:
                  type: array
                  minItems: 1
                  maxItems: 500
                  description: Source records, exactly as the feed produces them. The request body may not exceed 1 MiB.
                  items: { type: object }
            examples:
              default:
                value:
                  records:
                    - MsgId: AODB-7781243
                      FlightId: TG403-20261123
                      Airline: TG
                      FltNo: '403'
                      Dir: D
                      Orig: VTBS
                      Dest: WSSS
                      STD: '2026-11-23T10:25:00+07:00'
                      ETD: '2026-11-23T10:35:00+07:00'
                      Reg: HS-THB
                      Stand: C2
                      LastUpdate: '2026-11-23T09:40:12+07:00'
                    - MsgId: AODB-7781244
                      FlightId: EK385-20261123
                      Airline: EK
                      FltNo: '385'
                      Dir: A
                      Orig: OMDB
                      Dest: VTBS
                      STD: '2026-11-23T12:05:00+07:00'
                      ETD: '2026-11-23T11:58:00+07:00'
                      Reg: A6-EGO
                      Stand: C2
                      LastUpdate: '2026-11-23T09:40:12+07:00'
      responses:
        '200':
          description: One result per record, in request order.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema:
                type: object
                required: [object, results]
                properties:
                  object: { const: ingest_result }
                  results:
                    type: array
                    items: { $ref: '#/components/schemas/IngestResult' }
              examples:
                default:
                  value:
                    object: ingest_result
                    results:
                      - index: 0
                        record_id: AODB-7781243
                        status: admitted
                        observations: [obs_5Hv1Xb7sM3jk, obs_8Tq4Bn2xC6wd]
                        errors: []
                      - index: 1
                        record_id: AODB-7781244
                        status: admitted
                        observations: [obs_0Yb5Qz7gL3ne, obs_7Jd3Fs9vK1pa]
                        errors: []
        '413': { $ref: '#/components/responses/Error' }
        default: { $ref: '#/components/responses/Error' }

  /feeds/{feed}/health:
    get:
      operationId: getFeedHealth
      tags: [Feeds]
      summary: Retrieve feed health
      description: |
        Returns throughput, latency and errors for the last 15 minutes. `state` is
        `healthy`, `degraded` when latency or the rejection rate exceeds the feed's
        thresholds, or `silent` when no record has arrived within `expected_interval_s`.
      x-release: preview-1
      x-scopes: [feeds:read]
      x-sample: { path: /feeds/feed_2c9f7d1e4a/health }
      parameters:
        - $ref: '#/components/parameters/Feed'
      responses:
        '200':
          description: The feed's health.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/FeedHealth' }
              examples:
                default:
                  value:
                    object: feed_health
                    feed: feed_2c9f7d1e4a
                    state: healthy
                    window: { from: '2026-11-23T02:43:41Z', to: '2026-11-23T02:58:41Z' }
                    last_record_at: '2026-11-23T02:58:40.912Z'
                    expected_interval_s: 5
                    records_per_s: 182.4
                    rejected_ratio: 0.0004
                    latency_ms: { p50: 290, p95: 610, p99: 1140 }
                    recent_errors:
                      - at: '2026-11-23T02:51:18Z'
                        code: unknown_reference
                        message: 'No aircraft with icao24 "8a03ff" is known at VTBS.'
                        count: 6
        default: { $ref: '#/components/responses/Error' }

  /scenarios:
    post:
      operationId: createScenario
      tags: [Scenarios]
      summary: Run a scenario
      description: |
        Simulates one airport day twice, once as planned and once with your changes, and
        compares the two. The scenario runs asynchronously. A full day at VTBS takes
        about four seconds. Poll the scenario, stream its progress, or subscribe to the
        `scenario.completed` webhook.
      x-release: preview-2
      x-scopes: [scenarios:write]
      x-sample: { path: /scenarios }
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ScenarioCreate' }
            examples:
              default:
                summary: Close runway 02R-20L from 10:00 to 10:30 local time.
                value:
                  airport: VTBS
                  name: 02R-20L closed 10:00-10:30
                  day: '2026-11-23'
                  changes:
                    - type: runway_closure
                      runway: runway:02R-20L
                      from: '2026-11-23T03:00:00Z'
                      until: '2026-11-23T03:30:00Z'
      responses:
        '202':
          description: The scenario was accepted and queued.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
            Location:
              description: The URL of the new scenario.
              schema: { type: string, format: uri }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Scenario' }
              examples:
                default:
                  value:
                    id: scn_5e8c1b72d9
                    object: scenario
                    airport: VTBS
                    name: 02R-20L closed 10:00-10:30
                    day: '2026-11-23'
                    window: { from: '2026-11-22T17:00:00Z', to: '2026-11-23T17:00:00Z' }
                    changes:
                      - type: runway_closure
                        runway: runway:02R-20L
                        from: '2026-11-23T03:00:00Z'
                        until: '2026-11-23T03:30:00Z'
                    status: queued
                    created_at: '2026-11-23T02:59:02Z'
                    completed_at: null
                    result: null
        default: { $ref: '#/components/responses/Error' }

  /scenarios/{scenario}:
    get:
      operationId: getScenario
      tags: [Scenarios]
      summary: Retrieve a scenario
      description: Returns the scenario. Once `status` is `succeeded`, `result` holds the baseline, the scenario and the difference between them.
      x-release: preview-2
      x-scopes: [scenarios:read]
      x-sample: { path: /scenarios/scn_5e8c1b72d9 }
      parameters:
        - $ref: '#/components/parameters/Scenario'
      responses:
        '200':
          description: The scenario.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Scenario' }
              examples:
                default:
                  value:
                    id: scn_5e8c1b72d9
                    object: scenario
                    airport: VTBS
                    name: 02R-20L closed 10:00-10:30
                    day: '2026-11-23'
                    window: { from: '2026-11-22T17:00:00Z', to: '2026-11-23T17:00:00Z' }
                    changes:
                      - type: runway_closure
                        runway: runway:02R-20L
                        from: '2026-11-23T03:00:00Z'
                        until: '2026-11-23T03:30:00Z'
                    status: succeeded
                    created_at: '2026-11-23T02:59:02Z'
                    completed_at: '2026-11-23T02:59:06.214Z'
                    result:
                      movements: 1046
                      duration_ms: 3870
                      baseline:
                        departure_delay_min: 2184
                        arrival_delay_min: 1312
                        mean_taxi_out_min: 16.8
                        max_departure_queue: 9
                        on_time_departure_ratio: 0.812
                      scenario:
                        departure_delay_min: 3047
                        arrival_delay_min: 1690
                        mean_taxi_out_min: 18.1
                        max_departure_queue: 17
                        on_time_departure_ratio: 0.774
                      difference:
                        departure_delay_min: 863
                        arrival_delay_min: 378
                        mean_taxi_out_min: 1.3
                        max_departure_queue: 8
                        on_time_departure_ratio: -0.038
                      affected_flights: 71
        default: { $ref: '#/components/responses/Error' }

  /scenarios/{scenario}/flights:
    get:
      operationId: listScenarioFlights
      tags: [Scenarios]
      summary: List affected flights
      description: Returns flights whose times differ between baseline and scenario, largest delay first.
      x-release: preview-2
      x-scopes: [scenarios:read]
      x-sample: { path: '/scenarios/scn_5e8c1b72d9/flights?limit=2' }
      parameters:
        - $ref: '#/components/parameters/Scenario'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
      responses:
        '200':
          description: A page of affected flights.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema:
                type: object
                required: [object, data, next_cursor]
                properties:
                  object: { const: list }
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/ScenarioFlight' }
                  next_cursor: { $ref: '#/components/schemas/NextCursor' }
              examples:
                default:
                  value:
                    object: list
                    data:
                      - flight: flight:TG403-20261123
                        direction: departure
                        baseline: { off_block_at: '2026-11-23T03:31:00Z', runway: runway:02R-20L, runway_at: '2026-11-23T03:47:00Z' }
                        scenario: { off_block_at: '2026-11-23T03:31:00Z', runway: runway:02R-20L, runway_at: '2026-11-23T04:16:00Z' }
                        delay_min: 29
                        reason: knock_on
                      - flight: flight:TG102-20261123
                        direction: departure
                        baseline: { off_block_at: '2026-11-23T03:05:00Z', runway: runway:02R-20L, runway_at: '2026-11-23T03:19:00Z' }
                        scenario: { off_block_at: '2026-11-23T03:05:00Z', runway: runway:02L-20R, runway_at: '2026-11-23T03:44:00Z' }
                        delay_min: 25
                        reason: runway_closure
                    next_cursor: c_7a20e4f1b95d3c68
        default: { $ref: '#/components/responses/Error' }

  /scenarios/{scenario}/events:
    get:
      operationId: streamScenario
      tags: [Scenarios]
      summary: Stream scenario progress
      description: Opens a server-sent events stream of `scenario.progress` events, then one `scenario.succeeded` or `scenario.failed` event, then closes.
      x-release: preview-2
      x-scopes: [scenarios:read]
      x-sample: { path: /scenarios/scn_5e8c1b72d9/events }
      parameters:
        - $ref: '#/components/parameters/Scenario'
      responses:
        '200':
          description: An event stream that closes when the scenario finishes.
          content:
            text/event-stream:
              schema: { type: string }
              examples:
                default:
                  value: |
                    event: scenario.progress
                    data: {"scenario":"scn_5e8c1b72d9","run":"baseline","simulated_until":"2026-11-23T05:00:00Z","ratio":0.25}

                    event: scenario.progress
                    data: {"scenario":"scn_5e8c1b72d9","run":"scenario","simulated_until":"2026-11-23T17:00:00Z","ratio":1}

                    event: scenario.succeeded
                    data: {"scenario":"scn_5e8c1b72d9","duration_ms":3870,"affected_flights":71}
        default: { $ref: '#/components/responses/Error' }
      x-codeSamples:
        - lang: curl
          source: |
            curl -N https://api.surfacelens.app/v1/scenarios/scn_5e8c1b72d9/events \
              -H "Authorization: Bearer $SURFACELENS_KEY"
        - lang: TypeScript
          source: |
            const res = await fetch(
              "https://api.surfacelens.app/v1/scenarios/scn_5e8c1b72d9/events",
              { headers: { Authorization: `Bearer ${process.env.SURFACELENS_KEY}` } },
            );
            for await (const chunk of res.body!.pipeThrough(new TextDecoderStream())) {
              process.stdout.write(chunk);
            }
        - lang: Python
          source: |
            import os, httpx

            url = "https://api.surfacelens.app/v1/scenarios/scn_5e8c1b72d9/events"
            headers = {"Authorization": f"Bearer {os.environ['SURFACELENS_KEY']}"}

            with httpx.stream("GET", url, headers=headers, timeout=None) as res:
                for line in res.iter_lines():
                    if line:
                        print(line)

  /webhooks:
    post:
      operationId: createWebhook
      tags: [Webhooks]
      summary: Create a webhook
      description: Registers an HTTPS endpoint to receive the listed event types. The response includes the signing secret, which is shown only once.
      x-release: preview-2
      x-scopes: [webhooks:write]
      x-sample: { path: /webhooks }
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url, events]
              properties:
                url: { type: string, format: uri, description: 'An HTTPS URL. Must answer within 10 seconds.' }
                events:
                  type: array
                  minItems: 1
                  items: { $ref: '#/components/schemas/WebhookEventType' }
                airports:
                  type: array
                  description: Only events for these airports. Omit for every airport the application can read.
                  items: { $ref: '#/components/schemas/AirportId' }
            examples:
              default:
                value:
                  url: https://ops-board.example.net/hooks/surfacelens
                  events: [airfield.status_changed, scenario.completed]
                  airports: [VTBS]
      responses:
        '201':
          description: The webhook was created.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Webhook' }
              examples:
                default:
                  value:
                    id: wh_0a7d3e91c4
                    object: webhook
                    url: https://ops-board.example.net/hooks/surfacelens
                    events: [airfield.status_changed, scenario.completed]
                    airports: [VTBS]
                    status: enabled
                    secret: whsec_Q3r8Zk1vN6pT2mYb5wLc9xHd
                    created_at: '2026-11-23T03:02:17Z'
        default: { $ref: '#/components/responses/Error' }
    get:
      operationId: listWebhooks
      tags: [Webhooks]
      summary: List webhooks
      description: Returns the application's webhooks. Secrets are not included.
      x-release: preview-2
      x-scopes: [webhooks:write]
      x-sample: { path: /webhooks }
      parameters:
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
      responses:
        '200':
          description: A page of webhooks.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema:
                type: object
                required: [object, data, next_cursor]
                properties:
                  object: { const: list }
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Webhook' }
                  next_cursor: { $ref: '#/components/schemas/NextCursor' }
              examples:
                default:
                  value:
                    object: list
                    data:
                      - id: wh_0a7d3e91c4
                        object: webhook
                        url: https://ops-board.example.net/hooks/surfacelens
                        events: [airfield.status_changed, scenario.completed]
                        airports: [VTBS]
                        status: enabled
                        created_at: '2026-11-23T03:02:17Z'
                    next_cursor: null
        default: { $ref: '#/components/responses/Error' }

  /webhooks/{webhook}:
    delete:
      operationId: deleteWebhook
      tags: [Webhooks]
      summary: Delete a webhook
      description: Stops deliveries immediately. Deliveries already in flight may still arrive.
      x-release: preview-2
      x-scopes: [webhooks:write]
      x-sample: { path: /webhooks/wh_0a7d3e91c4 }
      parameters:
        - name: webhook
          in: path
          required: true
          description: The webhook ID.
          schema: { type: string, pattern: '^wh_[0-9a-z]{10}$' }
      responses:
        '204':
          description: The webhook was deleted.
        default: { $ref: '#/components/responses/Error' }

  /applications:
    post:
      operationId: createApplication
      tags: [Applications]
      summary: Create an application
      description: |
        Creates an application: one consumer of the shared model with one set of
        permissions. Every key you issue for it carries exactly these permissions.
      x-release: preview-1
      x-scopes: [applications:write]
      x-sample: { path: /applications }
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ApplicationCreate' }
            examples:
              default:
                value:
                  name: Turnaround board
                  airports: [VTBS]
                  scopes: [airports:read, entities:read, events:read]
                  entity_types: [aircraft, flight, stand, vehicle]
      responses:
        '201':
          description: The application was created.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Application' }
              examples:
                default:
                  value:
                    id: app_4f1e9a7c20
                    object: application
                    name: Turnaround board
                    airports: [VTBS]
                    scopes: [airports:read, entities:read, events:read]
                    entity_types: [aircraft, flight, stand, vehicle]
                    feeds: []
                    created_at: '2026-11-23T01:12:45Z'
        default: { $ref: '#/components/responses/Error' }

  /applications/{application}:
    get:
      operationId: getApplication
      tags: [Applications]
      summary: Retrieve an application
      description: Returns one application. Pass `me` to read the application that owns the calling key.
      x-release: preview-1
      x-scopes: []
      x-sample: { path: /applications/me }
      parameters:
        - name: application
          in: path
          required: true
          description: The application ID, or `me`.
          schema: { type: string, pattern: '^(app_[0-9a-z]{10}|me)$' }
      responses:
        '200':
          description: The application.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Application' }
              examples:
                default:
                  value:
                    id: app_4f1e9a7c20
                    object: application
                    name: Turnaround board
                    airports: [VTBS]
                    scopes: [airports:read, entities:read, events:read]
                    entity_types: [aircraft, flight, stand, vehicle]
                    feeds: []
                    created_at: '2026-11-23T01:12:45Z'
        default: { $ref: '#/components/responses/Error' }

  /applications/{application}/keys:
    post:
      operationId: createKey
      tags: [Applications]
      summary: Create a key
      description: |
        Issues an API key for the application. The `secret` is returned once and cannot
        be retrieved again. Keys for the `test` environment read the sandbox; keys for
        `live` read production data.
      x-release: preview-1
      x-scopes: [applications:write]
      x-sample: { path: /applications/app_4f1e9a7c20/keys }
      parameters:
        - $ref: '#/components/parameters/Application'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [environment]
              properties:
                environment: { $ref: '#/components/schemas/Environment' }
                label: { type: string, maxLength: 80, description: A note to help you identify the key later. }
                expires_at:
                  $ref: '#/components/schemas/Timestamp'
                  description: When the key stops working. Omit for a key that does not expire.
            examples:
              default:
                value:
                  environment: test
                  label: Local development
                  expires_at: '2027-02-23T00:00:00Z'
      responses:
        '201':
          description: The key, including its secret.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ApiKey' }
              examples:
                default:
                  value:
                    id: key_6d2a91f0b3
                    object: api_key
                    application: app_4f1e9a7c20
                    environment: test
                    label: Local development
                    prefix: sl_test_9xKq
                    secret: sl_test_9xKq2VwM7pLr4TnB8cYz3HdF
                    created_at: '2026-11-23T01:13:02Z'
                    expires_at: '2027-02-23T00:00:00Z'
                    last_used_at: null
        default: { $ref: '#/components/responses/Error' }

  /applications/{application}/keys/{key}:
    delete:
      operationId: revokeKey
      tags: [Applications]
      summary: Revoke a key
      description: Revokes the key on the edge immediately and on on-premise nodes within 60 seconds. Open streams using the key are closed.
      x-release: preview-1
      x-scopes: [applications:write]
      x-sample: { path: /applications/app_4f1e9a7c20/keys/key_6d2a91f0b3 }
      parameters:
        - $ref: '#/components/parameters/Application'
        - name: key
          in: path
          required: true
          description: The key ID. This is not the secret.
          schema: { type: string, pattern: '^key_[0-9a-z]{10}$' }
      responses:
        '204':
          description: The key was revoked.
        default: { $ref: '#/components/responses/Error' }

  /status:
    get:
      operationId: getStatus
      tags: [Gateway]
      summary: Retrieve node status
      description: |
        Describes the node that answered: edge or on-premise, which airports it is
        primary for, and how far behind it is. Clients use it to decide where to send
        requests. See [Fail over to on-premise](../guides/failover.md).
      x-release: preview-1
      x-scopes: []
      x-sample: { path: /status }
      responses:
        '200':
          description: The node's status.
          headers:
            SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
            SurfaceLens-Node: { $ref: '#/components/headers/Node' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/NodeStatus' }
              examples:
                default:
                  value:
                    object: node_status
                    node: { id: edge, kind: edge, region: apac, colo: BKK }
                    checked_at: '2026-11-23T02:58:41Z'
                    airports:
                      - airport: VTBS
                        role: primary
                        epoch: 7
                        revision: 48213377
                        peer: { kind: onprem, reachable: true, lag_ms: 420 }
        default: { $ref: '#/components/responses/Error' }

  # The three partner observation operations follow the draft observation gateway
  # contract in contracts/gateway (TypeSpec). Their examples are validated against
  # that contract by contracts/gateway/contract.test.ts. Change the docs to match
  # the contract, never the reverse.
  /observations:
    post:
      operationId: ingestObservations
      tags: [Partner observations]
      summary: Ingest observations
      description: |
        Submits 1 to 100 observations from one airport in at most 256 KiB of JSON. The
        key's authenticated context supplies the producer and the airports it may write
        to; neither goes in the body.

        The batch is admitted atomically. `results` follows the request order: `stored`
        is a newly admitted report and `existing` an identical resubmission, and both
        carry the gateway's `recordId` for that report. The key of a report is its
        producer, airport and `sourceObservationId`. Different content under the same key
        returns `409` with the code `observation_conflict`, and a conflicting or invalid
        batch admits nothing, so keep both the key and the content when you retry.

        The partner observation operations follow the draft observation gateway
        contract: field names are camelCase, and an error is a JSON object whose `error`
        member holds a `code` and a `message`.
      x-release: preview-1
      x-scopes: []
      x-sample: { path: /observations }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/PartnerIngestRequest' }
            examples:
              default:
                value:
                  observations:
                    - sourceObservationId: vtbs-insp-20261123-0412
                      airportIcao: VTBS
                      observedAt: '2026-11-23T02:51:00Z'
                      kind: suspected_fod
                      areaRef: apron-c-stand-c2
                      evidenceOrigin: Synthetic
                    - sourceObservationId: vtbs-insp-20261123-0413
                      airportIcao: VTBS
                      observedAt: '2026-11-23T02:55:00Z'
                      kind: inspection_clear
                      areaRef: apron-c-stand-c2
                      evidenceOrigin: Synthetic
                    - sourceObservationId: vtbs-adsb-8851a4-0258
                      airportIcao: VTBS
                      observedAt: '2026-11-23T02:58:00.400Z'
                      kind: aircraft_position
                      aircraftRef: '8851a4'
                      position: { longitude: 100.75391, latitude: 13.69212 }
                      evidenceOrigin: Synthetic
      responses:
        '200':
          description: The whole batch was admitted. One result per observation, in request order.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PartnerIngestReceipt' }
              examples:
                default:
                  value:
                    results:
                      - sourceObservationId: vtbs-insp-20261123-0412
                        recordId: rec_4Kp7Tz2wN9qd
                        disposition: stored
                      - sourceObservationId: vtbs-insp-20261123-0413
                        recordId: rec_7Hd2Lx5vB8mf
                        disposition: stored
                      - sourceObservationId: vtbs-adsb-8851a4-0258
                        recordId: rec_9Wc3Qn6yF1ta
                        disposition: existing
        default: { $ref: '#/components/responses/PartnerError' }
    get:
      operationId: queryObservations
      tags: [Partner observations]
      summary: Query observations
      description: |
        Returns the observations admitted for one airport whose reported `observedAt`
        falls in `[from, to)`. The window may span at most 24 hours. Rows are ordered by
        `observedAt`, then `recordId`. Each row pairs the submitted report, with its time
        normalized to milliseconds, with the `recordId` and `admittedAt` that the gateway
        assigned when it first stored it. A window with no matches returns an empty
        `observations` array.

        Every page of one read uses the admission cutoff named by `snapshotRef`, so
        reports admitted after it appear only in a new read. Pass `nextCursor` back as
        `cursor` with the other parameters unchanged; it is `null` on the last page. The
        gateway checks the key's authorization again on every page.
      x-release: preview-1
      x-scopes: []
      x-sample: { path: '/observations?airportIcao=VTBS&from=2026-11-23T02:50:00Z&to=2026-11-23T03:00:00Z&limit=2' }
      parameters:
        - name: airportIcao
          in: query
          required: true
          description: The airport to read, within the key's authorized airports.
          schema: { $ref: '#/components/schemas/AirportId' }
        - name: from
          in: query
          required: true
          description: Inclusive lower bound on `observedAt`.
          schema: { $ref: '#/components/schemas/PartnerTimestamp' }
        - name: to
          in: query
          required: true
          description: Exclusive upper bound on `observedAt`, later than `from` and at most 24 hours after it.
          schema: { $ref: '#/components/schemas/PartnerTimestamp' }
        - $ref: '#/components/parameters/Limit'
        - name: cursor
          in: query
          description: The `nextCursor` from the previous page. It is bound to the same query, key and admission cutoff.
          schema: { $ref: '#/components/schemas/PartnerRef' }
      responses:
        '200':
          description: A page of admitted observations.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PartnerObservationPage' }
              examples:
                default:
                  value:
                    worldClass: simulation
                    snapshotRef: snap_2Fh9Vc6pL3wa
                    observations:
                      - recordId: rec_4Kp7Tz2wN9qd
                        admittedAt: '2026-11-23T02:58:40.218Z'
                        observation:
                          sourceObservationId: vtbs-insp-20261123-0412
                          airportIcao: VTBS
                          observedAt: '2026-11-23T02:51:00.000Z'
                          kind: suspected_fod
                          areaRef: apron-c-stand-c2
                          evidenceOrigin: Synthetic
                      - recordId: rec_7Hd2Lx5vB8mf
                        admittedAt: '2026-11-23T02:58:40.218Z'
                        observation:
                          sourceObservationId: vtbs-insp-20261123-0413
                          airportIcao: VTBS
                          observedAt: '2026-11-23T02:55:00.000Z'
                          kind: inspection_clear
                          areaRef: apron-c-stand-c2
                          evidenceOrigin: Synthetic
                    nextCursor: gwc_5Tq8Rm1zK4ne
        default: { $ref: '#/components/responses/PartnerError' }

  /queries/aircraft-within:
    post:
      operationId: aircraftWithin
      tags: [Partner observations]
      summary: Find aircraft within a radius
      description: |
        Returns the aircraft tracks whose latest position at `asOf` lies within `radiusM`
        of `centre`. For each permitted source track, the gateway first takes the latest
        position observed at or before `asOf` and no more than `maxAgeMs` earlier, then
        applies the inclusive great-circle radius. A track that has since moved outside
        the radius no longer counts. Separate sources can report the same aircraft as
        separate tracks.

        Pass the `snapshotRef` of an earlier read at the same airport to answer from the
        same admitted data, or omit it to use the current cutoff. `tracks` is ordered by
        distance. Use each `recordId` to match a track to an admitted observation. The
        body may be at most 256 KiB.
      x-release: preview-1
      x-scopes: []
      x-sample: { path: /queries/aircraft-within }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/PartnerAircraftQuery' }
            examples:
              default:
                value:
                  airportIcao: VTBS
                  asOf: '2026-11-23T02:58:41Z'
                  maxAgeMs: 120000
                  centre: { longitude: 100.7539, latitude: 13.6921 }
                  radiusM: 100
                  snapshotRef: snap_2Fh9Vc6pL3wa
      responses:
        '200':
          description: The tracks within the radius.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PartnerAircraftResult' }
              examples:
                default:
                  value:
                    worldClass: simulation
                    snapshotRef: snap_2Fh9Vc6pL3wa
                    asOf: '2026-11-23T02:58:41.000Z'
                    count: 1
                    tracks:
                      - recordId: rec_9Wc3Qn6yF1ta
                        aircraftRef: '8851a4'
                        observedAt: '2026-11-23T02:58:00.400Z'
                        position: { longitude: 100.75391, latitude: 13.69212 }
                        distanceM: 2.47
        default: { $ref: '#/components/responses/PartnerError' }

webhooks:
  airfield.status_changed:
    post:
      operationId: onAirfieldStatusChanged
      summary: Airfield status changed
      description: A runway, taxiway or stand opened, closed or changed restriction.
      parameters:
        - $ref: '#/components/parameters/Signature'
      requestBody:
        content:
          application/json:
            schema: { $ref: '#/components/schemas/WebhookDelivery' }
            examples:
              default:
                value:
                  id: evt_3c81f0a9d2
                  type: airfield.status_changed
                  airport: VTBS
                  created_at: '2026-11-23T03:00:02Z'
                  data:
                    entity: runway:02R-20L
                    previous: { status: open }
                    current: { status: closed, reason: inspection, until: '2026-11-23T03:30:00Z' }
                    observation: obs_9Ar2Te6mH0kc
      responses:
        '200': { description: Return any 2xx status within 10 seconds to acknowledge. }
  feed.health_changed:
    post:
      operationId: onFeedHealthChanged
      summary: Feed health changed
      description: A feed moved between `healthy`, `degraded` and `silent`.
      parameters:
        - $ref: '#/components/parameters/Signature'
      requestBody:
        content:
          application/json:
            schema: { $ref: '#/components/schemas/WebhookDelivery' }
            examples:
              default:
                value:
                  id: evt_7b20d4e6f1
                  type: feed.health_changed
                  airport: VTBS
                  created_at: '2026-11-23T02:47:30Z'
                  data:
                    feed: feed_e07a3c58b9
                    previous: healthy
                    current: silent
                    last_record_at: '2026-11-23T02:45:30Z'
      responses:
        '200': { description: Return any 2xx status within 10 seconds to acknowledge. }
  scenario.completed:
    post:
      operationId: onScenarioCompleted
      summary: Scenario completed
      description: A scenario reached `succeeded` or `failed`.
      parameters:
        - $ref: '#/components/parameters/Signature'
      requestBody:
        content:
          application/json:
            schema: { $ref: '#/components/schemas/WebhookDelivery' }
            examples:
              default:
                value:
                  id: evt_1f5e9c3a07
                  type: scenario.completed
                  airport: VTBS
                  created_at: '2026-11-23T02:59:06Z'
                  data: { scenario: scn_5e8c1b72d9, status: succeeded, affected_flights: 71 }
      responses:
        '200': { description: Return any 2xx status within 10 seconds to acknowledge. }

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: An API key sent as a bearer token. Keys start with `sl_test_` or `sl_live_`.

  parameters:
    Airport:
      name: airport
      in: path
      required: true
      description: The airport's ICAO code.
      schema: { $ref: '#/components/schemas/AirportId' }
      example: VTBS
    Entity:
      name: entity
      in: path
      required: true
      description: The entity ID, such as `aircraft:8851a4` or `stand:C2`.
      schema: { $ref: '#/components/schemas/EntityId' }
    Feed:
      name: feed
      in: path
      required: true
      description: The feed ID.
      schema: { $ref: '#/components/schemas/FeedId' }
    Scenario:
      name: scenario
      in: path
      required: true
      description: The scenario ID.
      schema: { type: string, pattern: '^scn_[0-9a-z]{10}$' }
    Application:
      name: application
      in: path
      required: true
      description: The application ID.
      schema: { type: string, pattern: '^app_[0-9a-z]{10}$' }
    At:
      name: at
      in: query
      description: The instant to read, RFC 3339 in UTC. Omit for now.
      schema: { $ref: '#/components/schemas/Timestamp' }
      example: '2026-11-23T02:30:00Z'
    KnownAt:
      name: known_at
      in: query
      description: Read only what had been received by this instant. Omit to use everything received so far, including late and corrected observations.
      schema: { $ref: '#/components/schemas/Timestamp' }
    Limit:
      name: limit
      in: query
      description: Page size, from 1 to 500.
      schema: { type: integer, minimum: 1, maximum: 500, default: 100 }
    Cursor:
      name: cursor
      in: query
      description: The `next_cursor` from the previous page. Other parameters must not change between pages. Cursors expire after one hour.
      schema: { type: string }
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      description: A unique value, such as a UUID, that makes the request safe to retry for 24 hours.
      schema: { type: string, maxLength: 255 }
    Signature:
      name: SurfaceLens-Signature
      in: header
      required: true
      description: '`t=<unix seconds>,v1=<hex>`, where `v1` is the HMAC-SHA256 of `t`, a full stop and the raw body, keyed with the webhook secret. Reject deliveries whose `t` is more than 300 seconds old.'
      schema: { type: string, example: 't=1763866802,v1=6f1c0e2a8b3d9f47a1c25e08b6d3f9a2c47e1b05d8f63a92e4c71b0d5a8f3e26' }
    Simulate:
      name: SurfaceLens-Simulate
      in: header
      description: 'Test keys only, accepted by every operation. `edge_unavailable` makes the edge answer `503 unavailable` without `Retry-After`, as it would in an outage.'
      schema: { type: string, enum: [edge_unavailable] }

  headers:
    RequestId:
      description: Identifies this request. Include it when you contact support.
      schema: { type: string, example: req_8Jw3Nd5kQ1ra }
    RetryAfter:
      description: Seconds to wait before retrying. Sent with `429` and with planned `503` responses.
      schema: { type: integer, example: 2 }
    RateLimit:
      description: 'Requests remaining in the current window and seconds until it resets, as `limit=100, remaining=37, reset=1`.'
      schema: { type: string }
    RateLimitPolicy:
      description: 'The policy that applies to this key, as `100;w=1;burst=200`.'
      schema: { type: string }
    Node:
      description: The node that answered, on every response. `edge; colo=<IATA>` or `onprem; id=<node>`.
      schema: { type: string, example: 'edge; colo=BKK' }

  responses:
    Error:
      description: An error, as an RFC 9457 problem document.
      headers:
        SurfaceLens-Request-Id: { $ref: '#/components/headers/RequestId' }
        Retry-After: { $ref: '#/components/headers/RetryAfter' }
        RateLimit: { $ref: '#/components/headers/RateLimit' }
        RateLimit-Policy: { $ref: '#/components/headers/RateLimitPolicy' }
      content:
        application/problem+json:
          schema: { $ref: '#/components/schemas/Problem' }
          examples:
            default:
              value:
                type: https://docs.surfacelens.app/reference/errors/#invalid_parameter
                title: Invalid parameter
                status: 400
                code: invalid_parameter
                detail: radius must be between 1 and 20000 metres.
                request_id: req_8Jw3Nd5kQ1ra
                errors:
                  - parameter: radius
                    message: Must be between 1 and 20000.
    PartnerError:
      description: An error from a partner observation operation, in the observation gateway's envelope rather than a problem document.
      headers:
        Retry-After:
          description: Sent with `429` and `rate_limited`.
          schema: { type: string, example: '5' }
      content:
        application/json:
          schema: { $ref: '#/components/schemas/PartnerError' }
          examples:
            default:
              value:
                error:
                  code: airport_access_denied
                  message: The request is outside the authorized data scope.

  schemas:
    Timestamp:
      type: string
      format: date-time
      description: RFC 3339 in UTC, with up to millisecond precision.
      pattern: '^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$'
    AirportId:
      type: string
      pattern: '^[A-Z]{4}$'
      description: An ICAO airport code.
    EntityId:
      type: string
      pattern: '^(aircraft|flight|vehicle|person|stand|runway|taxiway|area|airport):[A-Za-z0-9._-]+$'
      description: '`type:key`. The key is stable for the life of the entity.'
    FeedId:
      type: string
      pattern: '^feed_[0-9a-z]{10}$'
    ObservationId:
      type: string
      pattern: '^obs_[0-9A-Za-z]{12}$'
    NextCursor:
      type: [string, 'null']
      description: Pass as `cursor` to fetch the next page. Null on the last page.
    Environment:
      type: string
      enum: [test, live]
      description: '`test` reads the sandbox, a simulated VTBS day. `live` reads production data.'
    Position:
      type: object
      required: [lat, lon]
      description: WGS 84 decimal degrees.
      properties:
        lat: { type: number, minimum: -90, maximum: 90 }
        lon: { type: number, minimum: -180, maximum: 180 }

    Airport:
      type: object
      required: [id, object, iata, name, timezone, reference_point, home_region, airfield_version, onprem_node, environment]
      properties:
        id: { $ref: '#/components/schemas/AirportId' }
        object: { const: airport }
        iata: { type: string, pattern: '^[A-Z]{3}$', description: The IATA code. }
        name: { type: string }
        timezone: { type: string, description: IANA time zone. API times are always UTC; use this to display local time. }
        reference_point: { $ref: '#/components/schemas/Position' }
        elevation_ft: { type: number }
        home_region:
          type: string
          enum: [apac, eu, me, na]
          description: Where the airport's data is stored and its write path runs.
        airfield_version: { type: string, description: The version of the airfield model in force now. }
        onprem_node:
          type: [string, 'null']
          format: uri
          description: Base URL of the airport's on-premise node, or null if it has none.
        environment: { $ref: '#/components/schemas/Environment' }

    AirfieldFeatureType:
      type: string
      enum: [runway, taxiway, apron, stand, area]
    Airfield:
      type: object
      required: [type, airport, version, at, features]
      properties:
        type: { const: FeatureCollection }
        airport: { $ref: '#/components/schemas/AirportId' }
        version: { type: string }
        at: { $ref: '#/components/schemas/Timestamp' }
        features:
          type: array
          items:
            type: object
            required: [type, id, geometry, properties]
            properties:
              type: { const: Feature }
              id: { $ref: '#/components/schemas/EntityId' }
              geometry: { type: object, description: A GeoJSON geometry. }
              properties:
                type: object
                description: Type-specific properties such as `designators` and `length_m` for runways.
                additionalProperties: true
                required: [feature_type, status]
                properties:
                  feature_type: { $ref: '#/components/schemas/AirfieldFeatureType' }
                  status: { type: string, enum: [open, closed, restricted] }

    EntityType:
      type: string
      enum: [aircraft, flight, vehicle, person, stand, runway, taxiway, area, airport]
    Entity:
      type: object
      required: [id, object, type, label, position, attributes, observed_at, provenance]
      properties:
        id: { $ref: '#/components/schemas/EntityId' }
        object: { const: entity }
        type: { $ref: '#/components/schemas/EntityType' }
        label: { type: string, description: 'A display name: registration, flight number, stand name.' }
        position:
          oneOf:
            - $ref: '#/components/schemas/Position'
            - type: 'null'
          description: Last known position at `at`. Null for entities without one, such as flights.
        distance_m:
          type: number
          description: Distance from `near`, in metres. Present only on spatial queries with a point.
        attributes:
          type: object
          description: Type-specific state. See [the shared model](../concepts/shared-model.md#entity-types) for the attributes of each type.
        observed_at:
          $ref: '#/components/schemas/Timestamp'
          description: Time of the latest observation that contributed to this state.
        provenance:
          type: object
          description: For each attribute, the ID of the observation it came from.
          additionalProperties: { $ref: '#/components/schemas/ObservationId' }
    EntityPage:
      type: object
      required: [object, airport, at, revision, data, next_cursor]
      properties:
        object: { const: list }
        airport: { $ref: '#/components/schemas/AirportId' }
        at:
          $ref: '#/components/schemas/Timestamp'
          description: The instant the page describes. Every page of one query uses the same instant.
        revision:
          type: integer
          description: The airport revision the page was read at.
        data:
          type: array
          items: { $ref: '#/components/schemas/Entity' }
        next_cursor: { $ref: '#/components/schemas/NextCursor' }
    EntitySearch:
      type: object
      required: [within]
      properties:
        within:
          description: The area. Exactly one of the three shapes.
          oneOf:
            - type: object
              title: Circle
              required: [point, radius_m]
              properties:
                point: { $ref: '#/components/schemas/Position' }
                radius_m: { type: number, minimum: 1, maximum: 20000 }
            - type: object
              title: Polygon
              required: [polygon]
              properties:
                polygon: { type: object, description: 'A GeoJSON Polygon, longitude first.' }
            - type: object
              title: Airfield feature
              required: [feature]
              properties:
                feature: { $ref: '#/components/schemas/EntityId' }
                buffer_m: { type: number, minimum: 0, maximum: 500, default: 0, description: Grow the feature's outline by this many metres. }
        types:
          type: array
          items: { $ref: '#/components/schemas/EntityType' }
        at: { $ref: '#/components/schemas/Timestamp' }
        known_at: { $ref: '#/components/schemas/Timestamp' }
        limit: { type: integer, minimum: 1, maximum: 500, default: 100 }
        cursor: { type: string }

    ObservationKind:
      type: string
      enum: [position, status, schedule, allocation, weather, detection]
    Observation:
      type: object
      required: [id, object, entity, feed, kind, observed_at, received_at, revision, source_id, data]
      properties:
        id: { $ref: '#/components/schemas/ObservationId' }
        object: { const: observation }
        entity: { $ref: '#/components/schemas/EntityId' }
        feed: { $ref: '#/components/schemas/FeedId' }
        kind: { $ref: '#/components/schemas/ObservationKind' }
        observed_at:
          $ref: '#/components/schemas/Timestamp'
          description: When the source says the fact was true.
        received_at:
          $ref: '#/components/schemas/Timestamp'
          description: When SurfaceLens admitted it.
        revision: { type: integer, description: The airport revision that admitted it. }
        source_id: { type: string, description: The record ID assigned by the source. }
        data: { type: object, description: The mapped facts, in shared-schema attribute names. }
        record:
          type: object
          description: The raw record and mapping version. Returned only when retrieving a single observation.
          properties:
            mapping_version: { type: integer }
            body: { type: object }

    ChangeEvent:
      type: object
      description: The `data` of an event. Event names are `entity.snapshot`, `snapshot.complete`, `entity.created`, `entity.updated`, `entity.removed`, and `stream.overflow`, sent before the server closes a stream that has fallen more than 10,000 events behind.
      required: [revision]
      properties:
        revision: { type: integer }
        entity:
          description: The full entity on `entity.snapshot` and `entity.created`; its ID otherwise.
          oneOf:
            - type: object
            - $ref: '#/components/schemas/EntityId'
        changed: { type: object, description: On `entity.updated`, the attributes that changed and their new values. }
        observation: { $ref: '#/components/schemas/ObservationId' }
        observed_at: { $ref: '#/components/schemas/Timestamp' }
        count: { type: integer, description: On `snapshot.complete`, the number of entities sent. }
        detail: { type: string, description: On `stream.overflow`, why the stream is closing. }

    FeedKind:
      type: string
      enum: [flight_schedule, stand_allocation, surface_track, vehicle_position, workforce_position, weather, sensor, airfield_map]
    FeedStatus:
      type: string
      enum: [draft, active, paused]
    FeedCreate:
      type: object
      required: [airport, name, kind, transport]
      properties:
        airport: { $ref: '#/components/schemas/AirportId' }
        name: { type: string, maxLength: 80 }
        kind: { $ref: '#/components/schemas/FeedKind' }
        transport:
          type: string
          enum: [push]
          description: '`push`: the source sends records to `ingest_url`. Pull transports are planned.'
        priority:
          type: integer
          minimum: 0
          maximum: 100
          default: 50
          description: When two feeds report the same attribute for the same instant, the higher priority wins.
    FeedUpdate:
      type: object
      properties:
        name: { type: string, maxLength: 80 }
        priority: { type: integer, minimum: 0, maximum: 100 }
        status: { $ref: '#/components/schemas/FeedStatus' }
    Feed:
      type: object
      required: [id, object, airport, name, kind, transport, priority, status, mapping_version, created_at, ingest_url]
      properties:
        id: { $ref: '#/components/schemas/FeedId' }
        object: { const: feed }
        airport: { $ref: '#/components/schemas/AirportId' }
        name: { type: string }
        kind: { $ref: '#/components/schemas/FeedKind' }
        transport: { type: string, enum: [push] }
        priority: { type: integer }
        status: { $ref: '#/components/schemas/FeedStatus' }
        mapping_version: { type: [integer, 'null'], description: The current mapping version, or null before the first mapping. }
        created_at: { $ref: '#/components/schemas/Timestamp' }
        ingest_url: { type: string, format: uri, description: Where the source pushes records. }

    MappingValue:
      description: |
        A JSONPath into the record (`$.Stand`), a literal (`{ "const": "TG" }`), a conversion
        (`{ "from": "$.STD", "as": "timestamp" }`), or an entity reference
        (`{ "ref": "aircraft", "by": "registration", "from": "$.Reg" }`).
    MappingInput:
      type: object
      required: [record_id, observed_at, entity, emit]
      properties:
        record_id: { $ref: '#/components/schemas/MappingValue' }
        observed_at: { $ref: '#/components/schemas/MappingValue' }
        entity:
          type: object
          required: [type, key]
          properties:
            type: { $ref: '#/components/schemas/EntityType' }
            key: { $ref: '#/components/schemas/MappingValue' }
        emit:
          type: array
          minItems: 1
          items:
            type: object
            required: [kind, data]
            properties:
              kind: { $ref: '#/components/schemas/ObservationKind' }
              data:
                type: object
                description: Shared-schema attribute names mapped to values.
                additionalProperties: { $ref: '#/components/schemas/MappingValue' }
    Mapping:
      allOf:
        - $ref: '#/components/schemas/MappingInput'
        - type: object
          required: [object, feed, version, created_at]
          properties:
            object: { const: mapping }
            feed: { $ref: '#/components/schemas/FeedId' }
            version: { type: integer }
            created_at: { $ref: '#/components/schemas/Timestamp' }
    MappingTestResult:
      type: object
      required: [index, ok, observations, errors]
      properties:
        index: { type: integer }
        ok: { type: boolean }
        entity: { $ref: '#/components/schemas/EntityId' }
        observations:
          type: array
          items:
            type: object
            required: [kind, observed_at, data]
            properties:
              kind: { $ref: '#/components/schemas/ObservationKind' }
              observed_at: { $ref: '#/components/schemas/Timestamp' }
              data: { type: object }
        errors:
          type: array
          items: { $ref: '#/components/schemas/RecordError' }
    RecordError:
      type: object
      required: [code, path, message]
      properties:
        code: { type: string, enum: [missing_field, invalid_value, unknown_reference, conflict], description: '`conflict`: a record with this `record_id` was already admitted with different content.' }
        path: { type: string, description: The JSONPath in the record or mapping that failed. }
        message: { type: string }
    IngestResult:
      type: object
      required: [index, record_id, status, observations, errors]
      properties:
        index: { type: integer }
        record_id: { type: string }
        status:
          type: string
          enum: [admitted, duplicate, rejected]
          description: '`duplicate` means this record was already admitted with identical content.'
        observations:
          type: array
          items: { $ref: '#/components/schemas/ObservationId' }
        errors:
          type: array
          items: { $ref: '#/components/schemas/RecordError' }
    FeedHealth:
      type: object
      required: [object, feed, state, window, last_record_at, expected_interval_s, records_per_s, rejected_ratio, latency_ms, recent_errors]
      properties:
        object: { const: feed_health }
        feed: { $ref: '#/components/schemas/FeedId' }
        state: { type: string, enum: [healthy, degraded, silent] }
        window:
          type: object
          required: [from, to]
          properties:
            from: { $ref: '#/components/schemas/Timestamp' }
            to: { $ref: '#/components/schemas/Timestamp' }
        last_record_at: { oneOf: [{ $ref: '#/components/schemas/Timestamp' }, { type: 'null' }] }
        expected_interval_s: { type: integer, description: The longest gap between records before the feed counts as silent. }
        records_per_s: { type: number }
        rejected_ratio: { type: number, minimum: 0, maximum: 1 }
        latency_ms:
          type: object
          description: From `observed_at` to admission.
          properties:
            p50: { type: integer }
            p95: { type: integer }
            p99: { type: integer }
        recent_errors:
          type: array
          items:
            type: object
            required: [at, code, message, count]
            properties:
              at: { $ref: '#/components/schemas/Timestamp' }
              code: { type: string }
              message: { type: string }
              count: { type: integer }

    ScenarioChange:
      oneOf:
        - type: object
          title: runway_closure
          required: [type, runway, from, until]
          properties:
            type: { const: runway_closure }
            runway: { $ref: '#/components/schemas/EntityId' }
            from: { $ref: '#/components/schemas/Timestamp' }
            until: { $ref: '#/components/schemas/Timestamp' }
        - type: object
          title: taxiway_closure
          required: [type, taxiway, from, until]
          properties:
            type: { const: taxiway_closure }
            taxiway: { $ref: '#/components/schemas/EntityId' }
            from: { $ref: '#/components/schemas/Timestamp' }
            until: { $ref: '#/components/schemas/Timestamp' }
        - type: object
          title: stand_closure
          required: [type, stand, from, until]
          properties:
            type: { const: stand_closure }
            stand: { $ref: '#/components/schemas/EntityId' }
            from: { $ref: '#/components/schemas/Timestamp' }
            until: { $ref: '#/components/schemas/Timestamp' }
        - type: object
          title: flight_delay
          required: [type, flight, minutes]
          properties:
            type: { const: flight_delay }
            flight: { $ref: '#/components/schemas/EntityId' }
            minutes: { type: integer, minimum: 1, maximum: 720 }
    ScenarioCreate:
      type: object
      required: [airport, changes]
      properties:
        airport: { $ref: '#/components/schemas/AirportId' }
        name: { type: string, maxLength: 120 }
        day:
          type: string
          format: date
          description: The local operating day to simulate. Defaults to the day of the first change.
        changes:
          type: array
          minItems: 1
          maxItems: 20
          items: { $ref: '#/components/schemas/ScenarioChange' }
    ScenarioMetrics:
      type: object
      required: [departure_delay_min, arrival_delay_min, mean_taxi_out_min, max_departure_queue, on_time_departure_ratio]
      properties:
        departure_delay_min: { type: number, description: Total departure delay against schedule, in minutes. }
        arrival_delay_min: { type: number, description: Total arrival delay against schedule, in minutes. }
        mean_taxi_out_min: { type: number }
        max_departure_queue: { type: number, description: Most aircraft waiting for departure at once. }
        on_time_departure_ratio: { type: number, description: Share of departures within 15 minutes of schedule. }
    Scenario:
      type: object
      required: [id, object, airport, name, day, window, changes, status, created_at, completed_at, result]
      properties:
        id: { type: string, pattern: '^scn_[0-9a-z]{10}$' }
        object: { const: scenario }
        airport: { $ref: '#/components/schemas/AirportId' }
        name: { type: string }
        day: { type: string, format: date }
        window:
          type: object
          description: The simulated period in UTC, midnight to midnight local time.
          required: [from, to]
          properties:
            from: { $ref: '#/components/schemas/Timestamp' }
            to: { $ref: '#/components/schemas/Timestamp' }
        changes:
          type: array
          items: { $ref: '#/components/schemas/ScenarioChange' }
        status: { type: string, enum: [queued, running, succeeded, failed] }
        created_at: { $ref: '#/components/schemas/Timestamp' }
        completed_at: { oneOf: [{ $ref: '#/components/schemas/Timestamp' }, { type: 'null' }] }
        result:
          oneOf:
            - type: 'null'
            - type: object
              required: [movements, duration_ms, baseline, scenario, difference, affected_flights]
              properties:
                movements: { type: integer, description: Arrivals and departures simulated. }
                duration_ms: { type: integer, description: Wall-clock time for both runs. }
                baseline: { $ref: '#/components/schemas/ScenarioMetrics' }
                scenario: { $ref: '#/components/schemas/ScenarioMetrics' }
                difference: { $ref: '#/components/schemas/ScenarioMetrics' }
                affected_flights: { type: integer }
    ScenarioFlight:
      type: object
      required: [flight, direction, baseline, scenario, delay_min, reason]
      properties:
        flight: { $ref: '#/components/schemas/EntityId' }
        direction: { type: string, enum: [arrival, departure] }
        baseline: { $ref: '#/components/schemas/ScenarioFlightTimes' }
        scenario: { $ref: '#/components/schemas/ScenarioFlightTimes' }
        delay_min: { type: integer, description: Scenario minus baseline at the runway. }
        reason: { type: string, enum: [runway_closure, taxiway_closure, stand_closure, flight_delay, knock_on] }
    ScenarioFlightTimes:
      type: object
      required: [runway, runway_at]
      properties:
        off_block_at: { $ref: '#/components/schemas/Timestamp' }
        on_block_at: { $ref: '#/components/schemas/Timestamp' }
        runway: { $ref: '#/components/schemas/EntityId' }
        runway_at: { $ref: '#/components/schemas/Timestamp' }

    WebhookEventType:
      type: string
      enum: [airfield.status_changed, feed.health_changed, scenario.completed]
    Webhook:
      type: object
      required: [id, object, url, events, airports, status, created_at]
      properties:
        id: { type: string, pattern: '^wh_[0-9a-z]{10}$' }
        object: { const: webhook }
        url: { type: string, format: uri }
        events:
          type: array
          items: { $ref: '#/components/schemas/WebhookEventType' }
        airports:
          type: array
          items: { $ref: '#/components/schemas/AirportId' }
        status:
          type: string
          enum: [enabled, disabled]
          description: '`disabled` after 24 hours of failed deliveries.'
        secret: { type: string, description: Signing secret. Returned only on creation. }
        created_at: { $ref: '#/components/schemas/Timestamp' }
    WebhookDelivery:
      type: object
      required: [id, type, airport, created_at, data]
      properties:
        id: { type: string, description: Unique per event. Deduplicate on it. }
        type: { $ref: '#/components/schemas/WebhookEventType' }
        airport: { $ref: '#/components/schemas/AirportId' }
        created_at: { $ref: '#/components/schemas/Timestamp' }
        data: { type: object }

    Scope:
      type: string
      enum:
        - airports:read
        - entities:read
        - observations:read
        - events:read
        - feeds:read
        - feeds:write
        - records:write
        - scenarios:read
        - scenarios:write
        - webhooks:write
        - applications:write
    ApplicationCreate:
      type: object
      required: [name, airports, scopes]
      properties:
        name: { type: string, maxLength: 80 }
        airports:
          type: array
          minItems: 1
          items: { $ref: '#/components/schemas/AirportId' }
        scopes:
          type: array
          minItems: 1
          items: { $ref: '#/components/schemas/Scope' }
        entity_types:
          type: array
          description: Entity types the application may read. Omit for all.
          items: { $ref: '#/components/schemas/EntityType' }
        feeds:
          type: array
          description: Feeds the application may push records to with `records:write`.
          items: { $ref: '#/components/schemas/FeedId' }
    Application:
      type: object
      required: [id, object, name, airports, scopes, entity_types, feeds, created_at]
      properties:
        id: { type: string, pattern: '^app_[0-9a-z]{10}$' }
        object: { const: application }
        name: { type: string }
        airports:
          type: array
          items: { $ref: '#/components/schemas/AirportId' }
        scopes:
          type: array
          items: { $ref: '#/components/schemas/Scope' }
        entity_types:
          type: array
          items: { $ref: '#/components/schemas/EntityType' }
        feeds:
          type: array
          items: { $ref: '#/components/schemas/FeedId' }
        created_at: { $ref: '#/components/schemas/Timestamp' }
    ApiKey:
      type: object
      required: [id, object, application, environment, prefix, created_at, expires_at, last_used_at]
      properties:
        id: { type: string, pattern: '^key_[0-9a-z]{10}$' }
        object: { const: api_key }
        application: { type: string }
        environment: { $ref: '#/components/schemas/Environment' }
        label: { type: string }
        prefix: { type: string, description: The first 12 characters of the secret, for recognising it in logs. }
        secret: { type: string, description: The key itself. Returned only on creation. }
        created_at: { $ref: '#/components/schemas/Timestamp' }
        expires_at: { oneOf: [{ $ref: '#/components/schemas/Timestamp' }, { type: 'null' }] }
        last_used_at: { oneOf: [{ $ref: '#/components/schemas/Timestamp' }, { type: 'null' }] }

    NodeStatus:
      type: object
      required: [object, node, checked_at, airports]
      properties:
        object: { const: node_status }
        node:
          type: object
          required: [id, kind]
          properties:
            id: { type: string }
            kind: { type: string, enum: [edge, onprem] }
            region: { type: string }
            colo: { type: string, description: The Cloudflare data centre that answered. Edge only. }
        checked_at: { $ref: '#/components/schemas/Timestamp' }
        airports:
          type: array
          items:
            type: object
            required: [airport, role, epoch, revision, peer]
            properties:
              airport: { $ref: '#/components/schemas/AirportId' }
              role:
                type: string
                enum: [primary, standby]
                description: The primary admits writes for the airport. The standby serves reads and follows the primary.
              epoch: { type: integer, description: Increases by one each time the primary changes. }
              revision: { type: integer }
              peer:
                type: object
                required: [kind, reachable]
                properties:
                  kind: { type: string, enum: [edge, onprem] }
                  reachable: { type: boolean }
                  lag_ms: { type: [integer, 'null'], description: How far the standby is behind the primary. }

    Problem:
      type: object
      required: [type, title, status, code, detail, request_id]
      properties:
        type: { type: string, format: uri, description: Link to this error's documentation. }
        title: { type: string }
        status: { type: integer }
        code: { $ref: '#/components/schemas/ErrorCode' }
        detail: { type: string, description: What went wrong with this request, in a sentence. }
        request_id: { type: string }
        errors:
          type: array
          description: Per-field problems, on `invalid_parameter` and `invalid_body`.
          items:
            type: object
            properties:
              parameter: { type: string }
              pointer: { type: string, description: JSON Pointer into the request body. }
              message: { type: string }
    ErrorCode:
      type: string
      enum:
        - invalid_parameter
        - invalid_body
        - authentication_required
        - key_revoked
        - insufficient_scope
        - airport_not_permitted
        - not_found
        - time_out_of_range
        - conflict
        - idempotency_key_reused
        - payload_too_large
        - rate_limited
        - not_primary
        - unavailable
        - internal_error

    # Partner observation operations. These mirror the draft observation gateway
    # contract in contracts/gateway; see the comment above /observations.
    PartnerTimestamp:
      type: string
      format: date-time
      description: UTC from 1970 onward, with up to millisecond precision.
      pattern: '^(?:19[7-9][0-9]|[2-9][0-9]{3})-[0-9]{2}-[0-9]{2}T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,3})?Z$'
    PartnerRef:
      type: string
      minLength: 1
      maxLength: 128
    PartnerPosition:
      type: object
      required: [longitude, latitude]
      properties:
        longitude: { type: number, minimum: -180, maximum: 180 }
        latitude: { type: number, minimum: -90, maximum: 90 }
    PartnerObservation:
      type: object
      description: One report from a producer. `kind` decides which other fields it carries.
      oneOf:
        - $ref: '#/components/schemas/PartnerSuspectedFod'
        - $ref: '#/components/schemas/PartnerInspectionClear'
        - $ref: '#/components/schemas/PartnerAircraftPosition'
      discriminator:
        propertyName: kind
        mapping:
          suspected_fod: '#/components/schemas/PartnerSuspectedFod'
          inspection_clear: '#/components/schemas/PartnerInspectionClear'
          aircraft_position: '#/components/schemas/PartnerAircraftPosition'
      examples:
        - sourceObservationId: vtbs-adsb-8851a4-0258
          airportIcao: VTBS
          observedAt: '2026-11-23T02:58:00.400Z'
          kind: aircraft_position
          aircraftRef: '8851a4'
          position: { longitude: 100.75391, latitude: 13.69212 }
          evidenceOrigin: Synthetic
    PartnerSuspectedFod:
      title: Suspected FOD
      type: object
      required: [sourceObservationId, airportIcao, observedAt, kind, areaRef, evidenceOrigin]
      properties:
        sourceObservationId:
          $ref: '#/components/schemas/PartnerRef'
          description: Your ID for the report. Keep it stable across retries and unique per producer and airport.
        airportIcao: { $ref: '#/components/schemas/AirportId' }
        observedAt:
          $ref: '#/components/schemas/PartnerTimestamp'
          description: When the reported observation happened. The gateway records when it admitted the report separately.
        kind: { const: suspected_fod }
        areaRef:
          $ref: '#/components/schemas/PartnerRef'
          description: An agreed area reference. It carries no object coordinates.
        evidenceOrigin:
          type: string
          enum: [Synthetic, PhysicalCapture]
          description: Source policy restricts which origins a producer may send.
    PartnerInspectionClear:
      title: Inspection clear
      type: object
      required: [sourceObservationId, airportIcao, observedAt, kind, areaRef, evidenceOrigin]
      properties:
        sourceObservationId:
          $ref: '#/components/schemas/PartnerRef'
          description: Your ID for the report. Keep it stable across retries and unique per producer and airport.
        airportIcao: { $ref: '#/components/schemas/AirportId' }
        observedAt:
          $ref: '#/components/schemas/PartnerTimestamp'
          description: When the reported observation happened. The gateway records when it admitted the report separately.
        kind: { const: inspection_clear }
        areaRef:
          $ref: '#/components/schemas/PartnerRef'
          description: An agreed area reference. It carries no object coordinates.
        evidenceOrigin:
          type: string
          enum: [Synthetic, PhysicalCapture]
          description: Source policy restricts which origins a producer may send.
    PartnerAircraftPosition:
      title: Aircraft position
      type: object
      required: [sourceObservationId, airportIcao, observedAt, kind, aircraftRef, position, evidenceOrigin]
      properties:
        sourceObservationId:
          $ref: '#/components/schemas/PartnerRef'
          description: Your ID for the report. Keep it stable across retries and unique per producer and airport.
        airportIcao: { $ref: '#/components/schemas/AirportId' }
        observedAt:
          $ref: '#/components/schemas/PartnerTimestamp'
          description: When the reported observation happened. The gateway records when it admitted the report separately.
        kind: { const: aircraft_position }
        aircraftRef:
          $ref: '#/components/schemas/PartnerRef'
          description: Your stable reference for the aircraft track, in your own namespace.
        position:
          $ref: '#/components/schemas/PartnerPosition'
          description: The reported position, as WGS84 `longitude` and `latitude` in decimal degrees.
        evidenceOrigin:
          type: string
          enum: [Synthetic, Telemetry]
          description: Source policy restricts which origins a producer may send.
    PartnerIngestRequest:
      type: object
      required: [observations]
      properties:
        observations:
          type: array
          minItems: 1
          maxItems: 100
          description: Observations from one airport. Do not send a producer or world; the key supplies them.
          items: { $ref: '#/components/schemas/PartnerObservation' }
    PartnerIngestReceipt:
      type: object
      required: [results]
      properties:
        results:
          type: array
          minItems: 1
          maxItems: 100
          description: One result per submitted observation, in request order.
          items:
            type: object
            required: [sourceObservationId, recordId, disposition]
            properties:
              sourceObservationId: { $ref: '#/components/schemas/PartnerRef' }
              recordId:
                $ref: '#/components/schemas/PartnerRef'
                description: The gateway's ID for the admitted record. An exact retry returns the original ID.
              disposition:
                type: string
                enum: [stored, existing]
                description: '`stored` for a newly admitted report, `existing` for an identical resubmission.'
    PartnerObservationPage:
      type: object
      required: [worldClass, snapshotRef, observations, nextCursor]
      properties:
        worldClass: { type: string, enum: [operational, simulation] }
        snapshotRef:
          $ref: '#/components/schemas/PartnerRef'
          description: The admission cutoff that every page of this read uses. It grants no access.
        observations:
          type: array
          description: Ordered by `observedAt`, then `recordId`. Reports admitted after the cutoff are excluded.
          items:
            type: object
            required: [recordId, admittedAt, observation]
            properties:
              recordId: { $ref: '#/components/schemas/PartnerRef' }
              admittedAt:
                $ref: '#/components/schemas/PartnerTimestamp'
                description: When the gateway first admitted the record.
              observation: { $ref: '#/components/schemas/PartnerObservation' }
        nextCursor:
          oneOf: [{ $ref: '#/components/schemas/PartnerRef' }, { type: 'null' }]
          description: Pass as `cursor` for the next page. `null` on the last page.
    PartnerAircraftQuery:
      type: object
      required: [airportIcao, asOf, maxAgeMs, centre, radiusM]
      properties:
        airportIcao: { $ref: '#/components/schemas/AirportId' }
        asOf:
          $ref: '#/components/schemas/PartnerTimestamp'
          description: Inclusive cutoff on reported observation time, independent of the admission cutoff.
        maxAgeMs:
          type: integer
          minimum: 0
          maximum: 3600000
          description: Only positions observed at most this many milliseconds before `asOf` count.
        centre:
          $ref: '#/components/schemas/PartnerPosition'
          description: WGS84 `longitude` and `latitude` in decimal degrees.
        radiusM:
          type: number
          minimum: 0
          maximum: 50000
          description: Inclusive great-circle radius, in metres.
        snapshotRef:
          $ref: '#/components/schemas/PartnerRef'
          description: The admission cutoff of an earlier read at this airport. Omit to use the current cutoff.
    PartnerAircraftResult:
      type: object
      required: [worldClass, snapshotRef, asOf, count, tracks]
      properties:
        worldClass: { type: string, enum: [operational, simulation] }
        snapshotRef: { $ref: '#/components/schemas/PartnerRef' }
        asOf: { $ref: '#/components/schemas/PartnerTimestamp' }
        count:
          type: integer
          minimum: 0
          description: The number of tracks returned. It depends on feed coverage and freshness at the cutoff.
        tracks:
          type: array
          description: The latest qualifying position of each source track, nearest first.
          items:
            type: object
            required: [recordId, aircraftRef, observedAt, position, distanceM]
            properties:
              recordId: { $ref: '#/components/schemas/PartnerRef' }
              aircraftRef: { $ref: '#/components/schemas/PartnerRef' }
              observedAt: { $ref: '#/components/schemas/PartnerTimestamp' }
              position: { $ref: '#/components/schemas/PartnerPosition' }
              distanceM: { type: number, minimum: 0, description: Distance from `centre`, in metres. }
    PartnerError:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code:
              type: string
              enum:
                - invalid_request
                - authentication_required
                - airport_access_denied
                - observation_conflict
                - payload_too_large
                - rate_limited
                - temporarily_unavailable
            message: { type: string }
            requestId: { $ref: '#/components/schemas/PartnerRef' }
