AutoSDK.SourceGenerators 0.27.1-dev.30

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.27.1-dev.30                
NuGet\Install-Package AutoSDK.SourceGenerators -Version 0.27.1-dev.30                
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.27.1-dev.30">
  <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.
paket add AutoSDK.SourceGenerators --version 0.27.1-dev.30                
#r "nuget: AutoSDK.SourceGenerators, 0.27.1-dev.30"                
#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.
// Install AutoSDK.SourceGenerators as a Cake Addin
#addin nuget:?package=AutoSDK.SourceGenerators&version=0.27.1-dev.30&prerelease

// Install AutoSDK.SourceGenerators as a Cake Tool
#tool nuget:?package=AutoSDK.SourceGenerators&version=0.27.1-dev.30&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🚀

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:
    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.27.1-dev.44 30 11/27/2024
0.27.1-dev.43 31 11/27/2024
0.27.1-dev.37 34 11/19/2024
0.27.1-dev.35 34 11/14/2024
0.27.1-dev.33 30 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 31 11/13/2024
0.27.1-dev.25 31 11/13/2024
0.27.1-dev.22 38 11/12/2024
0.27.1-dev.21 38 11/12/2024
0.27.1-dev.20 35 11/12/2024
0.27.1-dev.9 38 11/6/2024
0.27.1-dev.3 39 11/2/2024
0.27.1-dev.2 34 11/2/2024
0.27.0 88 10/30/2024
0.26.1-dev.73 35 10/26/2024
0.26.1-dev.70 37 10/24/2024
0.26.1-dev.68 38 10/24/2024
0.26.1-dev.67 36 10/24/2024
0.26.1-dev.66 34 10/24/2024
0.26.1-dev.65 34 10/24/2024
0.26.1-dev.64 39 10/22/2024
0.26.1-dev.63 39 10/22/2024
0.26.1-dev.61 90 10/18/2024
0.26.1-dev.60 89 10/18/2024
0.26.1-dev.58 37 10/18/2024
0.26.1-dev.53 39 10/16/2024
0.26.1-dev.46 47 10/13/2024
0.26.1-dev.45 44 10/13/2024
0.26.1-dev.44 40 10/13/2024
0.26.1-dev.42 43 10/12/2024
0.26.1-dev.37 41 10/12/2024
0.26.1-dev.36 41 10/12/2024
0.26.1-dev.33 41 10/11/2024
0.26.1-dev.32 41 10/11/2024
0.26.1-dev.29 41 10/11/2024
0.26.1-dev.28 40 10/11/2024
0.26.1-dev.27 46 10/11/2024
0.26.1-dev.25 42 10/11/2024
0.26.1-dev.24 39 10/11/2024
0.26.1-dev.17 44 10/8/2024
0.26.1-dev.13 51 10/3/2024
0.26.1-dev.12 48 10/3/2024
0.26.1-dev.11 43 10/3/2024
0.26.1-dev.10 43 10/3/2024
0.26.1-dev.9 39 10/3/2024
0.26.1-dev.4 40 10/1/2024
0.26.1-dev.3 43 10/1/2024
0.26.1-dev.2 41 10/1/2024
0.26.1-dev.1 46 10/1/2024
0.26.0 113 10/1/2024
0.25.0 85 10/1/2024
0.24.1-dev.68 57 10/1/2024
0.24.1-dev.67 48 10/1/2024
0.24.1-dev.66 42 10/1/2024
0.24.1-dev.56 49 9/23/2024
0.24.1-dev.54 44 9/22/2024
0.24.1-dev.53 41 9/22/2024
0.24.1-dev.52 47 9/22/2024
0.24.1-dev.51 43 9/22/2024
0.24.1-dev.50 46 9/22/2024
0.24.1-dev.49 43 9/22/2024
0.24.1-dev.47 46 9/22/2024
0.24.1-dev.44 45 9/21/2024
0.24.1-dev.41 46 9/20/2024
0.24.1-dev.40 39 9/20/2024
0.24.1-dev.39 41 9/20/2024
0.24.1-dev.33 60 9/17/2024
0.24.1-dev.31 37 9/17/2024
0.24.1-dev.28 57 9/15/2024
0.24.1-dev.27 42 9/15/2024
0.24.1-dev.26 50 9/14/2024
0.24.1-dev.25 45 9/14/2024
0.24.1-dev.24 44 9/12/2024
0.24.1-dev.23 47 9/12/2024
0.24.1-dev.22 52 9/11/2024
0.24.1-dev.19 49 9/11/2024
0.24.1-dev.18 46 9/11/2024
0.24.1-dev.15 48 9/11/2024
0.24.1-dev.14 56 9/11/2024
0.24.1-dev.13 53 9/11/2024
0.24.1-dev.11 57 9/11/2024
0.24.1-dev.10 55 9/11/2024
0.24.1-dev.9 49 9/11/2024
0.24.1-dev.8 50 9/11/2024
0.24.1-dev.7 51 9/11/2024
0.24.1-dev.2 50 9/10/2024
0.24.1-dev.1 61 9/10/2024
0.24.0 119 9/10/2024
0.23.1-dev.3 52 9/10/2024
0.23.1-dev.2 48 9/10/2024
0.23.1-dev.1 53 9/9/2024
0.23.0 109 9/9/2024
0.22.6-dev.10 56 9/9/2024

⭐ Last 10 features:
- feat: Replaced AnyOf JsonConverterFactory with explicit generic converters. 2024-11-13
- feat(cli): Use net9 in sln template. 2024-11-13
- feat: Added support for default responses. 2024-11-12
- feat: Initial support for non success responses(through exceptions) 2024-11-12
- feat: Initial work for System.ComponentModel.Annotations support. 2024-11-12
- feat: Added default/example block to xml doc. 2024-11-12
- feat: Added constructors with all values besides parameterless. 2024-11-12
- feat: Added Client.ReadResponseAsString property to enable debugging. Closes #20. 2024-11-12
- feat: Added PropertyData.Example. 2024-11-07
- feat: Generate FromJsonStream methods. 2024-11-07
🐞 Last 10 bug fixes:
- fix(cli): Now draft PRs will not trigger PR test pipeline. 2024-11-13
- fix(cli): Fixed mkdocs github actions template. 2024-11-13
- fix: Try to use response with schema for Success response if it there. 2024-11-13
- fix: Fixed xml doc for <defaul> tag. 2024-11-12
- fix: Fixed missing xml param doc for required deprecated properties. 2024-11-12
- fix: Now error responses have order. 2024-11-12
- fix: Use ApiException instead System.InvalidOperationException in methods. 2024-11-12
- fix: Fixed bug with OpenApi31Support for json exclusiveMinMax. 2024-11-07
- fix: Fixed issue with AnyOf object implicit conversion. 2024-11-07
- fix: Removed default headers for Multipart form data. 2024-11-03