Skip to content

Smoke Test Finding F2: Support Top-Level (Non-Collection-Scoped) Resource URLs #35

Closed

Description

@Sam-Bolling

Task

Support top-level (non-collection-scoped) resource URL patterns in url_builder.ts and endpoint.ts, so the builder can construct correct URLs for servers that expose CSAPI resources at the API root (e.g., /api/systems) rather than under a collection path (e.g., /collections/{id}/systems).

Origin: Live server smoke test (post Phase 2.1) — Finding F2
Smoke Test Report: docs/implementation/live-server-smoke-test-post-phase-2.1.md


Context — What We Found

Our builder assumes resources are scoped under a collection's self URL: {collectionSelfUrl}/{resourceType}. When tested against OpenSensorHub, we found:

  • The server's root document has absolute URLs for each resource: href: "http://server/sensorhub/api/systems"
  • The server's collection documents have self links pointing to /collections (the collection list), not to the individual collection
  • Resources live at the API root (e.g., /sensorhub/api/systems), not under a collection path

Result: Our builder constructs http://server/sensorhub/api/collections/systems instead of http://server/sensorhub/api/systems.

Both patterns (collection-scoped and top-level) are valid per the OGC spec. We need to support both.

Files to Create or Modify

File Action Est. Lines Purpose
src/ogc-api/csapi/url_builder.ts Modify ~20–40 changed Update extractBaseUrl() and buildResourceUrl() to support top-level URL patterns; optionally accept a resource URL map
src/ogc-api/csapi/url_builder.spec.ts Modify ~30–40 added Add tests for top-level URL pattern, mixed patterns, correct URL generation
src/ogc-api/endpoint.ts Modify ~10–20 changed Update csapi() factory to pass root document resource URLs to the builder when available

Blueprint Reference

The existing extractBaseUrl() and buildResourceUrl() methods in url_builder.ts (current collection-scoped implementation). The csapi() factory in endpoint.ts (current implementation passes only the collection document). The EDR pattern in endpoint.ts for how edr() creates its builder.

Scope — What to Implement

Builder: Support Resource URL Map

When the builder receives absolute resource URLs (from the root document), it should use them directly instead of computing paths relative to a collection self link.

Approach options (implementer should choose the simplest):

Option A — Constructor accepts optional resource URL map:

constructor(collection: OgcApiCollectionInfo, resourceUrls?: Map<string, string>)

When resourceUrls is provided (e.g., { systems: "http://server/api/systems" }), buildResourceUrl uses those absolute URLs as the base. When not provided, falls back to current collection-scoped behavior.

Option B — extractBaseUrl() checks for root-level self link:
If the collection's self link points to /collections (the list, not an individual collection), infer that resources are at the API root and adjust the base URL accordingly.

Either approach is acceptable. Existing collection-scoped behavior MUST be preserved for backwards compatibility.

Endpoint: Pass Resource URLs from Root Document

The csapi() factory in endpoint.ts already fetches the collection document. It should also examine the root API document's links (which are already available via this.data) for absolute resource URLs and pass them to the builder if found.

JSDoc Requirements

  • Update JSDoc on extractBaseUrl() and/or the constructor to document both URL patterns
  • Document the new parameter if Option A is chosen
  • Add @see links to OGC CSAPI Part 1 specification sections for resource URL patterns
  • Follow the JSDoc style already established in url_builder.ts and endpoint.ts

