Skip to content

Refactor openapiMiddleware to accept multiple documents#1851

Merged
pmcelhaney merged 2 commits intomainfrom
copilot/refactor-openapi-middleware
Apr 14, 2026
Merged

Refactor openapiMiddleware to accept multiple documents#1851
pmcelhaney merged 2 commits intomainfrom
copilot/refactor-openapi-middleware

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Summary

Changes openapiMiddleware from (path, url) to an array of { path, baseUrl, id? } descriptors, enabling future multi-spec support. Single-entry arrays preserve the existing /counterfact/openapi behavior; multi-entry arrays serve each spec at /counterfact/openapi/{id}.

// Before
openapiMiddleware(config.openApiPath, `//localhost:${port}${prefix}`)

// After
openapiMiddleware([{ path: config.openApiPath, baseUrl: `//localhost:${port}${prefix}` }])

For now the call site always passes a single-item array (with id omitted).

Original Prompt

Change the signature to accept an array of objects with path, baseUrl, and id. All keys are strings.

If the array has length 1, it should respond to "/counterfact/openapi" as it does now.

Otherwise, it should respond to each of /counterfact/openapi/{id}.

For now, it will always be called with an array of 1 item and the id will be undefined.

Manual acceptance tests

  • GET /counterfact/openapi returns 200 with the OpenAPI YAML when a single spec is configured
  • Swagger UI at /counterfact/swagger still loads correctly with a single spec
  • When two descriptors are provided, GET /counterfact/openapi/spec-a and /counterfact/openapi/spec-b each return the correct spec
  • When two descriptors are provided, GET /counterfact/openapi falls through (no 200)
  • Each multi-doc response injects the correct servers[0].url for its own baseUrl
  • Routes unrelated to /counterfact/openapi are unaffected

Tasks

  • Exported OpenApiDocumentConfig interface (path, baseUrl, id?) from openapi-middleware.ts
  • Refactored openapiMiddleware to accept OpenApiDocumentConfig[]; single-entry → /counterfact/openapi, multi-entry → /counterfact/openapi/{id}
  • Updated create-koa-app.ts call site to pass a single-item array
  • Updated existing tests and added three new tests covering multi-document routing and per-doc baseUrl injection

@pmcelhaney pmcelhaney marked this pull request as ready for review April 14, 2026 00:10
Copilot AI changed the title [WIP] Refactor openApiMiddleware to accept multiple documents Refactor openapiMiddleware to accept multiple documents Apr 14, 2026
Copilot AI requested a review from pmcelhaney April 14, 2026 00:10
@pmcelhaney pmcelhaney enabled auto-merge April 14, 2026 00:12
@pmcelhaney pmcelhaney added this pull request to the merge queue Apr 14, 2026
Merged via the queue into main with commit a7cbeab Apr 14, 2026
8 of 11 checks passed
@pmcelhaney pmcelhaney deleted the copilot/refactor-openapi-middleware branch April 14, 2026 00:18
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.

Refactor openApiMiddleware to accept multiple documents

2 participants