AutoSDK.SourceGenerators 0.24.1-dev.26

This is a prerelease version of AutoSDK.SourceGenerators.
There is a newer version of this package available.
See the version list below for details.
dotnet add package AutoSDK.SourceGenerators --version 0.24.1-dev.26
                    
NuGet\Install-Package AutoSDK.SourceGenerators -Version 0.24.1-dev.26
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoSDK.SourceGenerators" Version="0.24.1-dev.26">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoSDK.SourceGenerators" Version="0.24.1-dev.26" />
                    
Directory.Packages.props
<PackageReference Include="AutoSDK.SourceGenerators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AutoSDK.SourceGenerators --version 0.24.1-dev.26
                    
#r "nuget: AutoSDK.SourceGenerators, 0.24.1-dev.26"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AutoSDK.SourceGenerators@0.24.1-dev.26
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AutoSDK.SourceGenerators&version=0.24.1-dev.26&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AutoSDK.SourceGenerators&version=0.24.1-dev.26&prerelease
                    
Install as a Cake Tool

AutoSDK

Allows you to partially (for example, only models) or completely generate a native (without dependencies) C# client sdk according to the OpenAPI specification.
Inspired by NSwag ❤️.

🔥Features🔥

  • Uses Incremental Source Generators for efficient generation and caching.
  • Detects your TargetFramework and generates optimal code for it (including net6.0/net7.0/net8.0 improvements)
  • Supports .Net Framework/.Net Standard
  • 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
  • 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🚀

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
  • 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:
    rider_show_generated_code.png

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📚

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

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.28.1-dev.114 40 1/21/2026
0.28.1-dev.113 30 1/21/2026
0.28.1-dev.75 5,350 6/30/2025
0.28.1-dev.74 148 6/25/2025
0.28.1-dev.73 137 6/25/2025
0.28.1-dev.72 137 6/25/2025
0.28.1-dev.71 136 6/25/2025
0.28.1-dev.70 137 6/25/2025
0.28.1-dev.67 144 6/24/2025
0.28.1-dev.66 139 6/24/2025
0.28.1-dev.64 144 6/24/2025
0.28.1-dev.63 139 6/24/2025
0.28.1-dev.62 139 6/23/2025
0.28.1-dev.60 154 6/18/2025
0.28.1-dev.59 141 6/18/2025
0.28.1-dev.58 164 6/17/2025
0.28.1-dev.57 142 6/17/2025
0.28.1-dev.55 141 6/17/2025
0.28.1-dev.53 146 6/17/2025
0.28.1-dev.50 149 6/17/2025
0.28.1-dev.47 487 6/5/2025
0.28.1-dev.46 187 6/5/2025
0.28.1-dev.45 155 6/5/2025
0.28.1-dev.40 348 5/15/2025
0.28.1-dev.39 234 5/13/2025
0.28.1-dev.38 225 5/12/2025
0.28.1-dev.36 86 5/9/2025
0.28.1-dev.34 151 5/8/2025
0.28.1-dev.31 152 5/8/2025
0.28.1-dev.30 148 5/8/2025
0.28.1-dev.29 156 5/7/2025
0.28.1-dev.27 154 5/7/2025
0.28.1-dev.26 154 5/7/2025
0.28.1-dev.24 149 5/7/2025
0.28.1-dev.23 155 5/6/2025
0.28.1-dev.20 197 4/17/2025
0.28.1-dev.18 492 4/10/2025
0.28.1-dev.17 158 4/10/2025
0.28.1-dev.16 185 3/30/2025
0.28.1-dev.15 154 3/30/2025
0.28.1-dev.8 155 3/21/2025
0.28.1-dev.7 142 3/21/2025
0.28.1-dev.4 144 3/14/2025
0.28.1-dev.2 213 3/6/2025
0.28.0 350 3/5/2025
0.27.1-dev.89 248 2/28/2025
0.27.1-dev.88 109 2/27/2025
0.27.1-dev.87 136 2/26/2025
0.27.1-dev.86 86 2/26/2025
0.27.1-dev.85 97 2/26/2025
0.27.1-dev.84 91 2/26/2025
0.27.1-dev.76 104 2/7/2025
0.27.1-dev.70 99 1/7/2025
0.27.1-dev.69 78 1/7/2025
0.27.1-dev.68 89 1/7/2025
0.27.1-dev.65 111 12/22/2024
0.27.1-dev.64 103 12/17/2024
0.27.1-dev.59 97 12/9/2024
0.27.1-dev.57 96 12/8/2024
0.27.1-dev.53 93 12/4/2024
0.27.1-dev.52 87 12/3/2024
0.27.1-dev.44 98 11/27/2024
0.27.1-dev.43 97 11/27/2024
0.27.1-dev.37 97 11/19/2024
0.27.1-dev.35 94 11/14/2024
0.27.1-dev.33 95 11/13/2024
0.27.1-dev.32 85 11/13/2024
0.27.1-dev.30 98 11/13/2024
0.27.1-dev.26 83 11/13/2024
0.27.1-dev.25 95 11/13/2024
0.27.1-dev.22 89 11/12/2024
0.27.1-dev.21 93 11/12/2024
0.27.1-dev.20 90 11/12/2024
0.27.1-dev.9 95 11/6/2024
0.27.1-dev.3 97 11/2/2024
0.27.1-dev.2 97 11/2/2024
0.27.0 256 10/30/2024
0.26.1-dev.73 87 10/26/2024
0.26.1-dev.70 95 10/24/2024
0.26.1-dev.68 94 10/24/2024
0.26.1-dev.67 92 10/24/2024
0.26.1-dev.66 85 10/24/2024
0.26.1-dev.65 90 10/24/2024
0.26.1-dev.64 103 10/22/2024
0.26.1-dev.63 95 10/22/2024
0.26.1-dev.61 141 10/18/2024
0.26.1-dev.60 143 10/18/2024
0.26.1-dev.58 88 10/18/2024
0.26.1-dev.53 85 10/16/2024
0.26.1-dev.46 97 10/13/2024
0.26.1-dev.45 92 10/13/2024
0.26.1-dev.44 95 10/13/2024
0.26.1-dev.42 92 10/12/2024
0.26.1-dev.37 87 10/12/2024
0.26.1-dev.36 93 10/12/2024
0.26.1-dev.33 90 10/11/2024
0.26.1-dev.32 89 10/11/2024
0.26.1-dev.29 101 10/11/2024
0.26.1-dev.28 87 10/11/2024
0.26.1-dev.27 108 10/11/2024
0.26.1-dev.25 91 10/11/2024
0.26.1-dev.24 79 10/11/2024
0.26.1-dev.17 88 10/8/2024
0.26.1-dev.13 104 10/3/2024
0.26.1-dev.12 107 10/3/2024
0.26.1-dev.11 99 10/3/2024
0.26.1-dev.10 92 10/3/2024
0.26.1-dev.9 94 10/3/2024
0.26.1-dev.4 90 10/1/2024
0.26.1-dev.3 89 10/1/2024
0.26.1-dev.2 95 10/1/2024
0.26.1-dev.1 95 10/1/2024
0.26.0 216 10/1/2024
0.25.0 157 10/1/2024
0.24.1-dev.68 108 10/1/2024
0.24.1-dev.67 96 10/1/2024
0.24.1-dev.66 96 10/1/2024
0.24.1-dev.56 99 9/23/2024
0.24.1-dev.54 96 9/22/2024
0.24.1-dev.53 93 9/22/2024
0.24.1-dev.52 103 9/22/2024
0.24.1-dev.51 96 9/22/2024
0.24.1-dev.50 104 9/22/2024
0.24.1-dev.49 92 9/22/2024
0.24.1-dev.47 94 9/22/2024
0.24.1-dev.44 96 9/21/2024
0.24.1-dev.41 99 9/20/2024
0.24.1-dev.40 95 9/20/2024
0.24.1-dev.39 86 9/20/2024
0.24.1-dev.33 112 9/17/2024
0.24.1-dev.31 97 9/17/2024
0.24.1-dev.28 108 9/15/2024
0.24.1-dev.27 100 9/15/2024
0.24.1-dev.26 102 9/14/2024
0.24.1-dev.25 104 9/14/2024
0.24.1-dev.24 96 9/12/2024
0.24.1-dev.23 91 9/12/2024
0.24.1-dev.22 109 9/11/2024
0.24.1-dev.19 95 9/11/2024
0.24.1-dev.18 95 9/11/2024
0.24.1-dev.15 96 9/11/2024
0.24.1-dev.14 104 9/11/2024
0.24.1-dev.13 115 9/11/2024
0.24.1-dev.11 105 9/11/2024
0.24.1-dev.10 107 9/11/2024
0.24.1-dev.9 98 9/11/2024
0.24.1-dev.8 100 9/11/2024
0.24.1-dev.7 100 9/11/2024
0.24.1-dev.2 97 9/10/2024
0.24.1-dev.1 111 9/10/2024
0.24.0 181 9/10/2024
0.23.1-dev.3 99 9/10/2024
0.23.1-dev.2 99 9/10/2024
0.23.1-dev.1 98 9/9/2024
0.23.0 183 9/9/2024
0.22.6-dev.10 101 9/9/2024

