Support local dereferencing of schema anchors#492
Support local dereferencing of schema anchors#492ayushshrivastv wants to merge 4 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 I wanted to share a little more context on this PR. The instability I was seeing was coming from the older async fan-out path used during external dereferencing on Linux 6.1, rather than from the local-anchor change itself. I pushed the fixes I had on hand for that path so the branch reflects the current working state. I’m also working on another issue and would like to base that follow-up work on the right |
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