Support local dereferencing of schema anchors#492
Support local dereferencing of schema anchors#492ayushshrivastv wants to merge 9 commits intomattpolzin:mainfrom
Conversation
|
CI note: the This branch was missing the earlier Linux-stability follow-ups that we had already applied on other OpenAPIKit branches, so I pulled those fixes into this PR as well. Concretely, the fix removes the async fan-out in Local verification after the fix:
|
|
@mattpolzin Can you guide me on this pull request? I have tried to add local dereferencing to support anchors, while trying to stay aligned with the existing code patterns, especially since this ends up touching more lines than I’d ideally like, but my test suite is still hitting some test failures. So before I make further changes, would you mind taking a quick look and letting me know if the approach is headed in the right direction? |
Closes #363
Summary
#anchorreferences as a first-classJSONReference.InternalReferencecaseDocument.locallyDereferenced()build an anchor-aware temporary lookup so schema anchors can resolve during local dereferencingImplementation Details
OpenAPI 3.1 schema anchors live outside the Components Object, but local dereferencing in OpenAPIKit currently resolves only through
document.components. To keep the fix narrow and avoid changing unrelated reference behavior, this patch keeps the anchor support scoped to local dereferencing:JSONReference<...>.InternalReferencenow preserves#anchorvalues as.anchor(name:)instead of collapsing them into a generic path reference.JSONReference<JSONSchema>.anchor(named:)was added as a convenience constructor for local schema anchor references.Document.locallyDereferenced()now uses a temporary, anchor-aware copy ofcomponentsthat is populated by walking the document's inline and component-hosted schemas and registering anchored schemas for lookup during dereferencing.Components+JSONReferencenow recognizes.anchor(name:)forJSONSchemalookups so the existing dereference machinery can resolve anchored schemas and continue following nested references/cycles consistently.This keeps the public fix focused on the issue at hand: local document dereferencing now works for
$ref: '#someAnchor'without widening non-schema or non-local lookup behavior.Testing
swift test --filter JSONReferenceTestsswift test --filter DereferencedDocumentTestsswift test --filter ComponentsTestsswift test