Skip to content

Commit

Permalink
Merge pull request #5733 from svrooij/main
Browse files Browse the repository at this point in the history
Kiota with dependency injection dotnet
  • Loading branch information
baywet authored Jun 21, 2024
2 parents d77b5c4 + 7c45bd0 commit 59d8681
Show file tree
Hide file tree
Showing 29 changed files with 917 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ updates:
kiota-dependencies:
patterns:
- "*kiota*"
- package-ecosystem: nuget
directory: "/get-started/dotnet-dependency-injection"
schedule:
interval: daily
open-pull-requests-limit: 10
groups:
kiota-dependencies:
patterns:
- "*kiota*"
- package-ecosystem: nuget
directory: "/get-started/quickstart/cli/src"
schedule:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
working-directory: sample-api/api

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/get-started-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ on:
paths:
- 'get-started/azure-auth/dotnet/**'
- 'get-started/azure-auth/cli/**'
- 'get-started/dotnet-dependency-injection/**'
- 'get-started/quickstart/dotnet/**'
- 'get-started/quickstart/cli/**'
pull_request:
branches: [ main ]
paths:
- 'get-started/azure-auth/dotnet/**'
- 'get-started/azure-auth/cli/**'
- 'get-started/dotnet-dependency-injection/**'
- 'get-started/quickstart/dotnet/**'
- 'get-started/quickstart/cli/**'

jobs:
build-azure-dotnet:

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand All @@ -40,6 +43,7 @@ jobs:
build-azure-cli:

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand All @@ -55,9 +59,30 @@ jobs:
run: dotnet build --no-restore
working-directory: get-started/azure-auth/cli/src/

build-dotnet-dependency-injection:
defaults:
run:
working-directory: get-started/dotnet-dependency-injection/

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Restore dependencies dotnet-dependency-injection
run: dotnet restore ./dotnet-dependency-injection.sln
- name: Build dotnet-dependency-injection
run: dotnet build ./dotnet-dependency-injection.sln --no-restore

build-quickstart-dotnet:

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand All @@ -79,6 +104,7 @@ jobs:
build-quickstart-cli:

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/get-started-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
working-directory: get-started/azure-auth/java/

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand All @@ -45,6 +46,7 @@ jobs:
working-directory: get-started/quickstart/java/

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/get-started-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
working-directory: get-started/azure-auth/php/

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -51,6 +52,7 @@ jobs:
working-directory: get-started/quickstart/php/

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/get-started-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
working-directory: get-started/azure-auth/python/

runs-on: ubuntu-latest
needs: []

strategy:
matrix:
Expand Down Expand Up @@ -52,6 +53,7 @@ jobs:
working-directory: get-started/quickstart/python/

runs-on: ubuntu-latest
needs: []

strategy:
matrix:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/get-started-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
working-directory: get-started/azure-auth/ruby/

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/get-started-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
working-directory: get-started/azure-auth/typescript/

runs-on: ubuntu-latest
needs: []

strategy:
matrix:
Expand All @@ -45,6 +46,7 @@ jobs:
working-directory: get-started/quickstart/typescript/

runs-on: ubuntu-latest
needs: []

strategy:
matrix:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/get-started.go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
working-directory: get-started/azure-auth/go/

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand All @@ -41,6 +42,7 @@ jobs:
working-directory: get-started/quickstart/go/

runs-on: ubuntu-latest
needs: []

steps:
- uses: actions/checkout@v4
Expand Down
46 changes: 46 additions & 0 deletions get-started/dotnet-dependency-injection/GitHub/GitHubClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// <auto-generated/>
using GitHub.ApiClient.Repos;
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 GitHub.ApiClient
{
/// <summary>
/// The main entry point of the SDK, exposes the configuration and the fluent API.
/// </summary>
public class GitHubClient : BaseRequestBuilder
{
/// <summary>The repos property</summary>
public GitHub.ApiClient.Repos.ReposRequestBuilder Repos
{
get => new GitHub.ApiClient.Repos.ReposRequestBuilder(PathParameters, RequestAdapter);
}
/// <summary>
/// Instantiates a new <see cref="GitHub.ApiClient.GitHubClient"/> and sets the default values.
/// </summary>
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
public GitHubClient(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>();
if (string.IsNullOrEmpty(RequestAdapter.BaseUrl))
{
RequestAdapter.BaseUrl = "https://api.github.com";
}
PathParameters.TryAdd("baseurl", RequestAdapter.BaseUrl);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using GitHub.ApiClient;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Http.HttpClientLibrary;

namespace GitHub;

public class GitHubClientFactory
{
private readonly IAuthenticationProvider _authenticationProvider;
private readonly HttpClient _httpClient;

public GitHubClientFactory(HttpClient httpClient)
{
_authenticationProvider = new AnonymousAuthenticationProvider();
_httpClient = httpClient;
}

public GitHubClient GetClient() {
return new GitHubClient(new HttpClientRequestAdapter(_authenticationProvider, httpClient: _httpClient));
}
}
73 changes: 73 additions & 0 deletions get-started/dotnet-dependency-injection/GitHub/Models/Error.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// <auto-generated/>
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Abstractions;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
namespace GitHub.ApiClient.Models
{
#pragma warning disable CS1591
public class Error : ApiException, IAdditionalDataHolder, IParsable
#pragma warning restore CS1591
{
/// <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 error documentation URL</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? DocumentationUrl { get; set; }
#nullable restore
#else
public string DocumentationUrl { get; set; }
#endif
/// <summary>The error message</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? MessageEscaped { get; set; }
#nullable restore
#else
public string MessageEscaped { get; set; }
#endif
/// <summary>
/// Instantiates a new <see cref="GitHub.ApiClient.Models.Error"/> and sets the default values.
/// </summary>
public Error()
{
AdditionalData = new Dictionary<string, object>();
}
/// <summary>
/// Creates a new instance of the appropriate class based on discriminator value
/// </summary>
/// <returns>A <see cref="GitHub.ApiClient.Models.Error"/></returns>
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
public static GitHub.ApiClient.Models.Error CreateFromDiscriminatorValue(IParseNode parseNode)
{
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
return new GitHub.ApiClient.Models.Error();
}
/// <summary>
/// The deserialization information for the current model
/// </summary>
/// <returns>A IDictionary&lt;string, Action&lt;IParseNode&gt;&gt;</returns>
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{
return new Dictionary<string, Action<IParseNode>>
{
{ "documentation_url", n => { DocumentationUrl = n.GetStringValue(); } },
{ "message", n => { MessageEscaped = 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("documentation_url", DocumentationUrl);
writer.WriteStringValue("message", MessageEscaped);
writer.WriteAdditionalData(AdditionalData);
}
}
}
Loading

0 comments on commit 59d8681

Please sign in to comment.