AutoSDK.SourceGenerators 0.24.1-dev.28

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.28
                    
NuGet\Install-Package AutoSDK.SourceGenerators -Version 0.24.1-dev.28
                    
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.28">
  <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.28" />
                    
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.28
                    
#r "nuget: AutoSDK.SourceGenerators, 0.24.1-dev.28"
                    
#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.
#addin nuget:?package=AutoSDK.SourceGenerators&version=0.24.1-dev.28&prerelease
                    
Install AutoSDK.SourceGenerators as a Cake Addin
#tool nuget:?package=AutoSDK.SourceGenerators&version=0.24.1-dev.28&prerelease
                    
Install AutoSDK.SourceGenerators 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.40 194 10 days ago
0.28.1-dev.39 193 13 days ago
0.28.1-dev.38 178 14 days ago
0.28.1-dev.36 45 16 days ago
0.28.1-dev.34 112 17 days ago
0.28.1-dev.31 109 18 days ago
0.28.1-dev.30 106 18 days ago
0.28.1-dev.29 108 18 days ago
0.28.1-dev.27 109 18 days ago
0.28.1-dev.26 109 18 days ago
0.28.1-dev.24 112 18 days ago
0.28.1-dev.23 109 20 days ago
0.28.1-dev.20 156 a month ago
0.28.1-dev.18 400 2 months ago
0.28.1-dev.17 119 2 months ago
0.28.1-dev.16 144 2 months ago
0.28.1-dev.15 110 2 months ago
0.28.1-dev.8 107 2 months ago
0.28.1-dev.7 106 2 months ago
0.28.1-dev.4 105 2 months ago
0.28.1-dev.2 175 3 months ago
0.28.0 222 3 months ago
0.27.1-dev.89 201 3 months ago
0.27.1-dev.88 59 3 months ago
0.27.1-dev.87 96 3 months ago
0.27.1-dev.86 54 3 months ago
0.27.1-dev.85 58 3 months ago
0.27.1-dev.84 56 3 months ago
0.27.1-dev.76 71 4 months ago
0.27.1-dev.70 66 5 months ago
0.27.1-dev.69 47 5 months ago
0.27.1-dev.68 53 5 months ago
0.27.1-dev.65 63 5 months ago
0.27.1-dev.64 63 5 months ago
0.27.1-dev.59 64 6 months ago
0.27.1-dev.57 62 6 months ago
0.27.1-dev.53 61 6 months ago
0.27.1-dev.52 53 6 months ago
0.27.1-dev.44 53 6 months ago
0.27.1-dev.43 53 6 months ago
0.27.1-dev.37 53 6 months ago
0.27.1-dev.35 57 6 months ago
0.27.1-dev.33 53 6 months ago
0.27.1-dev.32 50 6 months ago
0.27.1-dev.30 62 6 months ago
0.27.1-dev.26 51 6 months ago
0.27.1-dev.25 57 6 months ago
0.27.1-dev.22 56 6 months ago
0.27.1-dev.21 55 6 months ago
0.27.1-dev.20 52 6 months ago
0.27.1-dev.9 56 7 months ago
0.27.1-dev.3 57 7 months ago
0.27.1-dev.2 60 7 months ago
0.27.0 157 7 months ago
0.26.1-dev.73 53 7 months ago
0.26.1-dev.70 54 7 months ago
0.26.1-dev.68 55 7 months ago
0.26.1-dev.67 53 7 months ago
0.26.1-dev.66 55 7 months ago
0.26.1-dev.65 55 7 months ago
0.26.1-dev.64 59 7 months ago
0.26.1-dev.63 57 7 months ago
0.26.1-dev.61 109 7 months ago
0.26.1-dev.60 111 7 months ago
0.26.1-dev.58 51 7 months ago
0.26.1-dev.53 53 7 months ago
0.26.1-dev.46 63 7 months ago
0.26.1-dev.45 58 7 months ago
0.26.1-dev.44 55 7 months ago
0.26.1-dev.42 59 7 months ago
0.26.1-dev.37 55 7 months ago
0.26.1-dev.36 56 7 months ago
0.26.1-dev.33 55 7 months ago
0.26.1-dev.32 57 7 months ago
0.26.1-dev.29 55 7 months ago
0.26.1-dev.28 56 7 months ago
0.26.1-dev.27 64 7 months ago
0.26.1-dev.25 57 7 months ago
0.26.1-dev.24 51 7 months ago
0.26.1-dev.17 60 8 months ago
0.26.1-dev.13 66 8 months ago
0.26.1-dev.12 64 8 months ago
0.26.1-dev.11 59 8 months ago
0.26.1-dev.10 57 8 months ago
0.26.1-dev.9 53 8 months ago
0.26.1-dev.4 55 8 months ago
0.26.1-dev.3 58 8 months ago
0.26.1-dev.2 58 8 months ago
0.26.1-dev.1 61 8 months ago
0.26.0 158 8 months ago
0.25.0 105 8 months ago
0.24.1-dev.68 72 8 months ago
0.24.1-dev.67 62 8 months ago
0.24.1-dev.66 56 8 months ago
0.24.1-dev.56 63 8 months ago
0.24.1-dev.54 58 8 months ago
0.24.1-dev.53 55 8 months ago
0.24.1-dev.52 63 8 months ago
0.24.1-dev.51 57 8 months ago
0.24.1-dev.50 60 8 months ago
0.24.1-dev.49 57 8 months ago
0.24.1-dev.47 60 8 months ago
0.24.1-dev.44 59 8 months ago
0.24.1-dev.41 63 8 months ago
0.24.1-dev.40 55 8 months ago
0.24.1-dev.39 54 8 months ago
0.24.1-dev.33 74 8 months ago
0.24.1-dev.31 53 8 months ago
0.24.1-dev.28 70 8 months ago
0.24.1-dev.27 56 8 months ago
0.24.1-dev.26 64 8 months ago
0.24.1-dev.25 62 8 months ago
0.24.1-dev.24 57 8 months ago
0.24.1-dev.23 62 8 months ago
0.24.1-dev.22 65 8 months ago
0.24.1-dev.19 63 8 months ago
0.24.1-dev.18 62 8 months ago
0.24.1-dev.15 64 8 months ago
0.24.1-dev.14 70 8 months ago
0.24.1-dev.13 73 8 months ago
0.24.1-dev.11 72 8 months ago
0.24.1-dev.10 71 8 months ago
0.24.1-dev.9 63 8 months ago
0.24.1-dev.8 62 8 months ago
0.24.1-dev.7 66 8 months ago
0.24.1-dev.2 64 9 months ago
0.24.1-dev.1 75 9 months ago
0.24.0 136 9 months ago
0.23.1-dev.3 63 9 months ago
0.23.1-dev.2 61 9 months ago
0.23.1-dev.1 65 9 months ago
0.23.0 126 9 months ago
0.22.6-dev.10 70 9 months ago

⭐ Last 10 features:
- feat: Added interfaces. 2024-09-15
- 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
🐞 Last 10 bug fixes:
- fix: Removed BaseUrl from interfaces. 2024-09-15
- 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