Skip to content

[Core] Add identifiers to the opportunity model and OppRef #1219

Closed

Description

@laurabelinfante

Summary

OppRef carries only id and title, while OrgRef and AwdRef expose typed identifier collections. The awards reference implementation joins USASpending awards to Grants.gov opportunities on the funding opportunity number but cannot publish that number on award.opportunity; this is the v0.5 opportunity-model gap deferred from v0.4.

Add OppIdFon is IdentifierT<string, "opp:us:fon">, OppIdAln is IdentifierT<string, "opp:us:aln">, and OppIds extends IdentifierCollection. Add versioned identifiers?: OppIds to OppRef; OpportunityBase receives the property through its existing ...OppRef spread and must not redeclare it. The registry catalog already contains both codes, so this ticket checks consistency rather than creating duplicate registry entries.

The TS and Python v0.9 opportunity-alignment tickets own the official SDK OpportunityBase changes. The award-schema tickets own the shared OppRef identifier closure once because AwardBase.opportunity reaches it. Identifier lookup on GET /opportunities remains the separate, unimplemented ADR 0023 requirement.

Acceptance criteria

  • OppIdFon, OppIdAln, and OppIds exist with @Versioning.added(v0_5), and OppRef.identifiers?: OppIds is added once and inherited by OpportunityBase
  • The typed keys, embedded registry codes, links, examples, and existing catalog entries for opp:us:fon and opp:us:aln agree
  • Generated v0.4 artifacts remain unchanged; v0.5 OpenAPI and JSON Schema artifacts expose the typed identifier models and inherited field
  • Examples or fixtures exercise both base registry keys, and website model documentation plus the changelog describe the field
  • Validation pass: before merging to the hold branch, draft the new models in Zod and Pydantic to catch design issues early (not merged, just a check)
  • cg-usaspending can emit opportunity.identifiers and validate against the v0.5 bundle with OPPORTUNITY_IDENTIFIERS=include

Activity

  1. added
    coreIssues related to @common-grants/core library
    sdkIssue or PR related to our SDKs
    featureNew capability. Belongs on a hold branch.
    on Sep 23, 2026
  2. karinamzalez commented on Oct 1, 2026

    @karinamzalez
    Collaborator

    T5: Zod and Pydantic validation pass for OppIds

    Scratch branch karina/1219-sdk-validation-pass (nothing merges; the code exists so the findings are reviewable). Full write-up in 1219-T5-FINDINGS.md on that branch.

    Zod: the shapes express cleanly. One identifierT(code, id) factory covers Identifier, SystemId, OppIdFon, and OppIdAln, with IdentifierCollection, OppIds, and OppRef on top. The parity harness passes on all eight schemas with two understood divergences: the ADR 0024 nullish gap (#1192), and IdentifierCollection, which the protocol leaves open but the harness force-seals with .strict(), so no open protocol schema can currently be matched. That second one is a harness limitation worth its own issue. Colon-bearing keys and allOf flattening via .extend() both work, the latter only because the sealed collection is the sole sealing subschema.

    Pydantic: datamodel-codegen loses three protocol guarantees.

    1. otherIds validates and then silently discards every extension identifier: Record<Identifier> emits as unevaluatedProperties over empty properties, which the generator renders as a bare model. This is data loss and is protocol-wide for every Record<T>; emitting additionalProperties instead would fix it.
    2. Sealed objects are not sealed: unevaluatedProperties: {not: {}} survives only as inert json_schema_extra. Needs an extra="forbid" decision on CommonGrantsBaseModel.
    3. An optional const registry.code becomes a required field with a default, so the model invents a code the producer never sent.

    Colon-keyed aliases (Field(alias="opp:us:fon")) work as-is through the camelCase alias generator, which answers the ticket's open question.

    Also found: T1 left lib/ts-sdk red. OpportunityBaseSchema lacked the identifiers field that OpportunityBase now inherits, and the ts-sdk workflow is path-filtered to lib/ts-sdk/**, so the core change never ran the suite that it broke. Fixed in #1250: the field is accepted permissively with the divergence tracked against #1156, and the workflow now also triggers on lib/core/**.

    Python SDK gates could not be run on this machine (no Poetry, no Python 3.11+), so the Pydantic draft is unlinted.

  3. karinamzalez commented on Oct 1, 2026

    @karinamzalez
    Collaborator

    T6: cg-usaspending validates clean against the v0.5 schemas

    Ran agilesix/cg-usaspending at 2ec4e9e against the v0.5 bundle from 2b0ac7a (website/public/schemas/yaml), using the tracked snapshots (no live API calls):

    OPPORTUNITY_IDENTIFIERS=include AS_OF=2026-08-14 \
    CG_SCHEMA_DIR=<repo>/website/public/schemas/yaml pnpm build:awards
    

    Result: 84 records, 0 validation failures, 0 known-gap records at /opportunity/identifiers. Every record carries systemId, opp:us:fon, and opp:us:aln, so the new fields are exercised rather than absent. The same output against the vendored v0.4 bundle reports 84 known-gap records, one per record, so the schema is the only variable.

    Where opp:grants.gov:system lands: under systemId.registry.code (src/transform/award.ts:235), not as a top-level key. A top-level key would fail (unevaluatedProperties), which I confirmed by mutating a record; wrong registry constants and unknown top-level keys are rejected too, while the same key under otherIds passes. OPPORTUNITY_IDENTIFIERS=omit also validates, since the field is optional.

    No producer-side change is needed. Once v0.5 ships, cg-usaspending can drop the opportunityIdentifiers switch and the /opportunity/identifiers known-gap plumbing (src/config.ts:59-69, src/index.ts:40-62). Happy to open that issue if wanted.

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

Metadata

Metadata

Assignees

Labels

coreIssues related to @common-grants/core libraryfeatureNew capability. Belongs on a hold branch.sdkIssue or PR related to our SDKs

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions