-
Notifications
You must be signed in to change notification settings - Fork 48
Add URI resolution helpers for base URI resolution #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ayushshrivastv
wants to merge
13
commits into
mattpolzin:main
Choose a base branch
from
ayushshrivastv:BaseURIHelpers.swift
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4a1df96
Add base URI resolution helpers
ayushshrivastv bd82590
Avoid async let crashes in path item dereferencing
ayushshrivastv a2a309e
Fix schema ID preservation and coverage
ayushshrivastv 018c42a
Align URI resolution changes with existing patterns
ayushshrivastv 4f22198
Use core context for schema identifier access
ayushshrivastv ac7a46f
Match main branch schema decode style
ayushshrivastv e44bc6a
Retry swift 6.1 noble CI
ayushshrivastv d14d1ec
Merge branch 'main' into BaseURIHelpers.swift
ayushshrivastv 9ee80ba
Merge branch 'main' into BaseURIHelpers.swift
ayushshrivastv 848b779
Merge branch 'main' into BaseURIHelpers.swift
ayushshrivastv a87c3b9
Merge branch 'main' into BaseURIHelpers.swift
ayushshrivastv 27e8540
Trigger CI rerun
ayushshrivastv cb46622
Add Appendix F document URI resolution coverage
ayushshrivastv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import OpenAPIKitCore | ||
|
|
||
| #if canImport(FoundationEssentials) | ||
| import FoundationEssentials | ||
| #else | ||
| import Foundation | ||
| #endif | ||
|
|
||
| public extension OpenAPI.Document { | ||
| /// Establish the base URI for this document. | ||
| /// | ||
| /// If the document has a `$self`, it is resolved against the retrieval URI. | ||
| /// Otherwise, the retrieval URI itself is the established base URI. | ||
| func baseURI(relativeTo retrievalURI: URL? = nil) -> URL? { | ||
| selfURI?.resolvedURI(relativeTo: retrievalURI) ?? retrievalURI | ||
| } | ||
|
|
||
| /// Resolve a JSON reference against this document's established base URI. | ||
| func resolvedURI<ReferenceType>( | ||
| for reference: JSONReference<ReferenceType>, | ||
| relativeTo retrievalURI: URL? = nil | ||
| ) -> URL { | ||
| reference.resolvedURI(relativeTo: baseURI(relativeTo: retrievalURI)) | ||
| } | ||
|
|
||
| /// Resolve an OpenAPI reference against this document's established base URI. | ||
| func resolvedURI<ReferenceType>( | ||
| for reference: OpenAPI.Reference<ReferenceType>, | ||
| relativeTo retrievalURI: URL? = nil | ||
| ) -> URL { | ||
| reference.resolvedURI(relativeTo: baseURI(relativeTo: retrievalURI)) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import OpenAPIKitCore | ||
|
|
||
| #if canImport(FoundationEssentials) | ||
| import FoundationEssentials | ||
| #else | ||
| import Foundation | ||
| #endif | ||
|
|
||
| public extension JSONReference { | ||
| /// A URI-reference representing this JSON reference. | ||
| /// | ||
| /// Internal references are represented as fragment-only URLs. | ||
| var uriReference: URL { | ||
| switch self { | ||
| case .internal(let reference): | ||
| return URL(string: reference.rawValue)! | ||
| case .external(let url): | ||
| return url | ||
| } | ||
| } | ||
|
|
||
| /// Resolve this reference against the given base URI. | ||
| /// | ||
| /// If `baseURI` is `nil`, relative URI-references remain relative. | ||
| func resolvedURI(relativeTo baseURI: URL?) -> URL { | ||
| uriReference.resolvedURI(relativeTo: baseURI) | ||
| } | ||
| } | ||
|
|
||
| public extension OpenAPI.Reference { | ||
| /// A URI-reference representing this OpenAPI reference. | ||
| var uriReference: URL { | ||
| jsonReference.uriReference | ||
| } | ||
|
|
||
| /// Resolve this reference against the given base URI. | ||
| /// | ||
| /// If `baseURI` is `nil`, relative URI-references remain relative. | ||
| func resolvedURI(relativeTo baseURI: URL?) -> URL { | ||
| jsonReference.resolvedURI(relativeTo: baseURI) | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to go via a string here and force to non-nil? The situations where I am ok with forcing (and inherently introducing a crash risk) are few and far between.