Skip to content

Commit

Permalink
Merge pull request #4001 from microsoft/hotfix/apis-guru-dns-expired
Browse files Browse the repository at this point in the history
- directly downloads descriptions from github instead of apis.guru
  • Loading branch information
baywet authored Jan 12, 2024
2 parents ce5732b + bff04a2 commit fa5da75
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.10.1] - 2024-01-12

### Added

### Changed

- Fixed an issue where domain expiration for apis.guru would lead to search failures.

## [1.10.0] - 2024-01-11

### Added
Expand Down Expand Up @@ -1213,3 +1221,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial GitHub release


2 changes: 1 addition & 1 deletion src/Kiota.Builder/Kiota.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>Microsoft.OpenApi.Kiota.Builder</Title>
<PackageId>Microsoft.OpenApi.Kiota.Builder</PackageId>
<PackageOutputPath>./nupkg</PackageOutputPath>
<VersionPrefix>1.11.0</VersionPrefix>
<VersionPrefix>1.10.1</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<PackageReleaseNotes>
https://github.com/microsoft/kiota/releases
Expand Down
3 changes: 2 additions & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Kiota.Builder.Manifest;
using Kiota.Builder.OpenApiExtensions;
using Kiota.Builder.Refiners;
using Kiota.Builder.SearchProviders.APIsGuru;
using Kiota.Builder.Validation;
using Kiota.Builder.Writers;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -411,7 +412,7 @@ private async Task<Stream> LoadStream(string inputPath, CancellationToken cancel
{
ClearCache = config.ClearCache,
};
var targetUri = new Uri(inputPath);
var targetUri = APIsGuruSearchProvider.ChangeSourceUrlToGitHub(new Uri(inputPath)); // so updating existing clients doesn't break
var fileName = targetUri.GetFileName() is string name && !string.IsNullOrEmpty(name) ? name : "description.yml";
input = await cachingProvider.GetDocumentAsync(targetUri, "generation", fileName, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public APIsGuruSearchProvider(Uri searchUri, HttpClient httpClient, ILogger logg
public HashSet<string> KeysToExclude
{
get; init;
} = new() {
} = new(StringComparer.OrdinalIgnoreCase) {
"microsoft.com:graph"
};
public async Task<IDictionary<string, SearchResult>> SearchAsync(string term, string? version, CancellationToken cancellationToken)
Expand All @@ -53,10 +53,14 @@ public async Task<IDictionary<string, SearchResult>> SearchAsync(string term, st
.Where(static x => x.versionInfo is not null)
.DistinctBy(static x => x.Key, StringComparer.OrdinalIgnoreCase)
.ToDictionary(static x => x.Key,
static x => new SearchResult(x.versionInfo!.info?.title ?? string.Empty, x.versionInfo.info?.description ?? string.Empty, x.versionInfo.info?.contact?.url, x.versionInfo.swaggerUrl, x.Item3 ?? Enumerable.Empty<string>().ToList()),
static x => new SearchResult(x.versionInfo!.info?.title ?? string.Empty, x.versionInfo.info?.description ?? string.Empty, x.versionInfo.info?.contact?.url, ChangeSourceUrlToGitHub(x.versionInfo.swaggerUrl), x.Item3 ?? Enumerable.Empty<string>().ToList()),
StringComparer.OrdinalIgnoreCase);
return results;
}
internal static Uri ChangeSourceUrlToGitHub(Uri original) =>
original.Host.StartsWith("api.apis.guru", StringComparison.OrdinalIgnoreCase) ?
new(original.ToString().Replace("https://api.apis.guru", "https://raw.githubusercontent.com/APIs-guru/openapi-directory/gh-pages", StringComparison.OrdinalIgnoreCase), UriKind.Absolute) :
original;
private static string GetVersionKey(bool singleCandidate, string? version, KeyValuePair<string, ApiEntry> x) => singleCandidate && !string.IsNullOrEmpty(version) ? version : x.Value.preferred;
}

Expand Down
2 changes: 1 addition & 1 deletion src/kiota/kiota.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>Microsoft.OpenApi.Kiota</Title>
<PackageId>Microsoft.OpenApi.Kiota</PackageId>
<PackageOutputPath>./nupkg</PackageOutputPath>
<VersionPrefix>1.11.0</VersionPrefix>
<VersionPrefix>1.10.1</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<PackageReleaseNotes>
https://github.com/microsoft/kiota/releases
Expand Down
4 changes: 4 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaSearcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public async Task GetsGithubFromApisGuruWithExactMatch()
var searcher = new KiotaSearcher(new Mock<ILogger<KiotaSearcher>>().Object, searchConfiguration, httpClient, null, null);
var results = await searcher.SearchAsync("apisguru::github.com:api.github.com.2022-11-28", string.Empty, new CancellationToken());
Assert.Single(results);
var result = results.First();
var resultUrl = result.Value.DescriptionUrl;
var bytes = await httpClient.GetByteArrayAsync(resultUrl);
Assert.NotEmpty(bytes);
}
public void Dispose()
{
Expand Down

0 comments on commit fa5da75

Please sign in to comment.