Skip to content

feat(mockapi): add OpenAPI validation draft#35

Draft
miguelsanchez-upsun wants to merge 5 commits intomainfrom
add-openapi-validation
Draft

feat(mockapi): add OpenAPI validation draft#35
miguelsanchez-upsun wants to merge 5 commits intomainfrom
add-openapi-validation

Conversation

@miguelsanchez-upsun
Copy link
Collaborator

@miguelsanchez-upsun miguelsanchez-upsun commented Mar 24, 2026

Add infrastructure to validate mock API responses against the official
Upsun OpenAPI specification with automatic spec download:

  • OpenAPI validation middleware with route matching and schema validation
  • Automatic spec download from developer.upsun.com on first use
  • Fix localhost server URL handling (remove spec servers section)
  • Add Content-Type: application/json header to all mock responses
  • Add Makefile targets for manual spec download/update
  • Add comprehensive tests and documentation

The validation middleware can be enabled with VALIDATE_OPENAPI=1 to catch
discrepancies between mock responses and the real API specification.

Environment variables:

Usage:

   make download-openapi              # Download/update OpenAPI spec           
   VALIDATE_OPENAPI=1 go test ./...   # Run tests with validation        

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

miguelsanchez-upsun and others added 5 commits March 24, 2026 22:44
… path

Remove automatic OpenAPI spec download functionality from test runtime.
Spec will now be downloaded via Makefile only.

Changes:
- Delete openapi_download.go and openapi_download_test.go (~200 lines)
- Update loadOpenAPISpec() to use fixed path: pkg/mockapi/testdata/upsun-openapi.json
- Remove ensureOpenAPISpec() path-hunting logic
- Validation gracefully disables when spec missing (shows warning)

Part of CLI-124: OpenAPI validation implementation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Update Makefile to automatically download OpenAPI spec as dependency
of integration tests. Add module root resolution for reliable path
handling across different test contexts.

Changes:
- Add pkg/mockapi/testdata/upsun-openapi.json file target in Makefile
- Make integration-test depend on spec file (downloads if missing)
- Add findModuleRoot() to locate spec from any test working directory
- Works from both pkg/mockapi tests and integration-tests

Part of CLI-124: OpenAPI validation implementation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add explicit step to download OpenAPI specification before running
integration tests. Spec downloads once per CI run (no caching).

Part of CLI-124: OpenAPI validation implementation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant