Skip to content

parseResourceRef() should normalize type to rt for OSH @link objects (P5-F5) #114

Closed

Description

@Sam-Bolling

Task

Normalize the type field from OSH @link objects to the rt property on CSAPIResourceRef, so the media type string is not silently dropped.

Finding Reference: P5-F5 from Smoke Test #23
Severity: Low
Category: Parser / Model alignment
Ownership: Ours


Problem Statement

parseResourceRef() in geojson.ts reads raw.rt to populate the CSAPIResourceRef.rt field. However, OSH @link objects use type (per OGC API / RFC 8288 link conventions), not rt. This causes the media type string to be silently dropped during extraction.

Evidence:

OSH system@link on a datastream detail response:

{
  "system@link": {
    "href": "http://45.55.99.236:8080/sensorhub/api/systems/03bc5ofvvstg?f=json",
    "uid": "urn:osh:driver:mavsdk:cube:replay",
    "type": "application/geo+json"
  }
}

Current parseResourceRef() code:

function parseResourceRef(raw: Record<string, unknown>): CSAPIResourceRef {
  return {
    href: String(raw.href),
    ...(typeof raw.uid === 'string' ? { uid: raw.uid } : {}),
    ...(typeof raw.title === 'string' ? { title: raw.title } : {}),
    ...(typeof raw.rt === 'string' ? { rt: raw.rt } : {}),
  };
}

The type: "application/geo+json" field is present in the raw JSON but parseResourceRef() only checks raw.rt. Since OSH sends type, the media type is silently lost.

Impact: CSAPIResourceRef.rt is always undefined for OSH @link objects. The href and uid fields are unaffected. This affects all 4 @link extraction paths in extractCSAPIFeature() (systemKind, platform, deployedSystems, sampledFeature) and would affect Part 2 @link extraction when Issue #110 is implemented.

Files to Create or Modify

File Action Est. Lines Purpose
src/ogc-api/csapi/formats/geojson.ts Modify ~1 Add type → rt fallback in parseResourceRef()
src/ogc-api/csapi/formats/geojson.spec.ts Modify ~10 Add test for type input normalized to rt output

Proposed Fix

Add raw.type as a fallback when raw.rt is not present:

...(typeof raw.rt === 'string'
  ? { rt: raw.rt }
  : typeof raw.type === 'string'
    ? { rt: raw.type }
    : {}),

This follows Postel's Law — accept type on the wire, normalize to rt in the model. If rt is already present (spec-ideal), it takes precedence. If only type is present (OSH behavior), it is mapped to rt.

Scope — What NOT to Touch

  • ❌ Do NOT modify CSAPIResourceRef interface in model.ts — the model property stays as rt
  • ❌ Do NOT add a type alias property to the interface — normalization happens at parse time
  • ❌ Do NOT modify Part 2 parsers (part2.ts) — they don't extract @link objects yet (Issue DEFERRED — No @link / @id resolution utilities for cross-resource reference following #110)
  • ❌ Do NOT modify files outside the "Files to Create or Modify" table above
  • ❌ Do NOT refactor existing code unless required to complete this task

Acceptance Criteria

  • parseResourceRef() normalizes type to rt when rt is absent
  • rt takes precedence over type if both are present
  • Test case: @link with type only → rt populated in output
  • Existing tests still pass (npm test)
  • tsc --noEmit produces 0 errors

Dependencies

Blocked by: Nothing
Blocks: Issue #110 (DEFERRED — @link resolution utilities) — when that issue is implemented, it will benefit from rt being correctly populated


Operational Constraints

⚠️ MANDATORY: Before starting work on this issue, review docs/governance/AI_OPERATIONAL_CONSTRAINTS.md and docs/implementation/server-quirks-reference.md.

Key constraints:

  • Precedence: OGC specifications → AI Collaboration Agreement → This issue description → Existing code → Conversational context
  • No scope expansion: Fix the finding, nothing more
  • No server-specific branches: Fixes must be general-purpose, not "if OSH" / "if 52N"
  • Minimal diffs: Prefer the smallest change that satisfies the acceptance criteria
  • Verify against live server: The acceptance criteria should include a live-server verification step where applicable

References

# Document What It Provides
1 Smoke Test #23 P5-F5 finding evidence and context
2 docs/governance/known-server-quirks.md Server behavior patterns
3 src/ogc-api/csapi/formats/geojson.ts (lines 406–416) Code containing parseResourceRef()
4 src/ogc-api/csapi/model.ts (lines 116–128) CSAPIResourceRef interface definition
5 OGC API - Connected Systems Part 1 (23-001) §16 JSON encoding for Part 1 resources, @link conventions

Activity

  1. added
    bug
    on Feb 21, 2026
  2. Sam-Bolling commented on Feb 21, 2026

    @Sam-Bolling
    Author

    Scoping Discussion

    Question (@sbolling):

    Is there anything about the new finding that we might consider potentially fixable and arguably in scope for and inline with the intent of our CSAPI client library contribution project?

    Response:

    Yes. P5-F5 is a small, targeted parser alignment fix — exactly the same class of work as F46 (one-word type change) and squarely within the @link extraction scope established by Issues #108/#109. The argument:

    1. It's a one-line parser fix — add raw.type as a fallback in parseResourceRef().

    2. It directly extends Issue Part 1 extractCSAPIFeature() silently drops all @link properties during parsing #109 work — that issue added @link extraction with the explicit goal of parsing OSH/52N @link objects faithfully. Dropping the media type field defeats part of that purpose.

    3. The spec supports it — OGC API link objects use type for media type (per RFC 8288 / OGC API-Common). Our model chose rt ("resource type") as the property name, but the wire format uses type. The parser's job is to bridge that gap — which it already does for href, uid, and title.

    4. It follows Postel's Law — the same design principle every other parser in this library follows. Accept type on the wire, normalize to rt in the model.

    5. Existing tests use rt in fixtures — they'd need one additional test case with type on input and rt on output, confirming the normalization.

    The fix is: one line in parseResourceRef(), one new test case, zero model changes. Same scale as F46.

  3. added a commit that references this issue on Feb 21, 2026
  4. Sam-Bolling commented on Feb 21, 2026

    @Sam-Bolling
    Author

    Live Server Validation — P5-F5 Fix Confirmed

    Ran a targeted test against OSH (http://45.55.99.236:8080/sensorhub/api) to validate the type → rt normalization.

    Test: Fetched GET /datastreams/03tbj7mvqg50 and inspected the system@link object.

    Raw @link from OSH:

    {
      "href": "http://45.55.99.236:8080/sensorhub/api/systems/03bc5ofvvstg?f=json",
      "uid": "urn:osh:driver:mavsdk:cube:replay",
      "type": "application/geo+json"
    }
    • Has type: ✅ "application/geo+json"
    • Has rt: ❌ (absent)

    Result: parseResourceRef() fallback resolves rt = "application/geo+json" from type.

    Verdict: ✅ PASS — media type string is no longer silently dropped. Commit 4379cdd.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Phase 5bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions