Skip to content

feat(core)!: v0.6.0 - #1427

Draft
SnowboardTechie wants to merge 5 commits into
mainfrom
CORE-v0.6.0
Draft

SnowboardTechie wants to merge 5 commits into
mainfrom
CORE-v0.6.0

Conversation

@SnowboardTechie

@SnowboardTechie SnowboardTechie commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Releases CommonGrants protocol v0.6.0. This is the staging PR for the CORE-v0.6.0 hold branch (hold branch rules). The release delivers the core library side of the API contract versioning epic (#582), which implements ADR 0032 (API version negotiation), plus the other core work in the [Core] v0.6.0 release milestone.

Note

Draft: not all of the release has merged into the hold branch yet. It's opened early so CI and the website preview run on the combined changes as each PR lands. Each PR into the hold branch is reviewed on its own, so this PR shouldn't need a full review. Changes apply to v0.6 only: the v0.1.0 to v0.5.0 OpenAPI documents are unchanged on the branch today.

Merged into the hold branch

Version negotiation (#582):

  • Version headers on every route. Optional CG-Version request header. Every response carries CG-Version-Served, plus optional Vary, Deprecation, Sunset and Link. Adds Versions.v0_6 and Types.protocolVersion. (#1401, fixes #1386)
  • Version errors on every route. version.malformed and version.conflict (400), version.unsupported and version.retired (406), added to every protocol route through Responses.WithVersionErrors<R>. (#1414, fixes #1388)
  • Versions discovery route. Optional GET /common-grants/versions returning VersionDiscovery (default version, baseline versions, per-route differences, upcoming default, deprecations). (#1399, fixes #1387)

Still to land

Open PRs into the hold branch:

  • #1421: optional searchInfo on the opportunity and award search responses (#959)
  • #1422: integer, not int32, for the pagination fields (#1196)
  • #1423 (draft): protocol docs for version negotiation (#1389)
  • #1415 (draft): mock API reads the CG-Version header (#1393)
  • #1418: cg check spec checks the version headers (#1390, CLI milestone; rides on this branch because it needs the 0.6.0 spec)

Open issues in the milestone or epic with no PR yet:

  • #1391: models, types and API docs dropdown for v0.6
  • #1392: CI check that the published OpenAPI documents don't change
  • #1419: spike on renaming Paginated / Sorted / Filtered to *Results; decides whether the rename ships in v0.6.0
  • #872: simplify protocol docs generation
  • Review rounds: #1406, #1407, #1408, #1409

SDK support for the discovery models ships in the SDK releases, not here: #1425 (TS SDK) and #1426 (Py SDK).

Before this leaves draft

  • Every PR in the milestone has merged into the hold branch, and the hold branch is synced with main
  • The core release review checklist has been run and its results noted here
  • This description has been rewritten as the squash commit body, one conventional-commit line per change, with BREAKING-CHANGE: footers where they apply (releasing from a hold branch)
  • The title keeps the ! only if a breaking change has landed. ADR 0032 makes the version negotiation work purely additive, so the ! depends on what else ships, such as the rename #1419 is weighing
  • The team has agreed whether a Python SDK release ships alongside core. The branch moves the Python SDK's core baseline test (lib/python-sdk/tests/schemas/test_award_inventory.py) to 0.6.0, so merging this PR also opens a Python SDK Release PR (SDK changes)
  • After merge, the issues fixed through the hold branch are closed by hand (GitHub doesn't auto-close them from a hold-branch PR)

karinamzalez and others added 3 commits November 18, 2026 10:35
### Summary

- Fixes #1386
- Time to review: 20 minutes

Adds protocol version 0.6.0 and the version headers from ADR 0032 (API
version negotiation) to the core library. Clients can ask for a version
with `CG-Version`, and every response confirms the version it was served
in with `CG-Version-Served`. The docs mock API now serves 0.6.0 so the
website build stays green. The version errors (#1388), the discovery
route (#1387, PR #1399), the docs (#1389, #1391) and moving the mock to
the version header (#1393) are separate tickets.

> [!IMPORTANT]
> This PR and #1399 both add `Versions.v0_6` and
`Types.protocolVersion`. Whichever merges second drops its copy. Once
both land, the discovery route needs its own 200 response without the
version headers, because ADR 0032 says discovery carries neither
`CG-Version-Served` nor `Vary`.

### Changes proposed

- Protocol version 0.6.0:
  - `lib/core/lib/main.tsp`: adds `v0_6: "0.6.0"` to `Versions`.
- `lib/core/lib/core/types.tsp`: adds `Types.protocolVersion`, a full
`MAJOR.MINOR.PATCH` version with no `v` prefix, no short forms and no
leading zeros.
- `lib/core/lib/core/headers.tsp`: new `CommonGrants.Headers` namespace,
not emitted as JSON Schema.
  - `VersionRequest`: optional `CG-Version` request header.
- `VersionResponse`: required `CG-Version-Served`, plus optional `Vary`,
`Deprecation` (RFC 9745 `@<timestamp>`), `Sunset` (RFC 8594 HTTP-date)
and `Link`.
- `VersionResponseAuth`: the same headers with `CG-Version-Served`
optional, for 401 and 403, because authentication can run before version
selection.
- The namespace example shows `...Headers.VersionRequest` on a
hand-declared protocol route, since custom routes ignore `CG-Version`.
- `lib/core/lib/core/index.tsp`: imports `headers.tsp`.
- Request header on every route:
`lib/core/lib/core/routes/{opportunities,awards,orgs,competitions,applications,form-responses,forms}.tsp`
spread `...Headers.VersionRequest` as the last parameter of every
operation, so adopters inherit it through `op x is Router.y`.
- Response headers on every response:
- `lib/core/lib/core/responses/success.tsp`: spreads
`...Headers.VersionResponse` into `OkT`, `PaginatedT`, `SortedT`,
`FilteredT`, `CreatedT` and `AcceptedT`. The emitted non-template models
are untouched.
- `lib/core/lib/core/responses/error.tsp`: `NotFound` intersects
`VersionResponse`. `Unauthorized` and `Forbidden` intersect
`VersionResponseAuth`.
- `lib/core/lib/core/routes/applications.tsp`: `submitApplication`
returns a new `ApplicationSubmissionErrorResponse` wrapper with an
explicit `@body`, so the submission error keeps `@error` and its body
reference while gaining the headers.
- Generated: `website/public/openapi/openapi.0.6.0.yaml` and
`website/public/schemas/yaml/protocolVersion.yaml`.
- Docs mock API serves 0.6.0:
- `website/src/lib/mock/data/fixtures.ts`: adds `0.6.0` to
`SUPPORTED_VERSIONS`. It shapes responses the same as 0.5.0, because
0.6.0 adds only headers.
- `website/__tests__/lib/mock/**` and
`website/__tests__/scripts/inject-mock-server.spec.ts`: cover 0.6.0, and
use 0.7.0 as the unsupported version.
- `lib/python-sdk/tests/schemas/test_award_inventory.py`: moves the Core
baseline tripwire from 0.5.0 to 0.6.0. 0.6.0 adds no fields to the Award
closure.

### Context for reviewers

The part worth the closest look is how the headers stay out of the 0.1.0
to 0.5.0 documents and out of the JSON Schemas.

- **Versioning on spreads.** Every header property carries its own
`@added(v0_6)`. Spreading a model copies its properties without the
model's versioning, so a model-level `@added` alone leaked the headers
into older documents.
- **Submission error wrapper.** It lives in `Routes`, not `Responses`,
because `Responses` is `@jsonSchema` and would emit the headers as
schema fields. Intersecting the headers onto
`ApplicationSubmissionError` dropped `@error` and moved it into the 200
response. The wrapper's explanation is a `//` comment because a doc
comment replaced the response description in older documents.
- **`Vary` is optional in OpenAPI.** ADR 0032 requires it only on
cacheable responses, which OpenAPI can't express, so the rule lives in
the header description.
- **CI is green.** Adding `Versions.v0_6` used to break two checks: the
website's mock server guard and the Python SDK's Core baseline tripwire.
This PR updates both. The mock still selects the version from the URL
path; #1393 moves it to `CG-Version`.

To verify:

1. Run core CI. It should pass.
   ```bash
   pnpm --filter @common-grants/core run ci
   ```
2. Regenerate the website outputs. `git status` should show no changes
under `website/public`.
   ```bash
pnpm --filter website run typespec && git status --short website/public
   ```
3. Confirm the older documents are unchanged. The output should be
empty.
   ```bash
git diff --stat origin/CORE-v0.6.0 --
website/public/openapi/openapi.0.{1,2,3,4,5}.0.yaml
   ```
4. Confirm the only JSON Schema change is the new
`protocolVersion.yaml`.
   ```bash
   git diff --stat origin/CORE-v0.6.0 -- website/public/schemas
   ```
5. Count the headers in 0.6.0. Expect 21 request header references, one
per operation, and 47 `CG-Version-Served` headers, one per response.
   ```bash
grep -c "Headers.VersionRequest'"
website/public/openapi/openapi.0.6.0.yaml
grep -c "CG-Version-Served:" website/public/openapi/openapi.0.6.0.yaml
   ```

### Additional information

Core CI:

```
$ tsp compile lib/main.tsp
TypeSpec compiler v1.17.0

✔ Compiling
✔ @typespec/json-schema 68ms tsp-output/@typespec/json-schema/
✔ @typespec/openapi3 397ms tsp-output/@typespec/openapi3/

Compilation completed successfully.
```

Every response in `openapi.0.6.0.yaml`, grouped by status code (count,
then whether each header is required or optional):

```
 19  200     | CG-Version-Served:req Vary:opt Deprecation:opt Sunset:opt Link:opt
  1  201     | CG-Version-Served:req Vary:opt Deprecation:opt Sunset:opt Link:opt
  1  202     | CG-Version-Served:req Vary:opt Deprecation:opt Sunset:opt Link:opt
 10  404     | CG-Version-Served:req Vary:opt Deprecation:opt Sunset:opt Link:opt
  1  default | CG-Version-Served:req Vary:opt Deprecation:opt Sunset:opt Link:opt
  9  401     | CG-Version-Served:opt Vary:opt Deprecation:opt Sunset:opt Link:opt
  6  403     | CG-Version-Served:opt Vary:opt Deprecation:opt Sunset:opt Link:opt
Sunset schema: {"type":"string","format":"http-date"}
Deprecation schema: {"type":"string","pattern":"^@-?[0-9]+$"}
CG-Version-Served schema: {"$ref":"#/components/schemas/CommonGrants.Types.protocolVersion"}
CG-Version params: 21 of 21 operations
```

Every 0.5.0 response compared against 0.6.0 for body, description,
pre-existing headers (such as `Location` on 202) and request bodies:

```
checked 47 responses, 0 differences
component schemas added in 0.6.0: [ 'CommonGrants.Types.protocolVersion' ]
```

Adopter quickstarts still compile against the new route interfaces:

```
✓ Getting Started (First steps) quickstart compiles
✓ Getting Started (after Customization) quickstart compiles
✓ lib/core/README.md quickstart compiles
```
### Summary

- Fixes #1388
- Time to review: 20 minutes

Adds the ADR 0032 version errors (`version.malformed`,
`version.conflict`, `version.unsupported`, `version.retired`) to the
core library and to every protocol route, in 0.6.0 only. SDK support, a
docs page for the errors, and the discovery route (#1399) are out of
scope.

### Changes proposed

- `lib/core/lib/core/responses/version-errors.tsp` (new):
- `VersionErrorScope` enum and a `VersionErrorDetail` base with `field`,
`message`, `supported`, `defaultVersion` and optional `discovery`
- One detail model per code: `requested` is omitted on conflict, `scope`
is required on unsupported and retired, `sunset` is required on retired
- Detail models accept unknown fields (`...Record<unknown>`), like the
discovery models in #1399: a version error is returned when negotiation
fails, so clients must tolerate fields added later
- Four error bodies extending `Error` (400: malformed, conflict; 406:
unsupported, retired), each with an ADR-based example; `errors` requires
at least one entry
- Status-code aliases (`Http.BadRequestResponse`, `Http.Response<406>`),
so status codes stay out of the JSON Schemas; version errors carry no
version headers, per the ADR
- `WithVersionErrors<R>` union: keeps a route's responses and adds the
errors as two `@added(v0_6)` variants, one per status code
- A generic `BadRequest` alias joins the 400 variant, with an optional
`CG-Version-Served` and the lifecycle headers
- `lib/core/lib/core/routes/*.tsp`: every protocol route's return type
is wrapped in `Responses.WithVersionErrors<...>` (22 operations)
- Doc examples:
- `lib/core/lib/core/responses/index.tsp`: example of a declared
protocol route (`listOpportunities`) using the wrapper
- `lib/core/lib/core/headers.tsp`: the existing custom route example now
uses the wrapper
- Generated:
- `website/public/openapi/openapi.0.6.0.yaml`: 400 and 406 on every
`/common-grants/` operation, plus the new schemas
  - `website/public/schemas/yaml/Version*.yaml`: 10 new JSON Schemas

### Context for reviewers

Look most closely at `WithVersionErrors<R>` in `version-errors.tsp`. Its
docs are on the error variants, not the union, because `@typespec/http`
copies a union's doc onto every response it flattens (it was overwriting
the 200 and 404 descriptions, including in 0.2.0 to 0.5.0).

Every route's 0.6.0 400 also accepts an ordinary `Error` with an
optional `CG-Version-Served` header, so a body that fails validation in
the requested version (ADR 0032 scenarios) and `submitApplication`'s
submission error still match the documented 400.

To verify:

1. Regenerate the outputs: `pnpm --filter website run typespec`. Then
`git status --short website/public` should print nothing.
2. Check that only the 0.6.0 document changed: `git diff --stat
origin/CORE-v0.6.0 -- website/public/openapi/`
3. Open `website/public/openapi/openapi.0.6.0.yaml` and find
`/common-grants/opportunities/{oppId}`. It should list `400` (malformed,
conflict, or a generic `Error` with an optional `CG-Version-Served`) and
`406` (unsupported or retired, with no headers).
4. Run the core checks: `pnpm --filter @common-grants/core run checks`

### Additional information

Preview deploy: https://pr-1414-common-grants.agile6.workers.dev. The
0.6.0 document is at `/openapi/openapi.0.6.0.yaml`; it lists
`VersionUnsupportedError` on all 21 operations.

Only the 0.6.0 document changes. The 0.1.0 to 0.5.0 documents are
byte-identical:

```
$ git diff --stat origin/CORE-v0.6.0 -- website/public/openapi/
 website/public/openapi/openapi.0.6.0.yaml | 1298 ++++++++++++++++++++++++++++-
 1 file changed, 1281 insertions(+), 17 deletions(-)
```

A script over the 0.6.0 document confirmed that every `/common-grants/`
operation lists 400 and 406, references all four error schemas, and
carries no version headers on them:

```
operations checked: 21 | missing version errors: 0
```

(`Competitions.apply` is wrapped too but isn't exposed in `lib/api.tsp`,
same as on `main`.)

`GET /common-grants/opportunities/{oppId}` in 0.6.0:

```yaml
        '400':
          description: The `CG-Version` value is malformed or was sent more than once
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/CommonGrants.Responses.VersionMalformedError'
                  - $ref: '#/components/schemas/CommonGrants.Responses.VersionConflictError'
        '406':
          description: The requested version isn't served by this server or this route
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/CommonGrants.Responses.VersionUnsupportedError'
                  - $ref: '#/components/schemas/CommonGrants.Responses.VersionRetiredError'
```

An implementer who reuses a route op gets the errors only when targeting
0.6.0. For a test service with `read is
Routes.Opportunities.read<MyOpp>`:

```
v0.5 statuses: 200 404
v0.6 statuses: 200 400 404 406
```

Core checks:

```
All matched files use Prettier code style!
✔ 58 formatted
All 25 utcDateTime.fromISO examples have a UTC offset.
```
### Summary

- Fixes #1387
- Time to review: 15 minutes

### Changes proposed

A server built on core 0.6.0 can declare `GET /common-grants/versions`
and publish which protocol versions it serves: its default version, the
versions it serves across routes (the baseline), entries for routes that
differ from that baseline, and, while a change is pending, an upcoming
default and deprecated versions with their retirement dates. Clients can
check support before sending a request, per [ADR
0032](https://github.com/HHS/simpler-grants-protocol/blob/main/website/src/content/docs/governance/adr/0032-api-version-negotiation.md)
(API version negotiation).

- `Routes.ProtocolVersions.read()` returns the new
`Responses.VersionDiscoveryResponse`, wired into the base API at
`/common-grants/versions`, tagged `Versions` and `optional`. The route
is optional; the ADR requires it of servers that serve more than one
version, and the route description carries that and the other server
rules.
- `Responses.VersionDiscoveryResponse` is the standard success envelope
without the version headers. `OkT` spreads `Headers.VersionResponse`
since #1401, and the ADR says discovery carries neither
`CG-Version-Served` nor `Vary: CG-Version`, because clients call it
before they know which version to request.
- New models in `CommonGrants.Models`: `VersionDiscovery`,
`OperationVersions`, `UpcomingDefault`, `VersionRetirement`, with the
two examples from the ADR. These four models accept fields they don't
declare (`...Record<unknown>`, as `FormJsonSchema` and `FormUISchema`
already do), so a server can add discovery fields later without a new
protocol version, which is what the route's "fields are only ever added"
rule promises. Other core models stay closed to undeclared fields, apart
from those free-form form-schema models and the typed filter maps.
- Regenerated `website/public/openapi/openapi.0.6.0.yaml` and added five
JSON Schema files.

### Context for reviewers

**Rebased onto #1401 and #1414.** `Versions.v0_6` and
`Types.protocolVersion` now come from the version headers PR, so the
stubs this PR carried are gone. The field names (`versions`,
`defaultVersion`, `operations`, `upcomingDefault`, `deprecated`) match
the published ADR.

**Why these models are open.** Discovery is the one route a client calls
before it knows a version, so its shape can't be versioned per document;
that's why these models are open while other core models are closed to
undeclared fields (`seal-object-schemas: true` in the website build,
which the SDKs' strict validators follow). Whether the additive rule
should bind other models is for the ADR, not this PR.

**Verified:**

- `pnpm --filter @common-grants/core run ci` passes (lint, format,
types, example dates, build, compile).
- The 0.1.0 through 0.5.0 OpenAPI documents are byte-identical to
`CORE-v0.6.0`: `git diff origin/CORE-v0.6.0 --
website/public/openapi/openapi.0.{1,2,3,4,5}.0.yaml` is empty. No
existing JSON Schema file changed.
- `pnpm --filter website run check:quickstarts`, `build` and `test` pass
(1225 tests).
- In the 0.6.0 document the route's 200 declares no headers, it takes no
`CG-Version` parameter and declares no version errors (the ADR says
discovery never returns one), and it is tagged `Versions` and
`optional`.
- The JSON Schema files reject a `deprecated` key that isn't a protocol
version, such as `v0.3`, at the top level and in route entries.

This PR targets the `CORE-v0.6.0` hold branch (see
[`lib/README.md`](https://github.com/HHS/simpler-grants-protocol/blob/main/lib/README.md)
on hold branches), and GitHub doesn't auto-close issues from a
hold-branch PR. #1387 is closed by hand when the `feat(core)!: v0.6.0`
staging PR merges into `main`, per the hold-branch checklist in that
file.

**For adopters.** Until the CLI bundles the 0.6.0 base spec, `cg check`
reports `/common-grants/versions` as an extra route on a server that
implements it early.

OpenAPI 3.0 shows one of the two `VersionDiscovery` examples (the
lifecycle one); both are in `VersionDiscovery.yaml`. Same emitter
behaviour as the existing multi-example scalars. The blank line inside
the route's `@doc("""…""")` block carries trailing spaces because `tsp
format` writes it that way and `check:format` requires the formatter's
output.

### Additional information

Discovery response for a server whose baseline is 0.4.0 and whose form
list is served only in 0.5.0 (the first example on the model):

```json
{
  "status": 200,
  "message": "Success",
  "data": {
    "versions": ["0.4.0"],
    "defaultVersion": "0.4.0",
    "operations": {
      "GET /common-grants/forms": {
        "versions": ["0.5.0"],
        "defaultVersion": "0.5.0"
      },
      "GET /common-grants/forms/{formId}": {
        "versions": ["0.4.0", "0.5.0"],
        "defaultVersion": "0.4.0"
      }
    }
  }
}
```
@SnowboardTechie SnowboardTechie added this to the [Core] v0.6.0 release milestone Nov 20, 2026
@github-actions github-actions Bot added website Issues related to the website core Issues related to @common-grants/core library python Issue or PR related to Python tooling sdk Issue or PR related to our SDKs typescript Issue or PR related to TypeScript tooling py-sdk Related to Python SDK labels Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Website Preview Deployed!

Preview your changes at: https://pr-1427-common-grants.agile6.workers.dev

Built from commit e2f68fa

karinamzalez and others added 2 commits November 20, 2026 11:51
### Summary

- Fixes #1393
- Time to review: 40 minutes

The docs mock API now picks the protocol version from the `CG-Version`
header instead of the path, serves `GET /common-grants/versions`, and
answers version errors per ADR 0032. Retirement behavior (`Deprecation`,
`Sunset`) and SDK support for `CG-Version` are out of scope.

### Changes proposed

- Version resolution:
- `website/src/lib/mock/http/version.ts`: new resolver for `CG-Version`
(default 0.6.0, major.minor matching, `version.malformed` /
`version.conflict` / `version.unsupported`), plus `CG-Version-Served`
and `Vary` helpers
- `website/src/lib/mock/http/envelope.ts`: `versionErrorResponse` builds
the error envelope with the `discovery` URL
- `website/src/lib/mock/data/fixtures.ts`: `hostedVersionFor` maps a
requested version to the served one
- Routing by header:
- `website/src/lib/mock/router.ts`: one resource route without a path
version; resolves the version per route, then dispatches. A path like
`/api/v0.5.0/...` is now a plain route miss
- `website/src/lib/mock/data/availability.ts`: `versionsFrom` lists the
versions a route serves
- `website/src/lib/mock/handlers/*.ts`: take the resolved version
instead of reading it from the path
- `website/src/lib/mock/handlers/versions.ts`: new `GET
/common-grants/versions` handler; it ignores `CG-Version` and lists the
routes added after 0.1.0
- `website/src/lib/mock/http/cors.ts`: allows `CG-Version` on preflights
and exposes `CG-Version-Served`, `Deprecation`, `Sunset` and `Link`
- Docs page and Swagger UI:
- `website/src/lib/mock/docs-wiring.ts`,
`website/src/scripts/inject-mock-server.ts`: every mock spec advertises
one server, `/api`
- `website/src/lib/api-docs-version.ts`: `withVersionHeader` adds
`CG-Version` to mock requests unless the user typed one
- `website/src/pages/protocol/api-docs.astro`: wires that helper into
Swagger's `requestInterceptor` and lists v0.6.0 as Latest
- `website/src/content/docs/governance/adr/0028-mock-api-hosting.md`:
note that ADR 0032 supersedes the path version
- Tests (`website/__tests__/`):
- New: `lib/mock/http/version.spec.ts`,
`lib/mock/version-routing.spec.ts`,
`lib/mock/versions-discovery.spec.ts`, `lib/api-docs-version.spec.ts`
- Migrated to header-based requests through a shared
`lib/mock/__fixtures__/mock-request.ts` helper; the golden corpus sends
the path version as `CG-Version`
- `lib/mock/http/cors.spec.ts`: version headers on preflights and
responses

### Context for reviewers

The closest look belongs in `router.ts` and `handlers/versions.ts`:
version errors come before dispatch, and the discovery route list must
stay in step with the 0.6.0 spec (a conformance test walks
`openapi.0.6.0.yaml` to check it).

To verify:

1. Start the docs site: `pnpm --filter website run dev`
2. Run `curl -si http://localhost:4321/api/common-grants/opportunities
-H 'CG-Version: 0.5.1' | grep -i cg-version`. Expect `cg-version-served:
0.5.0`.
3. Run `curl -s http://localhost:4321/api/common-grants/awards -H
'CG-Version: 0.2.0'`. Expect a 406 with `version.unsupported` and
`scope: "operation"`.
4. Run `curl -s http://localhost:4321/api/common-grants/versions`.
Expect the supported versions and per-route `operations`.
5. Open http://localhost:4321/protocol/api-docs?version=0.1.0, "Try it
out" on `GET /common-grants/opportunities`, and Execute. The request
carries `CG-Version: 0.1.0` and the response `cg-version-served: 0.1.0`.

### Additional information

Preview:
https://pr-1415-common-grants.agile6.workers.dev/protocol/api-docs?version=0.1.0.
The verification steps above work against it by swapping
`http://localhost:4321` for
`https://pr-1415-common-grants.agile6.workers.dev`.

Mock responses, captured by calling `handleMockRequest` directly:

```
no header                          200 served=0.6.0 vary=CG-Version
CG-Version: 0.5.1                  200 served=0.5.0 vary=CG-Version
CG-Version: v0.5                   400 served=- vary=CG-Version version.malformed
CG-Version: 0.4.0, 0.5.0           400 served=- vary=CG-Version version.conflict
CG-Version: 9.0.0                  406 served=- vary=CG-Version version.unsupported
awards, CG-Version: 0.2.0          406 served=- vary=CG-Version version.unsupported
GET /versions, CG-Version: bad     200 served=- vary=- versions=0.1.0,0.2.0,0.3.0,0.4.0,0.5.0,0.6.0
```

Checks and tests:

```
$ pnpm --filter website run checks
CSpell: Files checked: 1494, Issues found: 0 in 0 files.

$ pnpm --filter website exec vitest run __tests__/lib/mock __tests__/scripts __tests__/lib/api-docs-version.spec.ts
 Test Files  25 passed (25)
      Tests  676 passed (676)
```

Swagger UI "Try it out" on the 0.1.0 spec (`GET
/common-grants/opportunities`), run locally. The request goes to `/api`
with `CG-Version: 0.1.0`:

<img width="1740" height="620" alt="swagger-0 1 0-request"
src="https://github.com/user-attachments/assets/9caae3cd-fc74-4372-b611-56b3e44c6dd7"
/>


The response is served in 0.1.0, with `Vary` and the CORS allow and
expose headers:

<img width="1740" height="626" alt="swagger-0 1 0-headers"
src="https://github.com/user-attachments/assets/932f075e-182c-4ec9-8ea4-3647392f7768"
/>

On the 0.6.0 spec the header field pre-fills from the spec example,
which #1401 now sets to 0.6.0.

---------

Co-authored-by: Bryan Thompson <bryan@snowboardtechie.com>
)

### Summary

- Fixes #1390
- Time to review: 30 minutes

Makes `cg check spec` check the version negotiation headers from ADR
0032 against the 0.6.0 spec, and adds a single clear error for APIs that
put the version in their paths. Checking that multi-version servers
publish the discovery route is out of scope, since route tags can't
express that rule.

> [!IMPORTANT]
> This targets `CORE-v0.6.0`. The bundled 0.6.0 spec is regenerated from
the latest `CORE-v0.6.0`, so it includes the version headers (#1401),
the version errors (#1414), and the versions discovery route (#1399).

### Changes proposed

- Sort protocol versions as version numbers, so 0.10.0 comes after
0.9.0:
- `lib/cli/src/commands/check/check-args.ts`: new `parseBaseVersions`
sorts with `semver` and skips file names that aren't a clean version
- `lib/cli/package.json`, `pnpm-lock.yaml`: add `semver` and
`@types/semver`
- `lib/cli/lib/openapi/openapi.0.6.0.yaml`: bundle the 0.6.0 base spec
(version headers, version errors, and the `/common-grants/versions`
discovery route), which becomes the default when no `--protocol-version`
is passed
- `lib/cli/src/commands/check/utils/check-matching-routes.ts`:
- Report a missing header parameter (such as `CG-Version`) and a missing
required response header (such as `CG-Version-Served`) as errors. Names
match regardless of case, and a header declared once on the path item
counts.
- Check headers on routes tagged `experimental` too, which still skip
the other checks
- Only treat HTTP methods on a path item as routes, so path-level
`parameters` aren't checked as a route
- `lib/cli/src/commands/check/utils/check-extra-routes.ts`: same fix, so
path-level `parameters` or `summary` aren't reported as extra routes
- `lib/cli/src/commands/check/utils/check-path-versioning.ts`: new check
that reports one error when routes put a protocol version like `v0.6`
right before or after `/common-grants/`. It only mentions `CG-Version`
when the base spec declares it, and leaves a host API's own versioning
like `/api/v2/common-grants/` alone.
- `lib/cli/src/commands/check/check-service.ts`: run the path versioning
check first and stop there if it fires, instead of listing every route
as missing
- `lib/cli/src/commands/check/utils/types.ts`, `utils/error-utils.ts`:
new error types and their labels in the output
- `lib/cli/src/commands/check/README.md`: document the header and path
versioning checks
- `lib/cli/src/__tests__/commands/check/`: unit tests for each check,
plus end-to-end tests that edit the bundled specs

### Context for reviewers

Look most closely at `check-matching-routes.ts`: header expectations
come from the base spec rather than a version check in code, which is
why checks against 0.1.0 to 0.5.0 are unchanged.

To verify:

1. Build the CLI and run its tests: `pnpm --filter @common-grants/cli
run ci`. Expect 171 passing tests. The build also regenerates the 0.1.0
to 0.5.0 specs, so run `git checkout lib/cli/lib/openapi` afterwards
(#1417 refreshes 0.4.0 and 0.5.0 separately).
2. From `lib/cli`, check the 0.5.0 spec against 0.5.0: `node
dist/index.js check spec lib/openapi/openapi.0.5.0.yaml
--protocol-version 0.5.0`. Expect `Spec is valid and compliant with base
spec`, the same as today.
3. Check the same spec with no version: `node dist/index.js check spec
lib/openapi/openapi.0.5.0.yaml`. Expect it to fail, with `Header
parameter missing` and `Response header missing` on each route, plus a
warning that the optional `GET /common-grants/versions` route is
missing, because 0.6.0 is now the default.

### Additional information

Output from the built CLI. `missing-headers.yaml` is the 0.6.0 spec with
`CG-Version` removed from one route and `CG-Version-Served` removed from
another. `versioned-paths.yaml` is the 0.6.0 spec with every route under
`/v0.6`.

```
$ cg check spec missing-headers.yaml --protocol-version 0.6.0
Validation error: Spec validation failed:
2 errors
=================================
Route conflicts
  GET /common-grants/opportunities
    1 issues found:
    Header parameter missing
      Message: Missing header parameter [CG-Version]
  GET /common-grants/opportunities/{oppId}
    1 issues found:
    Response header missing
      Status code: 200
      Message: Missing response header [CG-Version-Served] for status code [200]
```

```
$ cg check spec versioned-paths.yaml
Validation error: Spec validation failed:
1 errors
=================================
Version in path
  Routes put the protocol version in the path, such as '/v0.6/common-grants/applications/search'. Serve CommonGrants routes under '/common-grants/' with no version segment and select the version with the 'CG-Version' request header (ADR 0032).
```

```
$ pnpm --filter @common-grants/cli run ci
All matched files use Prettier code style!
Compilation completed successfully.
 Test Files  19 passed (19)
      Tests  171 passed (171)
```

Release note: the FastAPI template's CI runs `cg check spec
openapi.yaml` with no version against the published CLI. Once CLI 0.6.0
is released, that job will fail until the template adds the version
headers or pins `--protocol-version 0.5.0`.
@github-actions github-actions Bot added cli Issue or PR related to the @common-grants/cli library dependencies Pull requests that update a dependency file labels Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Issue or PR related to the @common-grants/cli library core Issues related to @common-grants/core library dependencies Pull requests that update a dependency file py-sdk Related to Python SDK python Issue or PR related to Python tooling sdk Issue or PR related to our SDKs typescript Issue or PR related to TypeScript tooling website Issues related to the website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] Add the version errors to every route [Core] Add the versions discovery route [Core] Add the version headers to every route

2 participants