⭐ Last 10 features:
- feat: Added ability to override JsonSerializerContext. 2024-09-14
- feat: Added Summary MethodNamingConvention. 2024-09-12
- feat: Added uuid format support as System.Guid. 2024-09-10
- feat: Renamed to AutoSDK. 2024-09-09
- feat: Updated MinVer/Microsoft.OpenAPI 2024-09-07
- feat: Added OpenApiDocument Simplify extension. 2024-09-06
- feat: Added xml doc for Named AnyOfs. 2024-09-06
- feat: Added Unix timestamp detection. 2024-08-30
- feat: Added partial methods for constructors te set up/validate things. 2024-08-29
- feat: Added OperationContext. 2024-08-28
🐞 Last 10 bug fixes:
- fix: Removed usage of AutoSDK namespace in generated code. 2024-09-14
- fix: Fixed issue with Summary naming and collisions. 2024-09-12
- fix: Fixed issue with Summary naming and collisions. 2024-09-12
- fix: Fixed some issues with Summary method name generator. 2024-09-12
- fix: Fixed settings binding in cli. 2024-09-12
- fix: Fixed HeyGen xml doc issue. 2024-09-12
- fix: Fixed small issue with warnings in xml doc. 2024-09-11
- fix: Fixed issue with trimming for guid support. 2024-09-11
- fix: Don't use System namespace for AnyOf like types. 2024-09-10
- fix: Fixed CLI tool command name. 2024-09-10