Testing Requirements

  • Extend src/ogc-api/csapi/url_builder.spec.ts (~30–40 lines)
  • Test: builder with collection-scoped self link still produces correct URLs (regression)
  • Test: builder with top-level resource URL map produces correct URLs (e.g., getSystems() → http://server/api/systems)
  • Test: top-level getSystem('sys-001') appends ID correctly (e.g., http://server/api/systems/sys-001)
  • Test: top-level navigation methods append sub-paths correctly (e.g., getSystemSubsystems('sys-001') → http://server/api/systems/sys-001/subsystems)
  • Test: query parameters work correctly with top-level URLs
  • Follow test patterns from existing url_builder.spec.ts

Scope — What NOT to Touch

  • ❌ Do NOT modify extractAvailableResources() — link relation parsing belongs to Issue Smoke Test Finding F1: Support Multiple Link Relation Conventions for Resource Discovery #34 (F1)
  • ❌ Do NOT modify model.ts or helpers.ts — those are stable
  • ❌ Do NOT implement response parsing — that belongs to Phase 3
  • ❌ Do NOT add authentication/header support to the endpoint — that is a separate concern
  • ❌ Do NOT modify any Systems method signatures — they remain unchanged
  • ❌ 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

  • Builder produces correct URLs for collection-scoped patterns (no regression)
  • Builder produces correct URLs for top-level patterns when given resource URLs
  • All 12 Systems methods work correctly with both patterns (including ID encoding, sub-paths, query parameters)
  • endpoint.ts csapi() factory passes root document resource URLs to the builder when available
  • Existing tests still pass (npm test)
  • New tests verify both URL patterns
  • All new code has complete JSDoc documentation
  • No lint errors
  • No TypeScript errors

Dependencies

Blocked by: Issue #34 (F1 — resource discovery must work before URL construction matters)
Blocks: Issue #6 (Deployments Methods), Issue #7 (Procedures Methods), Issue #8 (Sampling Features Methods), Issue #9 (Properties Methods), and all subsequent Phase 2 resource-type tasks.


Operational Constraints

⚠️ MANDATORY: Before starting work on this issue, review docs/governance/AI_OPERATIONAL_CONSTRAINTS.md.

Key constraints for this task:

  • Precedence: OGC specifications → AI Collaboration Agreement → This issue description → Existing code → Conversational context
  • No scope expansion: Do not infer unstated requirements or add unrequested features
  • No refactoring: Do not rename, restructure, or "improve" code outside this issue's scope
  • Minimal diffs: Prefer the smallest change that satisfies the acceptance criteria
  • Ask when unclear: If intent is ambiguous, stop and ask for clarification

References

Read these documents before starting implementation. They are ordered by priority.

Primary References (must read)

# Document Section/Lines What It Provides
1 docs/implementation/live-server-smoke-test-post-phase-2.1.md Finding F2 Full description of the URL pattern mismatch with real server data
2 src/ogc-api/csapi/url_builder.ts extractBaseUrl() and buildResourceUrl() methods Current implementation to modify
3 src/ogc-api/endpoint.ts csapi() factory method (lines ~329–345) Current endpoint integration to modify
4 src/ogc-api/csapi/url_builder.spec.ts Full file Existing test patterns to follow

Upstream Type/Import References (files this task imports from)

# Document What to Import
5 src/ogc-api/model.ts OgcApiCollectionInfo (already imported)

Research References (context, not required reading)

# Document What It Provides
6 docs/implementation/live-server-smoke-test-post-phase-2.1.md Full smoke test results with server URL patterns
7 docs/implementation/phase-2.1-overview.md Current state of the builder architecture

Specification References (for @see links and field accuracy)

# Document Use
8 OGC API - Connected Systems Part 1 (23-001) Resource URL patterns — collection-scoped vs. top-level
9 OGC API - Common Part 2 Collection document structure, self links

Convention Quick Reference

Rule Example
Use .js extension for relative imports import { X } from './file.js'
Use import type for interfaces/types import type { Y } from './model.js'
Three-tier hierarchy: import from lower tiers only shared → ogc-api → csapi
Named exports for types and utilities export interface Z { ... }
as const arrays for enum-like values export const XTypes = [...] as const
HTTP mocking: globalThis.fetch = jest.fn() Never use nock, msw, or other libraries
Meaningful tests only Verify behavior, not that code runs without throwing

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions