AutoSDK 0.26.1-dev.73
See the version list below for details.
dotnet add package AutoSDK --version 0.26.1-dev.73
NuGet\Install-Package AutoSDK -Version 0.26.1-dev.73
<PackageReference Include="AutoSDK" Version="0.26.1-dev.73" />
paket add AutoSDK --version 0.26.1-dev.73
#r "nuget: AutoSDK, 0.26.1-dev.73"
// Install AutoSDK as a Cake Addin #addin nuget:?package=AutoSDK&version=0.26.1-dev.73&prerelease // Install AutoSDK as a Cake Tool #tool nuget:?package=AutoSDK&version=0.26.1-dev.73&prerelease
AutoSDK
The goal of this project is to automate and minimize the effort of maintaining high-quality .NET SDKs generated based on the OpenAPI specification, mainly to strengthen the AI ecosystem within .NET. The code generated by this library is also actively used in dozens of our various SDKs of varying complexity levels and in the LangChain.NET project, which ensures that it is tested in various scenarios and is ready for them.
Inspired by NSwag ❤️.
🔥Features🔥
- Detects your TargetFramework and generates optimal code for it (including net6.0/net7.0/net8.0 improvements)
- Supports .Net Framework/.Net Standard
- Supports OpenAPI 3.1 specs via internal conversion to OpenAPI 3.0 (includes support for nullability, examples, const)
- Does not contain dependencies for modern versions of dotnet.
- Only System.Text.Json dependency for .Net Framework/.Net Standard
- Any generated methods provide the ability to pass a CancellationToken
- Allows partial generation (models only) or end points filtering
- Available under MIT license for general users and most organizations
- Uses https://github.com/microsoft/OpenAPI.NET for parsing OpenAPI specification
- Supports nullable enable/trimming/native AOT compilation/CLS compliance
- Tested on GitHub 220k lines OpenAPI specification
- Supports OneOf/AnyOf/AllOf/Not schemas
- Supports Enums for System.Text.Json
- Supports SSE (Server-Sent Events) through the
application/x-ndjson
content type - Uses Incremental Source Generators for efficient generation and caching.
- Efficient O(n) implementation, fully suitable for large/super large OpenAPI specifications
- Used in 10+ real SDKs and adapted to solve various problems
🚀Quick start🚀
CLI (Recommended)
You can use the CLI to generate the code.
dotnet tool install --global autosdk.cli --prerelease
rm -rf Generated
autosdk generate openapi.yaml \
--namespace Namespace \
--clientClassName YourApi \
--targetFramework net8.0 \
--output Generated
It will generate the code in the "Generated" subdirectory.
It also will include polyfills for .Net Framework/.Net Standard TargetFrameworks.
Source generator
- Install the package
dotnet add package AutoSDK.SourceGenerators
- Add the following optional settings to your csproj file to customize generation. You can check all settings here:
<ItemGroup Label="AutoSDK">
<AdditionalFiles Include="$(MSBuildThisFileDirectory)../../../docs/openapi.yaml" />
</ItemGroup>
<PropertyGroup Label="AutoSDK">
<AutoSDK_Namespace>Ollama</AutoSDK_Namespace>
<AutoSDK_ClassName>OllamaApi</AutoSDK_ClassName>
<AutoSDK_GenerateSdk>false</AutoSDK_GenerateSdk>
<AutoSDK_GenerateModels>true</AutoSDK_GenerateModels>
<AutoSDK_GenerateMethods>true</AutoSDK_GenerateMethods>
<AutoSDK_GenerateConstructors>true</AutoSDK_GenerateConstructors>
<AutoSDK_IncludeOperationIds>getPet;deletePet</AutoSDK_IncludeOperationIds>
<AutoSDK_ExcludeOperationIds>getPet;deletePet</AutoSDK_ExcludeOperationIds>
<AutoSDK_IncludeModels>Pet;Model</AutoSDK_IncludeModels>
<AutoSDK_ExcludeModels>Pet;Model</AutoSDK_ExcludeModels>
</PropertyGroup>
- It's all! Now you can build your project and use the generated code. You also can use IDE to see the generated code in any moment, this is a example for Rider:
Trimming support
CLI
CLI generates Trimming/NativeAOT compatible code by default.
Source generator
Since there are two source generators involved, we will have to create a second project so that the generator for the JsonSerializerContext will “see” our models
- Create new project for your models. And disable methods/constructors generation:
<PropertyGroup Label="AutoSDK">
<AutoSDK_GenerateSdk>false</AutoSDK_GenerateSdk>
<AutoSDK_GenerateModels>true</AutoSDK_GenerateModels>
<AutoSDK_GenerateJsonSerializerContextTypes>true</AutoSDK_GenerateJsonSerializerContextTypes>
</PropertyGroup>
- Reference this project in your main project.
- Add
SourceGenerationContext.cs
file to your main project with the following content:
using System.Text.Json.Serialization;
namespace Namespace;
[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(AutoSDKTrimmableSupport))]
internal sealed partial class SourceGenerationContext : JsonSerializerContext;
- Add the following settings to your main csproj file:
<PropertyGroup Label="AutoSDK">
<AutoSDK_GenerateSdk>false</AutoSDK_GenerateSdk>
<AutoSDK_GenerateMethods>true</AutoSDK_GenerateMethods>
<AutoSDK_GenerateConstructors>true</AutoSDK_GenerateConstructors>
<AutoSDK_JsonSerializerContext>Namespace.SourceGenerationContext</AutoSDK_JsonSerializerContext>
</PropertyGroup>
- Add these settings to your new and main csproj file to enable trimming(or use Directory.Build.props file):
<PropertyGroup Label="Trimmable" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<IsAotCompatible>true</IsAotCompatible>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>
- It's all! Now you can build your project and use the generated code with full trimming/nativeAOT support.
📚Examples of use in real SDKs📚
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.OpenApi.Readers (>= 1.6.22)
- System.Collections.Immutable (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
.NETStandard 2.0
- Microsoft.OpenApi.Readers (>= 1.6.22)
- System.Collections.Immutable (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
net6.0
- Microsoft.OpenApi.Readers (>= 1.6.22)
- System.Collections.Immutable (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
net8.0
- Microsoft.OpenApi.Readers (>= 1.6.22)
- System.Collections.Immutable (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.27.1-dev.35 | 35 | 11/14/2024 |
0.27.1-dev.33 | 29 | 11/13/2024 |
0.27.1-dev.32 | 25 | 11/13/2024 |
0.27.1-dev.30 | 31 | 11/13/2024 |
0.27.1-dev.26 | 30 | 11/13/2024 |
0.27.1-dev.25 | 30 | 11/13/2024 |
0.27.1-dev.22 | 75 | 11/12/2024 |
0.27.1-dev.21 | 30 | 11/12/2024 |
0.27.1-dev.20 | 30 | 11/12/2024 |
0.27.1-dev.9 | 158 | 11/6/2024 |
0.27.1-dev.3 | 41 | 11/2/2024 |
0.27.1-dev.2 | 32 | 11/2/2024 |
0.27.0 | 1,059 | 10/30/2024 |
0.26.1-dev.73 | 521 | 10/26/2024 |
0.26.1-dev.70 | 69 | 10/24/2024 |
0.26.1-dev.68 | 33 | 10/24/2024 |
0.26.1-dev.67 | 35 | 10/24/2024 |
0.26.1-dev.66 | 35 | 10/24/2024 |
0.26.1-dev.65 | 32 | 10/24/2024 |
0.26.1-dev.64 | 34 | 10/22/2024 |
0.26.1-dev.63 | 37 | 10/22/2024 |
0.26.1-dev.61 | 443 | 10/18/2024 |
0.26.1-dev.60 | 82 | 10/18/2024 |
0.26.1-dev.58 | 35 | 10/18/2024 |
0.26.1-dev.53 | 55 | 10/16/2024 |
0.26.1-dev.46 | 392 | 10/13/2024 |
0.26.1-dev.45 | 39 | 10/13/2024 |
0.26.1-dev.44 | 35 | 10/13/2024 |
0.26.1-dev.42 | 85 | 10/12/2024 |
0.26.1-dev.37 | 70 | 10/12/2024 |
0.26.1-dev.36 | 36 | 10/12/2024 |
0.26.1-dev.33 | 42 | 10/11/2024 |
0.26.1-dev.32 | 46 | 10/11/2024 |
0.26.1-dev.29 | 39 | 10/11/2024 |
0.26.1-dev.28 | 37 | 10/11/2024 |
0.26.1-dev.27 | 41 | 10/11/2024 |
0.26.1-dev.25 | 44 | 10/11/2024 |
0.26.1-dev.24 | 38 | 10/11/2024 |
0.26.1-dev.17 | 43 | 10/8/2024 |
0.26.1-dev.13 | 116 | 10/3/2024 |
0.26.1-dev.12 | 41 | 10/3/2024 |
0.26.1-dev.11 | 995 | 10/3/2024 |
0.26.1-dev.10 | 41 | 10/3/2024 |
0.26.1-dev.9 | 39 | 10/3/2024 |
0.26.1-dev.4 | 38 | 10/1/2024 |
0.26.1-dev.3 | 31 | 10/1/2024 |
0.26.1-dev.2 | 36 | 10/1/2024 |
0.26.1-dev.1 | 44 | 10/1/2024 |
0.26.0 | 80 | 10/1/2024 |
0.25.0 | 87 | 10/1/2024 |
0.24.1-dev.68 | 46 | 10/1/2024 |
0.24.1-dev.67 | 43 | 10/1/2024 |
0.24.1-dev.66 | 45 | 10/1/2024 |
0.24.1-dev.56 | 45 | 9/23/2024 |
0.24.1-dev.54 | 39 | 9/22/2024 |
0.24.1-dev.53 | 42 | 9/22/2024 |
0.24.1-dev.52 | 44 | 9/22/2024 |
0.24.1-dev.51 | 42 | 9/22/2024 |
0.24.1-dev.50 | 39 | 9/22/2024 |
0.24.1-dev.49 | 44 | 9/22/2024 |
0.24.1-dev.47 | 42 | 9/22/2024 |
0.24.1-dev.44 | 45 | 9/21/2024 |
0.24.1-dev.41 | 47 | 9/20/2024 |
0.24.1-dev.40 | 41 | 9/20/2024 |
0.24.1-dev.39 | 39 | 9/20/2024 |
0.24.1-dev.33 | 59 | 9/17/2024 |
0.24.1-dev.31 | 36 | 9/17/2024 |
0.24.1-dev.28 | 57 | 9/15/2024 |
0.24.1-dev.27 | 49 | 9/15/2024 |
0.24.1-dev.26 | 50 | 9/14/2024 |
0.24.1-dev.25 | 49 | 9/14/2024 |
0.24.1-dev.24 | 43 | 9/12/2024 |
0.24.1-dev.23 | 43 | 9/12/2024 |
0.24.1-dev.22 | 53 | 9/11/2024 |
0.24.1-dev.19 | 47 | 9/11/2024 |
0.24.1-dev.18 | 44 | 9/11/2024 |
0.24.1-dev.15 | 50 | 9/11/2024 |
0.24.1-dev.14 | 46 | 9/11/2024 |
0.24.1-dev.13 | 45 | 9/11/2024 |
0.24.1-dev.11 | 56 | 9/11/2024 |
0.24.1-dev.10 | 47 | 9/11/2024 |
0.24.1-dev.9 | 46 | 9/11/2024 |
0.24.1-dev.8 | 45 | 9/11/2024 |
0.24.1-dev.7 | 50 | 9/11/2024 |
0.24.1-dev.2 | 50 | 9/10/2024 |
0.24.1-dev.1 | 48 | 9/10/2024 |
0.24.0 | 109 | 9/10/2024 |
0.23.1-dev.3 | 49 | 9/10/2024 |
0.23.1-dev.2 | 49 | 9/10/2024 |
0.23.1-dev.1 | 50 | 9/9/2024 |
0.23.0 | 115 | 9/9/2024 |
0.22.6-dev.10 | 59 | 9/9/2024 |
⭐ Last 10 features:
- feat: Use Discriminator mapping values for names AnyOf property names. 2024-10-26
- feat: Added Experimental attribute support. 2024-10-25
- feat: Removed default values - now I use it only in xml docs. 2024-10-24
- feat: Expose HttpClient. 2024-10-23
- feat: Additional work for discriminator support. 2024-10-18
- feat: Implemented ComputeDiscriminators. 2024-10-17
- feat: Added initial discriminator support. 2024-10-17
- feat: Added By separator for MethodAndPath naming convention. 2024-10-17
- feat: Added generation of discriminator classes. 2024-10-17
- feat: Added ToJson/FromJson methods to models. 2024-10-13
🐞 Last 10 bug fixes:
- fix: Fixed CLI. 2024-10-25
- fix: Fixed rare issue with AnyOf deserialization. 2024-10-24
- fix: Fixed issue with named OneOf JsonConverters. 2024-10-24
- fix: Fixed latest commit. 2024-10-23
- fix: Updated GitHub spec. Fixed issues with it. 2024-10-18
- fix: Removed nested OneOfs to unblock discriminator. 2024-10-17
- fix: Fixed issue with incorrect JsonConverter. 2024-10-17
- fix: Fixed issue with wrong #if NET6_0_OR_GREATER 2024-10-13
- fix: Added missing xml docs for latest commit. 2024-10-13
- fix: Fixed null in enums in OpenAPI 3.1 yaml. 2024-10-12