Skip to content

feat(core): add the versions discovery route - #1399

Merged
SnowboardTechie merged 6 commits into
CORE-v0.6.0from
bryan/1387-versions-discovery
Nov 20, 2026
Merged

SnowboardTechie merged 6 commits into
CORE-v0.6.0from
bryan/1387-versions-discovery

Conversation

@SnowboardTechie

@SnowboardTechie SnowboardTechie commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

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 (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 feat(core): add the version negotiation headers to every route #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 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):

{
  "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 linked an issue Nov 9, 2026 that may be closed by this pull request
4 tasks done
@karinamzalez

Copy link
Copy Markdown
Collaborator

@SnowboardTechie heads up from #1401 (version headers for #1386), which also targets CORE-v0.6.0:

  • Stubs: feat(core): add the version negotiation headers to every route #1401 adds Versions.v0_6 and Types.protocolVersion, so you can drop yours when you rebase. One difference: the pattern uses [0-9] instead of \d, because Python's \d matches non-ASCII digits.
  • Discovery 200: feat(core): add the version negotiation headers to every route #1401 spreads CG-Version-Served, Vary, Deprecation, Sunset and Link into OkT, so ProtocolVersions.read will pick them up. ADR 0032 says discovery carries neither CG-Version-Served nor Vary, so it needs its own 200 model without ...Headers.VersionResponse (the fallback you mentioned in the description).
  • Versioning gotcha: put @added(v0_6) on each property you spread, not only on the model. Spreading drops model-level versioning, and the headers leaked into 0.1.0 to 0.5.0 until I moved it.

karinamzalez added a commit that referenced this pull request Nov 16, 2026
`test_core_baseline_is_v0_5` asserts that no v0.6+ OpenAPI document exists,
so emitting openapi.0.6.0.yaml fails the Python SDK build. Rename it to
`test_core_baseline_is_v0_6` and bump both assertions. The change is
byte-identical to the one in #1399, so the two branches merge cleanly.

Refs #1386

Files changed:
- lib/python-sdk/tests/schemas/test_award_inventory.py
karinamzalez added a commit that referenced this pull request Nov 18, 2026
### 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
```
@SnowboardTechie
SnowboardTechie force-pushed the bryan/1387-versions-discovery branch from 4f0a3b8 to cc51eb4 Compare November 18, 2026 16:39
@github-actions github-actions Bot added website Issues related to the website core Issues related to @common-grants/core library typescript Issue or PR related to TypeScript tooling labels Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Website Preview Deployed!

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

Built from commit 3df872f

@SnowboardTechie
SnowboardTechie marked this pull request as ready for review November 18, 2026 17:32
@SnowboardTechie

Copy link
Copy Markdown
Collaborator Author

Thanks for the heads up on these, they made the rebase quick. This is rebased onto CORE-v0.6.0 now that your headers PR is in:

  • Stubs: dropped, so Versions.v0_6 and Types.protocolVersion come from yours.
  • Discovery 200: the route returns its own VersionDiscoveryResponse without ...Headers.VersionResponse, so the 0.6.0 document shows no CG-Version-Served or Vary on it.
  • Versioning gotcha: nothing is spread into the route now, so it doesn't come up here.

Ready for review when time allows.

@karinamzalez karinamzalez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with some questions and comments!

deprecation: utcDateTime;

/** When the server will stop serving the version, if scheduled */
sunset?: utcDateTime;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sunset optional vs. ADR wording: ADR line 34 describes deprecated versions "with their deprecation and sunset dates", but sunset is optional here ("if scheduled"). Is deprecated-without-a-sunset an intended state? If it is, maybe a short line in the ADR's "What goes in discovery" section so the two agree?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this, yes it's intentional. A server can deprecate a version before it knows when it'll turn it off, and the ADR plans for that: responses served in a retiring version send Deprecation right away and add Sunset "once a date is set" (lines 726 and 778). Discovery follows the headers, so sunset stays optional until the server picks a date. Requiring it would push a server to either make up a date or hold off on announcing the deprecation, and holding off is worse for clients since the early warning is the point. You're right that line 34 reads like both dates are always there though. I'll fix that wording in #1389 along with the rest of the versioning docs.

*
* Each key is a full protocol version listed in `versions`, matched on major and minor.
*/
deprecated?: Record<VersionRetirement>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDK follow-up (non-blocking): Is there a ticket for adding these four types to the SDKs (Zod in lib/ts-sdk, Pydantic in the Python SDK)? I couldn't find one linked from #1387. Discovery is probably the first thing an SDK user will call in 0.6.0, so I think a typed VersionDiscovery would be really handy!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, there wasn't one. I opened #1425 for the Zod schemas in the TS SDK and #1426 for the Pydantic models in the Python SDK, both under the versioning epic in each SDK's v0.10.0 milestone.

*
* Each key is a full protocol version listed in `versions`, matched on major and minor.
*/
deprecated?: Record<VersionRetirement>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarifying the deprecated key rule (minor): "Each key is a full protocol version listed in versions, matched on major and minor" took me a couple of reads. Does "matched on major and minor" mean that 0.3.1 in versions and a 0.3.0 key refer to the same version? Same text at line 97.

Maybe: "Each key is a full version such as 0.3.0. It refers to the entry in versions with the same major and minor."

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this, the wording mashed two rules together. The key is always the exact string from versions, so a server hosting 0.3.1 keys it 0.3.1, never 0.3.0. "Matched on major and minor" was about the client side: a client that asks for 0.3.0 gets served 0.3.1, so it has to compare major and minor to find its entry. I split those into two paragraphs with an example in 3df872f.

@Versioning.added(CommonGrants.Versions.v0_6)
model UpcomingDefault {
/** The version that will become the default */
version: Types.protocolVersion;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upcoming default must be listed (minor): defaultVersion says "one of versions", but UpcomingDefault.version doesn't, even though ADR line 607 says "A default is always one of the versions it applies to." Worth adding the same clause here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added in d9e532d. I put it on the upcomingDefault field in both models, since that's where versions is in scope.

*
* Each key is a full protocol version listed in `versions`, matched on major and minor.
*/
deprecated?: Record<VersionRetirement>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validating deprecated keys (non-blocking): The keys of deprecated aren't checked against the version format, so a malformed key like "v0.3" still passes validation.

We could add propertyNames: { $ref: protocolVersion.yaml } to the JSON Schema to catch this. OpenAPI 3.0 has no equivalent, so the check would only apply to the JSON Schema files. If the TypeSpec emitter makes that awkward, keeping it as a documented rule is fine too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added in d9e532d. @JsonSchema.extension puts propertyNames: { $ref: protocolVersion.yaml } on both deprecated fields, and the OpenAPI doc only gets the description change. I checked it against the generated schemas: 0.3.0 passes, and v0.3 and 0.5 fail.

karinamzalez added a commit that referenced this pull request Nov 19, 2026
### 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.
```
Adds GET /common-grants/versions to the 0.6.0 base API, tagged optional,
with the VersionDiscovery, OperationVersions, UpcomingDefault and
VersionRetirement models and a protocolVersion type. The route lets a
server publish its default version, the versions every route serves,
per-route exceptions, an upcoming default and deprecated versions, per
the API version negotiation ADR draft (#1159, #1372).

Versions.v0_6 and Types.protocolVersion are stubs owned by #1386 and
are dropped when that PR lands. The 0.1.0 through 0.5.0 OpenAPI
documents are unchanged.

Refs #1387
Discovery sits outside version selection, so its models tolerate
fields they don't know instead of being versioned per document, as
the route description promises. The baseline fields now say they
describe routes without an operations entry, versions requires at
least one entry, and the deprecated map documents its keys.

Refs #1387
OkT now spreads the version response headers, so discovery would have
advertised CG-Version-Served and Vary. ADR 0032 says discovery carries
neither, because clients call it before they know which version to
request. The route returns a dedicated VersionDiscoveryResponse instead.

Refs #1387
The defaultVersion docs now say a default is one of the listed
versions, which the schema can't express. The route description adds
the ADR's authentication ceiling and narrows "fields are only ever
added" to data, since the response envelope stays closed. The
interface comment says adopters don't type-parameterize the response,
now that the models accept unknown fields.

Refs #1387
Validate each key of `deprecated` against the protocol version format in the
JSON Schema files, and say that an upcoming default is one of `versions`, as
ADR 0032 requires of every default.
A key is written exactly as its version appears in `versions`. Matching on
major and minor is how a client finds the entry for the version it requested,
so say that separately, with an example.
@SnowboardTechie
SnowboardTechie force-pushed the bryan/1387-versions-discovery branch from 3527f5d to 3df872f Compare November 20, 2026 16:53
@SnowboardTechie
SnowboardTechie merged commit e2f68fa into CORE-v0.6.0 Nov 20, 2026
10 checks passed
@SnowboardTechie
SnowboardTechie deleted the bryan/1387-versions-discovery branch November 20, 2026 17:13
karinamzalez added a commit that referenced this pull request Nov 20, 2026
…covery route

Picks up #1414 (version errors) and #1399 (versions discovery route) from CORE-v0.6.0.

Files changed:
- lib/cli/lib/openapi/openapi.0.6.0.yaml
karinamzalez added a commit that referenced this pull request Nov 20, 2026
)

### 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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues related to @common-grants/core library 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 versions discovery route

2 participants