AutoSDK.SourceGenerators 0.30.1-dev.106

This is a prerelease version of AutoSDK.SourceGenerators.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package AutoSDK.SourceGenerators --version 0.30.1-dev.106
                    
NuGet\Install-Package AutoSDK.SourceGenerators -Version 0.30.1-dev.106
                    
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.30.1-dev.106">
  <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.30.1-dev.106" />
                    
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.30.1-dev.106
                    
#r "nuget: AutoSDK.SourceGenerators, 0.30.1-dev.106"
                    
#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.30.1-dev.106
                    
#: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.30.1-dev.106&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AutoSDK.SourceGenerators&version=0.30.1-dev.106&prerelease
                    
Install as a Cake Tool

AutoSDK

The goal of this project is to automate and minimize the effort of maintaining high-quality .NET SDKs generated based on OpenAPI and AsyncAPI specifications, 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 AsyncAPI specs for WebSocket client generation (send/receive methods, cross-namespace schema referencing)
  • 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🚀

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" AutoSDK_OpenApiSpecification="true" />
</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.

Known Errors

Generator error: "Could not write to output file 'Path/to/file'. Could not find part of the path"

This error happens if the generated file path is too long. This happens if you didn't activated long path support on windows. To enable it follow the offical docs: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#registry-setting-to-enable-long-paths

AsyncAPI / WebSocket Support

AutoSDK can generate typed WebSocket clients from AsyncAPI 3.0 specifications, producing send/receive methods for each channel operation.

Basic Usage

autosdk generate asyncapi.yaml \
    --namespace MyApi.Realtime \
    --websocket-class-name MyRealtimeClient \
    --output Generated

This generates:

  • A WebSocket client class with connect/disconnect lifecycle
  • Typed Send* methods for publish operations
  • Typed Receive* methods (via event callbacks) for subscribe operations
  • All associated models, enums, and JSON converters

Cross-Namespace Schema Referencing

When an API has both REST (OpenAPI) and WebSocket (AsyncAPI) specs that share model types, you can generate them into separate namespaces while avoiding model duplication:

# Step 1: Generate REST API (models + HTTP client) in main namespace
autosdk generate openapi.yaml \
    --namespace MyApi \
    --clientClassName MyApiClient \
    --output Generated

# Step 2: Generate WebSocket client referencing existing REST types
autosdk generate asyncapi.yaml \
    --namespace MyApi.Realtime \
    --websocket-class-name MyRealtimeClient \
    --types-namespace MyApi \
    --generate-models false \
    --json-serializer-context MyApi.SourceGenerationContext \
    --output Generated

Key options:

  • --types-namespace <ns> — Generated WebSocket client uses global::<ns>.{TypeName} references instead of its own namespace
  • --generate-models false — Skips model/enum/converter generation (they already exist in the types namespace)
  • --json-serializer-context <ctx> — References an existing JsonSerializerContext from the types namespace
  • --websocket-class-name <name> — Overrides the generated WebSocket client class name

Note: AsyncAPI schema names must match the target namespace's type names. If they differ (e.g., OpenAI where AsyncAPI uses different names), use separate namespaces with full model generation instead.

Real-world examples

🤖 Claude Code Skill

AutoSDK is available as a Claude Code skill via skills.sh, enabling AI-assisted SDK generation directly from your terminal.

Install

npx skills add tryAGI/AutoSDK@generating-dotnet-sdks

Usage

Once installed, you can use natural language prompts in Claude Code like:

  • "Generate a C# SDK from this OpenAPI spec"
  • "Scaffold a new AutoSDK project for the Stripe API"
  • "Help me customize the generated client with streaming support"

Claude Code will use the skill's knowledge of AutoSDK CLI options, project conventions, and customization patterns to produce correct commands and code.

What's included

The skill provides Claude Code with detailed knowledge of:

  • CLI commands and all their options (generate, init, http, ai spec-from-docs)
  • Standard project structure and the generate.sh regeneration pattern
  • AsyncAPI / WebSocket client generation and cross-namespace schema referencing
  • Post-generation customization (partial classes, client hooks, trimming support)
  • Troubleshooting common issues

Skill source: skills/generating-dotnet-sdks/

📚Examples of use in real SDKs📚

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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.30.1-dev.113 0 3/21/2026
0.30.1-dev.112 0 3/21/2026
0.30.1-dev.111 0 3/21/2026
0.30.1-dev.110 0 3/21/2026
0.30.1-dev.109 0 3/21/2026
0.30.1-dev.108 0 3/21/2026
0.30.1-dev.107 18 3/21/2026
0.30.1-dev.106 17 3/21/2026
0.30.1-dev.105 18 3/21/2026
0.30.1-dev.104 23 3/21/2026
0.30.1-dev.102 19 3/21/2026
0.30.1-dev.101 17 3/21/2026
0.30.1-dev.100 20 3/21/2026
0.30.1-dev.99 17 3/21/2026
0.30.1-dev.98 17 3/21/2026
0.30.1-dev.97 17 3/21/2026
0.30.1-dev.96 25 3/21/2026
0.30.1-dev.95 24 3/21/2026
0.30.1-dev.94 22 3/21/2026
0.30.0 80 3/15/2026
Loading failed

⭐ Last 10 features:
- feat: Native upstream AsyncAPI spec support — inline payloads, per-channel servers, operationTraits 2026-03-21
- feat: Add const discriminator support for AsyncAPI specs 2026-03-21
- feat: Add unit tests for DeriveNameFromMethodAndPath and strip more version prefixes 2026-03-21
- feat: Derive request/response type names from method+path when operationId is missing (#181) 2026-03-21
- feat: Support multi-channel AsyncAPI specs (#183) 2026-03-21
- docs: Add AsyncAPI / WebSocket support documentation to README 2026-03-21
- feat: Enable UseExtensionNaming by default with proper sub-client generation 2026-03-21
- feat: Support 14 OpenAPI x- extensions for improved SDK generation 2026-03-20
- feat: Add discriminated union support for WebSocket receive events 2026-03-20
- feat: Add AsyncAPI spec support for WebSocket client code generation 2026-03-19
🐞 Last 10 bug fixes:
- feat: Native upstream AsyncAPI spec support — inline payloads, per-channel servers, operationTraits 2026-03-21
- fix: Use CSharpTypeNullability for AnyOf ?. operator too 2026-03-21
- fix: Use CSharpTypeNullability instead of IsRequired for enum ?. operator (#179) 2026-03-21
- fix: Handle bool in AnyOf ToString, add tests, remove dead code 2026-03-21
- fix: Serialize bool query params as lowercase 'true'/'false' 2026-03-21
- perf: Cache compiled regex in MethodAndPathGenerator 2026-03-21
- fix: Normalize trailing slashes in path-derived type names 2026-03-21
- feat: Add unit tests for DeriveNameFromMethodAndPath and strip more version prefixes 2026-03-21
- docs: Clarify --websocket-class-name behavior for multi-channel specs 2026-03-21
- perf: Extract keyword escape dictionary, fix CA warnings, add benchmark test 2026-03-21