fix(oas:sync): resolve path-item $refs so sync stops deleting pages - #47
Draft
cursor[bot] wants to merge 4 commits into
Draft
fix(oas:sync): resolve path-item $refs so sync stops deleting pages#47cursor[bot] wants to merge 4 commits into
cursor[bot] wants to merge 4 commits into
Conversation
extractOperations walked the raw spec and treated a path-level $ref (OAS 3.1 components.pathItems, or a pointer to another path) as having zero operations. oas:sync and lint --fix then deleted every matching reference page. Resolve internal JSON Pointer $refs before collecting operations, and skip the delete pass when a $ref still cannot be inlined (e.g. a split spec that points at ./paths/*.yaml). Co-authored-by: Jon Ursenbach <erunion@users.noreply.github.com>
|
| Filename | Overview |
|---|---|
| src/commands/oas-sync.js | Replaces raw operation walking with reference-aware extraction, overlays path-item siblings, and disables destructive deletion when operation visibility is incomplete. |
| test/oas-sync.test.js | Adds regression coverage for internal, external, cyclic, inherited-property, sibling, non-object-target, and operation-level reference cases. |
| test/oas-reference.test.js | Verifies that operations supplied through OAS 3.1 path-item references are recognized by cross-file validation. |
| package.json | Adds the oas package used by the new extraction implementation. |
| package-lock.json | Locks the new oas dependency and its transitive dependency graph. |
Reviews (4): Last reviewed commit: "refactor(oas:sync): use the oas library ..." | Re-trigger Greptile
- Walk JSON Pointers with Object.hasOwn so #/__proto__ cannot escape into Object.prototype and empty the operation set. - Treat a $ref as unresolved only after following the full chain, so a pointer that lands on an external, cyclic, or broken $ref still skips the delete pass. - Overlay OAS 3.1 path-item siblings onto the resolved target instead of dropping them (local keys win). Co-authored-by: Jon Ursenbach <erunion@users.noreply.github.com>
A path-item $ref that resolved to an array or scalar used to return that target and drop sibling operations, while isUnresolvedRef treated the hop as successful. Sync then deleted the sibling page. Keep the original object on a non-object target so siblings stay in the operation map and $ref still trips the delete guard. Also skip unresolved operation $refs that have no operationId so we do not invent a synthetic get_pets page. Co-authored-by: Jon Ursenbach <erunion@users.noreply.github.com>
Replace the hand-rolled JSON Pointer walker and synthetic operationId helper with `oas`. getPaths() resolves path-item and operation $refs; Operation supplies getOperationId, getSummary, getDescription, and getTags. Keep a thin overlay for OAS 3.1 siblings that sit next to a path-item $ref (getPaths drops those) and skip the delete pass when a $ref is still unresolved so we do not wipe pages or invent get_pets stubs. Co-authored-by: Jon Ursenbach <erunion@users.noreply.github.com>
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.
oas:sync/lint --fixdeleted valid reference pages when the spec used path-item$refs🪄 Changes
extractOperationswalked the raw OpenAPI document and only counted HTTP methods sitting directly on each path item. A path-level$ref— including the OAS 3.1components.pathItemsform — therefore contributed zero operations.syncOneOasthen treated every existing page for that spec as orphaned and deleted it. Same path forreadme lint --fix(via theoas-referencevalidator).Concrete trigger: a repo with
reference/openapi.jsonlike:and a page
reference/.../listPets.mdwith custom body. Onereadme oas:syncorreadme lint --fixpermanently deletes that page.Fix:
$refs (#/components/pathItems/…,#/paths/~1pets, operation-level pointers) before collecting operations.$refstill cannot be inlined (e.g. a split spec pointing at./paths/pets.yaml), so "we couldn't see the operation" is not treated as "the operation was removed".No change to add/skip-on-collision behavior, path sanitization, or webhook handling (still covered by #43).
🧬 QA & Testing
pathItemsspec on unmodifiedmain(page gone;changes.deleted = ['Pets/Other/listPets.md']).oas-referencevalidator no longer reportsOperation not found.test/oas-sync.test.js(resolution, no-deletion for internal and external$refs) andtest/oas-reference.test.js(no false missing-operation).npm test).