Skip to content

[Enhancement] Add contract tests for the API layer against the OpenAPI specification #1008

Description

@RUKAYAT-CODER

Overview

package.json exposes validate:openapinode scripts/validateOpenApi.js, and src/types/api/schemas.ts plus src/services/api/validation.ts exist for runtime validation — but no workflow runs the validation script, and there is no test asserting that the TypeScript types in src/types/ match the specification. The 409 handler in axios.config.ts has a runtime shape guard precisely because the server contract is not otherwise enforced, which is the symptom of a missing contract test.

Specifications

Features:

  • The OpenAPI specification validated in CI
  • Generated or asserted types kept in sync with the specification
  • Response validation applied at the client boundary for critical endpoints

Tasks:

  • Add npm run validate:openapi as a CI step
  • Generate types from the specification, or add a test asserting the hand-written types match it
  • Apply the src/services/api/validation.ts guards to auth, payment and sync responses
  • Extend src/services/api/__tests__/validation.test.ts with contract fixtures

Impacted Files:

  • scripts/validateOpenApi.js
  • src/types/api/schemas.ts
  • src/services/api/validation.ts
  • .github/workflows/ci.yml

Acceptance Criteria

  • A specification change that breaks the client fails CI
  • Critical responses are validated at runtime
  • Types and specification cannot silently diverge

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions