# OIP-0001: Read APIs on OGC endpoints

| Field | Value |
|---|---|
| Status | DRAFT |
| Closes | G-EXCH-1 (function `exchange`, §5.10) |
| Affects | §5.10, §6 (Exchange row), §9; `schemas/json/product-manifest.schema.json`; `registers/functions.yaml` (`exchange`); `registers/relations.yaml` (`EXT-STA`, `EXT-STAC`, new rows for OGC API and WIS 2.0); new binding `bindings/ogc-api/`; new cases CT-GRID-004 to CT-GRID-007, CT-CONSUMER-004 and CT-CONSUMER-005 |
| Protocol version | obsp/0.1 |
| Last call | 30 days (revision of an existing function) unless the editors rule otherwise; see Open questions |

## Problem

The `exchange` function is declared but has no contract for reading. A grid operator can publish products, and a
consumer can hold a ProductManifest, but nothing says how a product, its observations or the catalogue of products
are read, so two implementations cannot interoperate and no case can test a read endpoint. The gateway API has no
read operation for observations, products or a catalogue.

Two further defects sit in the same function:

1. §5.10 requires every product to carry licence, the most restrictive upstream term, quality and correction state,
   but `product-manifest` has none of these fields and forbids additional properties. A manifest without a licence
   validates today.
2. §5.10 lists OGC API Connected Systems among the bindings an implementation SHOULD use. That standard is a draft;
   the protocol targets published editions only.

## Change

### Normative text (replaces the bullets of §5.10)

Governed products reach people and applications through versioned, read-only APIs, events, maps and exports.

1. **EXCH-1.** Every product an operator serves MUST have a ProductManifest that carries its licence, the most
   restrictive term of any upstream source, a quality statement and its correction state.
2. **EXCH-2.** A ProductManifest MUST declare every read endpoint that serves the product (`endpoints`), each with
   the binding it follows and the binding's version.
3. **EXCH-3.** A read endpoint MUST be read-only toward sites: it exposes no operation that changes state (P7).
4. **EXCH-4.** Every collection, feature, record or item an endpoint returns MUST identify the product
   (`productId`) and carry its current correction state; a superseded, withdrawn or recalled product MUST be
   answered with that state, never served as current and never silently dropped.
5. **EXCH-5.** A missing observed value MUST be served as its typed state (§5.6), never as zero, an empty string or
   an untyped null.
6. **EXCH-6.** A grid operator MUST serve a catalogue of its products as OGC API Records, one record per
   ProductManifest, derived from it without loss of licence, upstream term, quality or correction state.
7. **EXCH-7.** Geospatial products SHOULD be served through OGC API Features or OGC API EDR. Observations MAY also
   be served through OGC SensorThings API 1.1 (Sensing). Archives SHOULD be described with STAC. Publication to
   WMO WIS 2.0 is a product option.
8. **EXCH-8.** Errors MUST be RFC 9457 problem details valid against `error-problem`.
9. **EXCH-9.** A consumer MUST NOT present a product whose correction state is `WITHDRAWN` or `RECALLED` as current,
   and MUST carry the product's licence and upstream term with anything it re-publishes.

The bindings in EXCH-6 and EXCH-7 are profiled in `bindings/ogc-api/` (requirements `BND-OGCAPI-NN`), which maps
each protocol field to the standard's term by clause. OGC API Connected Systems and SensorThings API 2.0 are drafts:
they are tracked and not targeted until a published edition exists and a later proposal adds them.

§6, Exchange row: "OpenAPI 3.1; OGC API Features, EDR and Records (`bindings/ogc-api/`); SensorThings 1.1 Sensing;
STAC; WIS 2.0 (optional)".

### Contract changes

`product-manifest` (schemaVersion `3.1.0`, see Compatibility), new properties:

| Property | Required | Shape |
|---|---|---|
| `licence` | yes | object: `id` (SPDX licence identifier) or `uri` (one of the two), optional `title` |
| `upstreamTerm` | yes | object: `term` (the most restrictive upstream licence or use term, same shape as `licence`), `sourceRefs` (array of source-release UNIs it comes from, at least one), or `none: true` when the product has no upstream source |
| `quality` | yes | object: `worstFlag` (the most severe value present, from the §5.6 quality-flag vocabulary `GOOD`, `SUSPECT`, `BAD`, `MISSING`, `ESTIMATED`, `NOT_CHECKED`; no new vocabulary), optional `flagsRef` (EvidenceRef to the QualityFlag set) |
| `correctionState` | yes | the `correctionState` vocabulary of `StateVector` (`CURRENT`, `DISPUTED`, `SUPERSEDED`, `WITHDRAWN`, `RECALLED`) |
| `supersededBy` | when `correctionState` is `SUPERSEDED` | productId and version of the successor |
| `version` | yes | product version string; a corrected product is a new version (§5.9) |
| `endpoints` | yes, may be empty only when `outputs` are exports alone | array of `{binding, bindingVersion, href}`; `binding` one of `ogc-api-features`, `ogc-api-edr`, `ogc-api-records`, `sensorthings-1.1`, `stac`, `wis2-notification`; `href` an absolute URI or a URI template |

No new protocol object is added. The catalogue record, the feature and the SensorThings entities are projections
of existing objects (`product-manifest`, `observation-record`, `sensor-passport`, `source-release`) defined by the
binding, not new contracts.

New invariants (suite): `product-manifest-superseded-has-successor`, `product-manifest-upstream-term-sourced`,
`exchange-endpoints-declared` (every endpoint a report or evidence names is declared in the manifest),
`observation-missing-is-typed` (extends the existing typed-missing rule to the exchange projection).

## Compatibility

Pre-1.0 a minor version MAY break (§10). The new required properties make existing ProductManifests invalid. The
proposal treats this as a correction rather than a new contract version: §5.10 already required licence, upstream
term, quality and correction state, so no conforming 0.1 manifest could omit them. `schemaVersion` stays `3.1.0`.
Migration: an operator adds the seven properties; there is no automatic default for a licence. If the editors rule
the change breaking, the alternative is `schemaVersion` `3.2.0` for `product-manifest` with `3.1.0` accepted until
0.2.

## Tests

| Requirement | Case | Kind | Evidence |
|---|---|---|---|
| EXCH-1, EXCH-2 | CT-GRID-004 | schema + invariant | product-manifest |
| EXCH-4 (manifest side) | CT-GRID-005 | invariant | product-manifest (`product-manifest-superseded-has-successor`) |
| EXCH-5 | CT-GRID-006 | invariant | observation-record |
| EXCH-3, EXCH-6, EXCH-7, EXCH-8 | CT-GRID-007 | manual until the live harness exists, then live | attestation of an endpoint run; replaced by live cases in slice S6 |
| EXCH-9 | CT-CONSUMER-004 | manual | consumer attestation |
| EXCH-1 (consumer side) | CT-CONSUMER-005 | invariant | product-manifest (`product-manifest-upstream-term-sourced`) |

Negative fixtures (each breaks one rule): `product-manifest.missing-licence`, `.upstream-term-unsourced`,
`.superseded-without-successor`, `.unknown-endpoint-binding`, `.correction-state-unknown`, `.licence-id-and-uri`.
The binding adds its own examples both ways under `bindings/ogc-api/examples/`.

## Open questions

1. Last call: is closing a gap of an existing function a revision (30 days) or a new function's worth (90 days)?
2. Is adding required properties to `product-manifest` at `3.1.0` acceptable as a correction, or does it need
   `3.2.0`?
3. Should the catalogue also be offered as DCAT 3 (crosswalk `crosswalks/dcat.yaml`), or is OGC API Records with
   the DCAT crosswalk enough?
4. Tiles: §5.10 named OGC API Tiles; this proposal does not profile it (a tile carries no product identity per
   item). Keep as SHOULD without a binding, or drop?

Acceptance needs appointed editors and a last-call window. Until then this proposal stays at DRAFT or REVIEW and
`exchange` stays `OPEN_GAP` in the registers.
