feat: OpenApiDocument is now a class with built-in file watching and EventTarget#1826
Draft
feat: OpenApiDocument is now a class with built-in file watching and EventTarget#1826
Conversation
Copilot
AI
changed the title
[WIP] Convert OpenAPIDocument to a class for improved functionality
feat: OpenApiDocument is now a class with built-in file watching and EventTarget
Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OpenApiDocumentwas a plain interface — loading and watching the spec file were handled by separateloadOpenApiDocumentandOpenApiWatcherhelpers. This PR collapses all three responsibilities into a single class.src/server/openapi-document.ts— new class:EventTarget; dispatches"reload"whenever the file changes on disknew OpenApiDocument(source)— captures source pathawait doc.load()— reads + dereferences the spec, populatespaths,basePath,producesawait doc.watch()/await doc.stopWatching()— file-system watcher (no-op for"_"and HTTP sources)src/server/load-openapi-document.ts— now just creates an instance and callsload().src/server/dispatcher.ts— retains the oldOpenApiDocumentinterface for backward-compat; class instances satisfy it structurally so existing tests and consumers pass plain objects unchanged.src/app.ts—OpenApiWatcherremoved; replaced byopenApiDocument?.watch()/openApiDocument?.stopWatching().Original Prompt
OpenAPIDocument should be a class
It should know the location of its source file. It should read the file and initialize itself. It should watch for changes (instead of a separate OpenAPIWatcher). It should extend EventTarget so it can notify others when it has been reloaded (those that formerly relied on OpenAPIWatcher).
Manual acceptance tests
loadOpenApiDocument()returns an instance withpaths,basePath, andproducespopulated correctlyopenApiPath: "_"starts the server with no file watcher activeTasks
src/server/openapi-document.ts:OpenApiDocument extends EventTargetwithload(),watch(),stopWatching()src/server/load-openapi-document.tsto delegate to the new classOpenApiWatcherusage fromsrc/app.ts; wiredopenApiDocument.watch()/stopWatching()in its placeOpenApiDocumentinterface indispatcher.tsso plain-object test fixtures continue to compiletest/server/openapi-document.test.tswith 8 tests (EventTarget, load, error handling, reload event, path update after reload, no-op watch paths)