Skip to content

feat: add OpenAPI-based contract tests between FastAPI and Next.js#416

Open
Xenon010101 wants to merge 1 commit into
MRIARC-08:mainfrom
Xenon010101:fix/openapi-contract-tests
Open

feat: add OpenAPI-based contract tests between FastAPI and Next.js#416
Xenon010101 wants to merge 1 commit into
MRIARC-08:mainfrom
Xenon010101:fix/openapi-contract-tests

Conversation

@Xenon010101

Copy link
Copy Markdown

Closes #367

Summary

Adds OpenAPI-based contract tests between the Next.js TypeScript client and the FastAPI AI backend, enabling automated cross-service compatibility detection in CI.

What's included

Python: OpenAPI export script

  • Exports the FastAPI OpenAPI schema to JSON at services/ai/scripts/export-openapi.py
  • Works without PostgreSQL, model downloads, or Groq (dummy env vars)
  • Run: python scripts/export-openapi.py

Golden baseline

  • services/ai/openapi.golden.json — committed reference spec for breaking change detection
  • Updated with pnpm contract:update-golden

TypeScript: Contract tests

  • src/__tests__/contract.test.ts validates:
    • All expected path/method combinations exist
    • Response schemas and status codes match golden spec
    • Auth headers (X-Internal-API-Key) are correctly applied to internal routes
    • Error response schemas (HTTPValidationError, ValidationError) are present
    • Detects removed paths, methods, response statuses, and component schemas
    • Enum values match TypeScript expectations
    • Idempotency headers on write endpoints

CI workflow update

  • New contract-test job runs after the ai-service job
  • Exports OpenAPI spec during the ai-service job
  • Contract tests run without PostgreSQL, model downloads, or Groq
  • pnpm test:contract script for local runs

Documentation

  • "OpenAPI Contract" section in services/ai/README.md
  • Documents one-command regeneration and contract update workflow
  • Explains versioning policy for breaking changes

- Python export script (scripts/export-openapi.py) generates FastAPI
  OpenAPI schema without DB, model downloads, or Groq
- Golden spec (openapi.golden.json) as committed baseline
- TypeScript contract tests (src/__tests__/contract.test.ts) validate:
  - All expected path/method combinations exist
  - Response schemas and status codes match golden spec
  - Auth headers (X-Internal-API-Key) are correctly applied
  - Error response schemas (HTTPValidationError, ValidationError)
  - Enum values match TypeScript expectations
  - Breaking path/field/nullability changes are detected
- CI job exports spec from FastAPI and runs contract tests
- One-command regeneration: pnpm contract:update-golden
- Documentation in services/ai/README.md
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

@Xenon010101 is attempting to deploy a commit to the Adarsh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@MRIARC-08 MRIARC-08 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xenon010101 I like the direction, but this contract-test PR is not ready yet. It currently fails the local Node checks.

Local checks:

  • pnpm test src/__tests__/contract.test.ts fails because services/ai/openapi.json is missing. The test should either generate it as part of the script, read the committed golden spec for local runs, or document/use a script that creates it before running the test.
  • pnpm exec eslint src/__tests__/contract.test.ts fails on explicit any types and an unused path variable.
  • pnpm exec tsc --noEmit fails: missing beforeAll import, OpenApiSpec.security is not typed, spec is used outside its scope in the idempotency suite, and pathItem is unknown.

Please make pnpm test:contract work from a clean checkout and then rerun lint/typecheck.

@MRIARC-08 MRIARC-08 added gssoc gssoc level:intermediate GSSoC difficulty: intermediate type:testing Testing related contribution area:ai-backend Python AI service, embeddings, retrieval, and LLM infrastructure labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai-backend Python AI service, embeddings, retrieval, and LLM infrastructure gssoc gssoc level:intermediate GSSoC difficulty: intermediate type:testing Testing related contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TESTING][AI BACKEND] Add OpenAPI-based Next.js and FastAPI contract tests

2 participants