Skip to content

[T-085c] Generated API client (openapi-typescript + openapi-fetch) and typed TanStack Query hooks per resource #164

Closed

Description

@CodewithJha

Task T-085c · Milestone M8 — Dashboard · Size S · Priority P0 · Epic #8

Implements FR-DSH-008 · FR-API-001

Branch feat/t-085c-generated-api-client-openapi-typescript — one task = one branch = one PR (doc 32 §6)

Summary

Generate web/src/api/schema.d.ts from api/openapi.json (pnpm gen:api), a thin fetch client with bearer token + problem+json error type, and typed hooks (useCampaigns, useCampaign, useRuns, useRun, useModes, useRiskSlice, …) whose query keys mirror API paths.

Context / motivation

Doc 13 §5: types are generated, never hand-written; CI fails if the generated file is stale.

Scope

In scope

  • web/src/api/hooks/*.ts one file per resource.
  • CI step: regenerate and git diff --exit-code.

Implementation guidance

  • pnpm gen:api → openapi-typescript ../api/openapi.json -o src/api/schema.d.ts; client via openapi-fetch (createClient<paths>({ baseUrl: config.apiBaseUrl })) with a middleware that adds Authorization: Bearer from the session token store and converts non-2xx application/problem+json into ProblemError (fields typed from the ProblemDetail schema).
  • Hooks per resource in src/api/hooks/ (campaigns.ts, runs.ts, modes.ts, risk.ts, experiments.ts, spaces.ts, workers.ts, reports.ts, meta.ts): query keys mirror API path segments, e.g. ['campaigns', id, 'runs', filters]; infinite queries for keyset pagination (getNextPageParam: p => p.next_cursor ?? undefined); mutations for commands with explicit invalidation tables.
  • Mutations sending If-Match use the ETag captured from the last GET (stored in query meta).
  • CI: pnpm gen:api && git diff --exit-code src/api/schema.d.ts in the web job.
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Configuration keys

From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).

  • apiBaseUrl / ROBOPROBE_WEB_API_BASE_URL (runtime)
  • VITE_API_BASE_URL (build-time fallback, doc 13 §5)

Acceptance criteria

  • Generated types compile under strict; stale check in CI.
  • Hooks tested against MSW handlers.
  • ProblemError exposes code, title, detail, traceId, errors[].
  • Infinite runs query fetches the next page with the cursor (MSW test).
  • Stale generated types fail CI.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • web/src/api/*.test.ts with MSW.

Dependencies

Blocked by: #13 (T-007), #158 (T-084b)

Blocks: #165 (T-085d), #177 (T-110b)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • web/src/api/**
  • web/package.json (script)

Parallel with T-085a/b.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-085c (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 13 §5 · doc 12 §1 · doc 16 §7 · doc 27 §4.11

Requirements: FR-DSH-008 · FR-API-001 (traceability: doc 28)

External:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiREST + SSE API (FastAPI)area:dashboardReact web dashboardmilestone:M8M8 — Dashboardpriority:P0Critical path / blocks otherssize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions