Skip to content

Add URI resolution helpers for base URI resolution#489

Open
ayushshrivastv wants to merge 3 commits intomattpolzin:mainfrom
ayushshrivastv:BaseURIHelpers.swift
Open

Add URI resolution helpers for base URI resolution#489
ayushshrivastv wants to merge 3 commits intomattpolzin:mainfrom
ayushshrivastv:BaseURIHelpers.swift

Conversation

@ayushshrivastv
Copy link
Contributor

Summary

  • add reusable URI resolution helpers for raw URLs, JSON references, and documents in both OpenAPIKit and OpenAPIKit30
  • add schema base URI helpers and identifier support on OpenAPIKit schema contexts so callers can compose parent base URIs with schema identifiers
  • cover the new helpers with focused document, reference, and schema URI resolution tests

Closes #439.

Testing

  • swift test --filter JSONReferenceURIResolutionTests
  • swift test --filter DocumentURIResolutionTests
  • swift test --filter JSONSchemaURIResolutionTests
  • git diff --check

@ayushshrivastv
Copy link
Contributor Author

Implementation notes for reviewers:

  • Added shared URI-resolution helpers in both modules so callers can resolve URI references without reimplementing base-URI logic. JSONReference now exposes uriReference and resolvedURI(relativeTo:), and OpenAPI.Reference in OpenAPIKit forwards to the same logic.
  • Added document-level convenience helpers. In OpenAPIKit, OpenAPI.Document.baseURI(relativeTo:) establishes the document base URI by combining the retrieval URI with $self when present. In OpenAPIKit30, the retrieval URI is used directly since 3.0 documents do not support $self.
  • Added a small shared URL helper in OpenAPIKitCore so relative and fragment-only URI references are resolved consistently from one place.
  • Added schema base-URI support through JSONSchemaContext.baseURI(relativeTo:), and added id support on the OpenAPIKit schema context so schema identifiers can participate in base-URI composition through the public API.
  • Added focused regression coverage for:
    • JSONReferenceURIResolutionTests
    • DocumentURIResolutionTests
    • JSONSchemaURIResolutionTests

Files with the main implementation:

  • Sources/OpenAPIKitCore/Utility/URL+Resolution.swift
  • Sources/OpenAPIKit/JSONReference+URIResolution.swift
  • Sources/OpenAPIKit30/JSONReference+URIResolution.swift
  • Sources/OpenAPIKit/Document/Document+URIResolution.swift
  • Sources/OpenAPIKit30/Document/Document+URIResolution.swift
  • Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift
  • Sources/OpenAPIKit/Schema Object/JSONSchema.swift
  • Sources/OpenAPIKit30/Schema Object/JSONSchemaContext.swift

Local verification run on this branch:

  • swift test --filter JSONReferenceURIResolutionTests
  • swift test --filter DocumentURIResolutionTests
  • swift test --filter JSONSchemaURIResolutionTests
  • git diff --check

@ayushshrivastv
Copy link
Contributor Author

Follow-up for the failing linux (swift:6.1-jammy) job: the failure was not in the new URI-resolution code. It was the same older Swift async runtime crash in OpenAPI.PathItem.externallyDereferenced / OpenAPIKit30/Path Item/DereferencedPathItem.swift during ExternalDereferencingDocumentTests.test_example. I cherry-picked the proven compatibility fix (bd82590) onto this branch, pushed it, and re-ran the relevant coverage locally.

Additional local verification after the follow-up commit:

  • swift test --filter ExternalDereferencingDocumentTests/test_example -Xswiftc -strict-concurrency=complete
  • swift test --filter JSONReferenceURIResolutionTests
  • swift test --filter DocumentURIResolutionTests
  • swift test --filter JSONSchemaURIResolutionTests
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build in helpers to resolve URIs against base URIs

1 participant