feat: add OpenAPI Overlays support#2059
Conversation
pmcelhaney
left a comment
There was a problem hiding this comment.
Add some example overlays to fixtures.
pmcelhaney
left a comment
There was a problem hiding this comment.
Add a black box test
Done in 5532344. Added three overlay fixtures under
Each fixture is exercised by a new test in |
Done in 0ca5b36. Added two black box tests to
|
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: pmcelhaney <51504+pmcelhaney@users.noreply.github.com>
|
@copilot http://localhost/counterfact/openapi does not show the overlay changes applied. Make sure the overlay changes are applied everywhere. Add tests to lock in the changes. |
Fixed in 44b2547. The root cause was that Changes:
|
|
@copilot the unit tests are failing on Windows |
Head branch was pushed to by a user without write access
Fixed in 2e8bd27. The root cause was Changed to |
Summary
Adds support for OpenAPI Overlays v1.0.0 — a mechanism to apply targeted patches to an OpenAPI document without modifying the original file.
New CLI flag (repeatable, applied in order):
Overlay file format (
my-overlay.yaml):Per-spec overlays in
counterfact.yaml:Overlays are applied in the code-generation pipeline (
Specification.fromFile), the runtime server pipeline (OpenApiDocument.load), and the/counterfact/openapiendpoint (the raw spec served to Swagger UI).deepMergeis guarded against prototype pollution.Original Prompt
Add support for OpenAPI Overlays v1.0.0 — a mechanism to apply targeted patches to an OpenAPI document without modifying the original file. Expose a repeatable
--overlay <path>CLI flag and support per-specoverlaysentries incounterfact.yaml.Manual acceptance tests
counterfact openapi.yaml ./out --overlay overlay.yamlapplies the overlay'supdateaction (e.g. changesinfo.title) before generating route stubsremoveaction suppresses route stub generation for the removed pathoverlays:in acounterfact.yamlspec entry are applied on startup--overlaymultiple times applies each file in the order givenGET /counterfact/openapireturns the overlay-patched spec (e.g. updatedinfo.titleand removed paths are absent)Tasks
src/util/apply-overlay.ts:loadOverlay,applyOverlayActions(JSONPath viajsonpath-plus),applyOverlays;deepMergewith__proto__/constructor/prototypeguardSpecification.fromFile()/load()andOpenApiDocumentconstructor to acceptoverlays?: readonly string[]overlaysthroughConfig,SpecConfig,ApiRunner,CodeGenerator, andloadOpenApiDocument--overlay <path>Commander option torun.ts; per-specoverlaysin multi-spec config entries; single-spec CLI flag falls back toconfig.overlaysopenapiMiddlewareto apply overlays afterbundle()so thatGET /counterfact/openapi(Swagger UI source) reflects overlay changes; addedoverlays?: readonly string[]toOpenApiDocumentConfigpublic readonly overlaysonApiRunner;create-koa-app.tspassesrunner.overlaystoopenapiMiddlewarenew URL(...).pathnamewithfileURLToPath(new URL(..., import.meta.url))intest/util/apply-overlay.test.tsto avoid doubled drive-letter paths (D:\D:\a\...) on Windowstest/util/apply-overlay.test.ts, including fixture-based integration teststest/server/web-server/openapi-middleware.test.tslocking in overlay behavior at the/counterfact/openapiendpoint (update visible, remove suppresses path, no-overlay case unchanged)test/fixtures/openapi/overlays/:update-info.yaml— patches the API title, description, and contact blockremove-deprecated.yaml— removes the deprecated/legacy/itemsendpointadd-extensions.yaml— addsx-internal: trueto targeted operationstest-black-box/test_counterfact.py:test_overlay_removes_path_from_generated_routes— runs--generate --overlaywith aremoveaction and asserts the removed path produces no route filetest_overlay_update_changes_served_response— starts a live server with--serve --generate --overlayand verifies the overlay-modified example value is returned at runtimedocs/reference.mdwith full Overlays section and CLI flag entryorigin/main; resolvedyarn.lockconflict (preservedjsonifyandjsonpath-plusentries)