-
Notifications
You must be signed in to change notification settings - Fork 250
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
Fix: relative references in subdirectory documents are not loading #1674 #2243
base: main
Are you sure you want to change the base?
Fix: relative references in subdirectory documents are not loading #1674 #2243
Conversation
…crosoft#1674 Use OpenApiDocuments BaseUri as location of the document. This allows to have during loading further documents a base Url for retrieval, which can be combined with a relative Uri to get an absolute.
Thanks for the contribution! @MaggieKimani1 can you do an initial review here please? |
@@ -259,11 +265,11 @@ | |||
private static async Task<OpenApiDiagnostic> LoadExternalRefsAsync(OpenApiDocument document, OpenApiReaderSettings settings, string format = null, CancellationToken token = default) | |||
{ | |||
// Create workspace for all documents to live in. | |||
var baseUrl = settings.BaseUrl ?? new Uri(OpenApiConstants.BaseRegistryUri); | |||
var openApiWorkSpace = new OpenApiWorkspace(baseUrl); | |||
var baseUrl = document.BaseUri; |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning
baseUrl
@dldl-cmd sorry for the delay in response/review. Line 53 in ff287bc
Once you do so, the files will automatically be registered with the source document's workspace. Reference: Lines 85 to 98 in ff287bc
|
@MaggieKimani1 implementing just an own stream loader cannot solve the problem. The reason is, that the stream loader has no idea, which document is the current parent and where this document is located. Therefore it cannot resolve the relative reference as it doesn't know to which location it is relative. An example:
....
$ref: ./DirA/DirB/DirC/second.yaml#/components/schema/Second
...
$ref: ../third.yaml#/components/schema/Third
...
$ref: ./DirC/Fourth.yaml#/components/schema/Fourth.yaml When the reference This information is not only necessary at the time of loading the document but also when |
Use OpenApiDocuments BaseUri as location of the document. This allows to have during loading further documents a base Url for retrieval, which can be combined with a relative Uri to get an absolute.
Fixes #1674