Skip to content
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

[WIP] Kiota search apicurio #3670

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/Kiota.Builder/Configuration/SearchConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using System;
using System.Runtime.InteropServices;
andreaTP marked this conversation as resolved.
Show resolved Hide resolved

namespace Kiota.Builder.Configuration;

public class SearchConfiguration : SearchConfigurationBase, ICloneable
{
public Uri APIsGuruListUrl { get; set; } = new("https://raw.githubusercontent.com/APIs-guru/openapi-directory/gh-pages/v2/list.json");
public GitHubConfiguration GitHub { get; set; } = new();
public ApicurioConfiguration Apicurio { get; set; } = new();

public object Clone()
{
return new SearchConfiguration
{
APIsGuruListUrl = new(APIsGuruListUrl.ToString(), UriKind.RelativeOrAbsolute),
GitHub = (GitHubConfiguration)GitHub.Clone(),
Apicurio = (ApicurioConfiguration)Apicurio.Clone(),
ClearCache = ClearCache
};
}
Expand All @@ -36,3 +39,39 @@ public object Clone()
};
}
}

public class ApicurioConfiguration : ICloneable
{
public enum ApicurioSearchBy
{
LABEL,
PROPERTY
}

public Uri? ApiBaseUrl
{
get; set;
}

public Uri? UIBaseUrl
{
get; set;
}

public int ArtifactsLimit { get; set; } = 10;
public int VersionsLimit { get; set; } = 100;

public ApicurioSearchBy SearchBy { get; set; } = ApicurioSearchBy.LABEL;

public object Clone()
{
return new ApicurioConfiguration
{
ApiBaseUrl = (ApiBaseUrl != null) ? new(ApiBaseUrl.ToString(), UriKind.RelativeOrAbsolute) : null,
UIBaseUrl = (UIBaseUrl != null) ? new(UIBaseUrl.ToString(), UriKind.RelativeOrAbsolute) : null,
ArtifactsLimit = ArtifactsLimit,
VersionsLimit = VersionsLimit,
SearchBy = SearchBy
};
}
}
10 changes: 8 additions & 2 deletions src/Kiota.Builder/KiotaSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Kiota.Builder.Configuration;
using Kiota.Builder.SearchProviders;
using Kiota.Builder.SearchProviders.Apicurio;
using Kiota.Builder.SearchProviders.APIsGuru;
using Kiota.Builder.SearchProviders.GitHub;
using Kiota.Builder.SearchProviders.MSGraph;
Expand All @@ -20,9 +21,11 @@ public class KiotaSearcher
private readonly SearchConfiguration _config;
private readonly HttpClient _httpClient;
private readonly IAuthenticationProvider? _gitHubAuthenticationProvider;

private readonly IAuthenticationProvider? _apicurioAuthenticationProvider;
private readonly Func<CancellationToken, Task<bool>> _isGitHubSignedInCallBack;

public KiotaSearcher(ILogger<KiotaSearcher> logger, SearchConfiguration config, HttpClient httpClient, IAuthenticationProvider? gitHubAuthenticationProvider, Func<CancellationToken, Task<bool>> isGitHubSignedInCallBack)
public KiotaSearcher(ILogger<KiotaSearcher> logger, SearchConfiguration config, HttpClient httpClient, IAuthenticationProvider? gitHubAuthenticationProvider, Func<CancellationToken, Task<bool>> isGitHubSignedInCallBack, IAuthenticationProvider? apicurioAuthenticationProvider)
{
ArgumentNullException.ThrowIfNull(logger);
ArgumentNullException.ThrowIfNull(config);
Expand All @@ -32,6 +35,7 @@ public KiotaSearcher(ILogger<KiotaSearcher> logger, SearchConfiguration config,
_httpClient = httpClient;
_gitHubAuthenticationProvider = gitHubAuthenticationProvider;
_isGitHubSignedInCallBack = isGitHubSignedInCallBack;
_apicurioAuthenticationProvider = apicurioAuthenticationProvider;
}
public async Task<IDictionary<string, SearchResult>> SearchAsync(string? searchTerm, string? version, CancellationToken cancellationToken)
{
Expand All @@ -45,10 +49,12 @@ public async Task<IDictionary<string, SearchResult>> SearchAsync(string? searchT
_logger.LogDebug("searching APIs.guru with url {Url}", _config.APIsGuruListUrl);
var oasProvider = new OpenApiSpecSearchProvider();
var githubProvider = new GitHubSearchProvider(_httpClient, _logger, _config.ClearCache, _config.GitHub, _gitHubAuthenticationProvider, _isGitHubSignedInCallBack);
var apicurioProvider = new ApicurioSearchProvider(_httpClient, _logger, _config.ClearCache, _config.Apicurio, _apicurioAuthenticationProvider);
var results = await Task.WhenAll(
SearchProviderAsync(searchTerm, version, apiGurusSearchProvider, cancellationToken),
SearchProviderAsync(searchTerm, version, oasProvider, cancellationToken),
SearchProviderAsync(searchTerm, version, githubProvider, cancellationToken)).ConfigureAwait(false);
SearchProviderAsync(searchTerm, version, githubProvider, cancellationToken),
SearchProviderAsync(searchTerm, version, apicurioProvider, cancellationToken)).ConfigureAwait(false);
return results.SelectMany(static x => x)
.ToDictionary(static x => x.Key, static x => x.Value, StringComparer.OrdinalIgnoreCase);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <auto-generated/>
using ApiSdk.Groups;
using ApiSdk.Search;
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Serialization.Form;
using Microsoft.Kiota.Serialization.Json;
using Microsoft.Kiota.Serialization.Multipart;
using Microsoft.Kiota.Serialization.Text;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System;
namespace ApiSdk {
/// <summary>
/// The main entry point of the SDK, exposes the configuration and the fluent API.
/// </summary>
public class ApicurioClient : BaseRequestBuilder {
/// <summary>The groups property</summary>
public GroupsRequestBuilder Groups { get =>
new GroupsRequestBuilder(PathParameters, RequestAdapter);
}
/// <summary>The search property</summary>
public SearchRequestBuilder Search { get =>
new SearchRequestBuilder(PathParameters, RequestAdapter);
}
/// <summary>
/// Instantiates a new ApicurioClient and sets the default values.
/// </summary>
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
public ApicurioClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary<string, object>()) {
ApiClientBuilder.RegisterDefaultSerializer<JsonSerializationWriterFactory>();
ApiClientBuilder.RegisterDefaultSerializer<TextSerializationWriterFactory>();
ApiClientBuilder.RegisterDefaultSerializer<FormSerializationWriterFactory>();
ApiClientBuilder.RegisterDefaultSerializer<MultipartSerializationWriterFactory>();
ApiClientBuilder.RegisterDefaultDeserializer<JsonParseNodeFactory>();
ApiClientBuilder.RegisterDefaultDeserializer<TextParseNodeFactory>();
ApiClientBuilder.RegisterDefaultDeserializer<FormParseNodeFactory>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// <auto-generated/>
using ApiSdk.Groups.Item;
using Microsoft.Kiota.Abstractions;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System;
namespace ApiSdk.Groups {
/// <summary>
/// Builds and executes requests for operations under \groups
/// </summary>
public class GroupsRequestBuilder : BaseRequestBuilder {
/// <summary>Gets an item from the ApiSdk.groups.item collection</summary>
/// <param name="position">Unique identifier of the item</param>
public WithGroupItemRequestBuilder this[string position] { get {
var urlTplParams = new Dictionary<string, object>(PathParameters);
urlTplParams.Add("groupId", position);
return new WithGroupItemRequestBuilder(urlTplParams, RequestAdapter);
} }
/// <summary>
/// Instantiates a new GroupsRequestBuilder and sets the default values.
/// </summary>
/// <param name="pathParameters">Path parameters for the request</param>
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
public GroupsRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/groups", pathParameters) {
}
/// <summary>
/// Instantiates a new GroupsRequestBuilder and sets the default values.
/// </summary>
/// <param name="rawUrl">The raw URL to use for the request builder.</param>
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
public GroupsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/groups", rawUrl) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <auto-generated/>
using ApiSdk.Groups.Item.Artifacts;
using Microsoft.Kiota.Abstractions;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System;
namespace ApiSdk.Groups.Item {
/// <summary>
/// Builds and executes requests for operations under \groups\{groupId}
/// </summary>
public class WithGroupItemRequestBuilder : BaseRequestBuilder {
/// <summary>The artifacts property</summary>
public ArtifactsRequestBuilder Artifacts { get =>
new ArtifactsRequestBuilder(PathParameters, RequestAdapter);
}
/// <summary>
/// Instantiates a new WithGroupItemRequestBuilder and sets the default values.
/// </summary>
/// <param name="pathParameters">Path parameters for the request</param>
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
public WithGroupItemRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/groups/{groupId}", pathParameters) {
}
/// <summary>
/// Instantiates a new WithGroupItemRequestBuilder and sets the default values.
/// </summary>
/// <param name="rawUrl">The raw URL to use for the request builder.</param>
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
public WithGroupItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/groups/{groupId}", rawUrl) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// <auto-generated/>
using Microsoft.Kiota.Abstractions.Serialization;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
namespace ApiSdk.Models {
/// <summary>
/// A reference to a different artifact. Typically used with artifact types that can have dependencies like Protobuf.
/// </summary>
public class ArtifactReference : IAdditionalDataHolder, IParsable {
/// <summary>Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.</summary>
public IDictionary<string, object> AdditionalData { get; set; }
/// <summary>The artifactId property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? ArtifactId { get; set; }
#nullable restore
#else
public string ArtifactId { get; set; }
#endif
/// <summary>The groupId property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? GroupId { get; set; }
#nullable restore
#else
public string GroupId { get; set; }
#endif
/// <summary>The name property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? Name { get; set; }
#nullable restore
#else
public string Name { get; set; }
#endif
/// <summary>The version property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? Version { get; set; }
#nullable restore
#else
public string Version { get; set; }
#endif
/// <summary>
/// Instantiates a new ArtifactReference and sets the default values.
/// </summary>
public ArtifactReference() {
AdditionalData = new Dictionary<string, object>();
}
/// <summary>
/// Creates a new instance of the appropriate class based on discriminator value
/// </summary>
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
public static ArtifactReference CreateFromDiscriminatorValue(IParseNode parseNode) {
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
return new ArtifactReference();
}
/// <summary>
/// The deserialization information for the current model
/// </summary>
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
{"artifactId", n => { ArtifactId = n.GetStringValue(); } },
{"groupId", n => { GroupId = n.GetStringValue(); } },
{"name", n => { Name = n.GetStringValue(); } },
{"version", n => { Version = n.GetStringValue(); } },
};
}
/// <summary>
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteStringValue("artifactId", ArtifactId);
writer.WriteStringValue("groupId", GroupId);
writer.WriteStringValue("name", Name);
writer.WriteStringValue("version", Version);
writer.WriteAdditionalData(AdditionalData);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// <auto-generated/>
using Microsoft.Kiota.Abstractions.Serialization;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
namespace ApiSdk.Models {
/// <summary>
/// Describes the response received when searching for artifacts.
/// </summary>
public class ArtifactSearchResults : IAdditionalDataHolder, IParsable {
/// <summary>Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.</summary>
public IDictionary<string, object> AdditionalData { get; set; }
/// <summary>The artifacts returned in the result set.</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public List<SearchedArtifact>? Artifacts { get; set; }
#nullable restore
#else
public List<SearchedArtifact> Artifacts { get; set; }
#endif
/// <summary>The total number of artifacts that matched the query that produced the result set (may be more than the number of artifacts in the result set).</summary>
public int? Count { get; set; }
/// <summary>
/// Instantiates a new ArtifactSearchResults and sets the default values.
/// </summary>
public ArtifactSearchResults() {
AdditionalData = new Dictionary<string, object>();
}
/// <summary>
/// Creates a new instance of the appropriate class based on discriminator value
/// </summary>
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
public static ArtifactSearchResults CreateFromDiscriminatorValue(IParseNode parseNode) {
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
return new ArtifactSearchResults();
}
/// <summary>
/// The deserialization information for the current model
/// </summary>
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
{"artifacts", n => { Artifacts = n.GetCollectionOfObjectValues<SearchedArtifact>(SearchedArtifact.CreateFromDiscriminatorValue)?.ToList(); } },
{"count", n => { Count = n.GetIntValue(); } },
};
}
/// <summary>
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteCollectionOfObjectValues<SearchedArtifact>("artifacts", Artifacts);
writer.WriteIntValue("count", Count);
writer.WriteAdditionalData(AdditionalData);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// <auto-generated/>
using System.Runtime.Serialization;
using System;
namespace ApiSdk.Models {
/// <summary>Describes the state of an artifact or artifact version. The following statesare possible:* ENABLED* DISABLED* DEPRECATED</summary>
public enum ArtifactState {
[EnumMember(Value = "ENABLED")]
ENABLED,
[EnumMember(Value = "DISABLED")]
DISABLED,
[EnumMember(Value = "DEPRECATED")]
DEPRECATED,
}
}
Loading