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? |
|
@dldl-cmd sorry for the delay in response/review. Once you do so, the files will automatically be registered with the source document's workspace. Reference: |
|
@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.yamlWhen the reference This information is not only necessary at the time of loading the document but also when |
|
Also do you mind resolving the conflicts? |
Sorry for my late reply, I was unavailable a few days. I didn't notice the merge conflict until now. I have started to resolve them, but I need to check at least one conflict more in detail. Hopefully I can resolve it in the next days. |
| (_, true, false) when baseUrl.Scheme.Equals("file", StringComparison.OrdinalIgnoreCase) && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) => | ||
| new Uri(Path.Combine(baseUrl.AbsoluteUri, uri.ToString())), | ||
| (_, _, _) => new Uri(baseUrl, uri), | ||
| true => new Uri(Path.Combine(Directory.GetCurrentDirectory(), uri.ToString())), |
Check notice
Code scanning / CodeQL
Call to 'System.IO.Path.Combine' may silently drop its earlier arguments Note
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