diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index d041fd40..f11beac3 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -62,7 +62,7 @@ jobs: CoverletOutputFormat: "opencover" # https://github.com/microsoft/vstest/issues/4014#issuecomment-1307913682 shell: pwsh run: | - dotnet tool run dotnet-sonarscanner begin /k:"microsoft_kiota-abstractions-dotnet" /o:"microsoft" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="tests/abstractions/coverage.net8.0.opencover.xml,tests/authentication/azure/coverage.net8.0.opencover.xml,tests/http/httpClient/coverage.net8.0.opencover.xml,tests/serialization/json/coverage.net8.0.opencover.xml,tests/serialization/text/coverage.net8.0.opencover.xml,tests/serialization/form/coverage.net8.0.opencover.xml,tests/serialization/multipart/coverage.net8.0.opencover.xml" + dotnet tool run dotnet-sonarscanner begin /k:"microsoft_kiota-abstractions-dotnet" /o:"microsoft" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="tests/abstractions/coverage.net8.0.opencover.xml,tests/authentication/azure/coverage.net8.0.opencover.xml,tests/http/httpClient/coverage.net8.0.opencover.xml,tests/serialization/json/coverage.net8.0.opencover.xml,tests/serialization/text/coverage.net8.0.opencover.xml,tests/serialization/form/coverage.net8.0.opencover.xml,tests/serialization/multipart/coverage.net8.0.opencover.xml,tests/bundle/coverage.net8.0.opencover.xml" dotnet workload restore dotnet build dotnet test Microsoft.Kiota.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --framework net8.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a4bb347..90093d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.10.0] - 2024-07-17 + +- Adds Kiota bundle package to provide default adapter with registrations setup. [#290](https://github.com/microsoft/kiota-dotnet/issues/290) + ## [1.9.12] - 2024-07-30 - Fix non IParasable object serialization. diff --git a/Directory.Build.props b/Directory.Build.props index 97585040..3ee3a8f1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.9.12 + 1.10.0 false diff --git a/Microsoft.Kiota.sln b/Microsoft.Kiota.sln index 61af83d9..96ec5f6c 100644 --- a/Microsoft.Kiota.sln +++ b/Microsoft.Kiota.sln @@ -44,7 +44,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Kiota.Serializati EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Kiota.Serialization.Text.Tests", "tests\serialization\text\Microsoft.Kiota.Serialization.Text.Tests.csproj", "{5F6AC278-C4A4-4EED-A7D3-1750A4D6FD15}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Kiota.Trimming.Validation", "tests\trimming\Microsoft.Kiota.Trimming.Validation\Microsoft.Kiota.Trimming.Validation.csproj", "{13992912-662D-4A3B-9354-DD49DB1AC2D5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Kiota.Trimming.Validation", "tests\trimming\Microsoft.Kiota.Trimming.Validation\Microsoft.Kiota.Trimming.Validation.csproj", "{13992912-662D-4A3B-9354-DD49DB1AC2D5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Kiota.Bundle", "src\bundle\Microsoft.Kiota.Bundle.csproj", "{3F1F2EF2-8C57-4FC2-9722-68FAE551D19E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Kiota.Bundle.Tests", "tests\bundle\Microsoft.Kiota.Bundle.Tests.csproj", "{A1155A75-88FB-4C21-AA96-240A0E69FF1A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -116,6 +120,14 @@ Global {13992912-662D-4A3B-9354-DD49DB1AC2D5}.Debug|Any CPU.Build.0 = Debug|Any CPU {13992912-662D-4A3B-9354-DD49DB1AC2D5}.Release|Any CPU.ActiveCfg = Release|Any CPU {13992912-662D-4A3B-9354-DD49DB1AC2D5}.Release|Any CPU.Build.0 = Release|Any CPU + {3F1F2EF2-8C57-4FC2-9722-68FAE551D19E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F1F2EF2-8C57-4FC2-9722-68FAE551D19E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F1F2EF2-8C57-4FC2-9722-68FAE551D19E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F1F2EF2-8C57-4FC2-9722-68FAE551D19E}.Release|Any CPU.Build.0 = Release|Any CPU + {A1155A75-88FB-4C21-AA96-240A0E69FF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1155A75-88FB-4C21-AA96-240A0E69FF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1155A75-88FB-4C21-AA96-240A0E69FF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1155A75-88FB-4C21-AA96-240A0E69FF1A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/README.md b/README.md index ef2d6a29..b0ed0284 100644 --- a/README.md +++ b/README.md @@ -12,15 +12,16 @@ Read more about Kiota [here](https://github.com/microsoft/kiota/blob/main/README ## Libraries -| Library | Nuget Release | -| ------ | ------ | -| [Abstractions](./src/abstractions/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Abstractions?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Abstractions/) | -| [Authentication - Azure](./src/authentication/azure/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Authentication.Azure?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Authentication.Azure/) | -| [Http - HttpClientLibrary](./src/http/httpClient/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Http.HttpClientLibrary?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Http.HttpClientLibrary/) | -| [Serialization - JSON](./src/serialization/json/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Serialization.Json?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Serialization.Json/) | -| [Serialization - FORM](./src/serialization/form/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Serialization.Form?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Serialization.Form/) | -| [Serialization - TEXT](./src/serialization/text/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Serialization.Text?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Serialization.Text/) | +| Library | Nuget Release | +|----------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [Abstractions](./src/abstractions/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Abstractions?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Abstractions/) | +| [Authentication - Azure](./src/authentication/azure/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Authentication.Azure?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Authentication.Azure/) | +| [Http - HttpClientLibrary](./src/http/httpClient/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Http.HttpClientLibrary?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Http.HttpClientLibrary/) | +| [Serialization - JSON](./src/serialization/json/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Serialization.Json?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Serialization.Json/) | +| [Serialization - FORM](./src/serialization/form/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Serialization.Form?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Serialization.Form/) | +| [Serialization - TEXT](./src/serialization/text/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Serialization.Text?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Serialization.Text/) | | [Serialization - MULTIPART](./src/serialization/multipart/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Serialization.Multipart?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Serialization.Multipart/) | +| [Bundle](./src/bundle/README.md) | [![NuGet Version](https://buildstats.info/nuget/Microsoft.Kiota.Bundle?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Kiota.Bundle/) | ## Release notes diff --git a/src/bundle/DefaultRequestAdapter.cs b/src/bundle/DefaultRequestAdapter.cs new file mode 100644 index 00000000..c4fd6a3c --- /dev/null +++ b/src/bundle/DefaultRequestAdapter.cs @@ -0,0 +1,47 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +using System.Net.Http; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Abstractions.Authentication; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Http.HttpClientLibrary; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; + +namespace Microsoft.Kiota.Bundle +{ + /// + /// The implementation that derived from with registrations configured. + /// + public class DefaultRequestAdapter : HttpClientRequestAdapter + { + /// + /// Initializes a new instance of the class. + /// + /// The authentication provider. + /// The parse node factory. + /// The serialization writer factory. + /// The native HTTP client. + /// The observability options. + public DefaultRequestAdapter(IAuthenticationProvider authenticationProvider, IParseNodeFactory? parseNodeFactory = null, ISerializationWriterFactory? serializationWriterFactory = null, HttpClient? httpClient = null, ObservabilityOptions? observabilityOptions = null) : base(authenticationProvider, parseNodeFactory, serializationWriterFactory, httpClient, observabilityOptions) + { + SetupDefaults(); + } + + private static void SetupDefaults() + { + // Setup the default serializers/deserializers + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} diff --git a/src/bundle/Microsoft.Kiota.Bundle.csproj b/src/bundle/Microsoft.Kiota.Bundle.csproj new file mode 100644 index 00000000..b5bd3e1c --- /dev/null +++ b/src/bundle/Microsoft.Kiota.Bundle.csproj @@ -0,0 +1,21 @@ + + + + + Kiota Bundle package providing default implementations for client setup. + Kiota Bundle package for dotnet + + netstandard2.0;netstandard2.1;net5.0;net6.0;net8.0 + true + + + + + + + + + + + + diff --git a/src/bundle/README.md b/src/bundle/README.md new file mode 100644 index 00000000..ad4e8708 --- /dev/null +++ b/src/bundle/README.md @@ -0,0 +1,38 @@ +# Kiota Bundle Library for dotnet + +The Kiota Bundle Library for dotnet is the dotnet library providing default implementations for client setup. +The package provides a request adapter implementation with defaults serialization libraries setup fo use with a generated Kiota client. + +Read more about Kiota [here](https://github.com/microsoft/kiota/blob/main/README.md). + +## Using the Bundle Library + +```shell +dotnet add package Microsoft.Kiota.Bundle +``` + +## Debugging + +If you are using Visual Studio Code as your IDE, the **launch.json** file already contains the configuration to build and test the library. Otherwise, you can open the **Microsoft.Kiota.Abstractions.sln** with Visual Studio. + +## Contributing + +This project welcomes contributions and suggestions. Most contributions require you to agree to a +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us +the rights to use your contribution. For details, visit [https://cla.opensource.microsoft.com](https://cla.opensource.microsoft.com). + +When you submit a pull request, a CLA bot will automatically determine whether you need to provide +a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions +provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or +contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + +## Trademarks + +This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft +trademarks or logos is subject to and must follow +[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general). +Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. +Any use of third-party trademarks or logos are subject to those third-party's policies. diff --git a/tests/bundle/BundleTests.cs b/tests/bundle/BundleTests.cs new file mode 100644 index 00000000..addbe50e --- /dev/null +++ b/tests/bundle/BundleTests.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.Kiota.Abstractions.Authentication; +using Microsoft.Kiota.Abstractions.Serialization; +using Xunit; + +namespace Microsoft.Kiota.Bundle.Tests +{ + public class BundleTests + { + [Fact] + public void ThrowsArgumentNullExceptionOnNullAuthenticationProvider() + { + var exception = Assert.Throws(() => new DefaultRequestAdapter(null!)); + Assert.Equal("authenticationProvider", exception.ParamName); + } + + [Fact] + public void SerializersAreRegisteredAsExpected() + { + // setup + _ = new DefaultRequestAdapter(new AnonymousAuthenticationProvider()); + + // validate + var serializerCount = SerializationWriterFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories.Count; + var deserializerCount = ParseNodeFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories.Count; + + Assert.Equal(4, serializerCount); // four serializers present + Assert.Equal(3, deserializerCount);// three deserializers present + + var serializerKeys = SerializationWriterFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories.Keys; + var deserializerKeys = ParseNodeFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories.Keys; + + Assert.Contains("application/json", serializerKeys); + Assert.Contains("application/json", deserializerKeys);// Serializer and deserializer present for application/json + + Assert.Contains("text/plain", serializerKeys); + Assert.Contains("text/plain", deserializerKeys);// Serializer and deserializer present for text/plain + + Assert.Contains("application/x-www-form-urlencoded", serializerKeys); + Assert.Contains("application/x-www-form-urlencoded", deserializerKeys);// Serializer and deserializer present for application/x-www-form-urlencoded + + Assert.Contains("multipart/form-data", serializerKeys);// Serializer present for multipart/form-data + } + } +} diff --git a/tests/bundle/Microsoft.Kiota.Bundle.Tests.csproj b/tests/bundle/Microsoft.Kiota.Bundle.Tests.csproj new file mode 100644 index 00000000..d3bb6af6 --- /dev/null +++ b/tests/bundle/Microsoft.Kiota.Bundle.Tests.csproj @@ -0,0 +1,33 @@ + + + + true + net8.0;net462 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + \ No newline at end of file