AutoSDK.CLI
0.24.1-dev.68
See the version list below for details.
dotnet tool install --global AutoSDK.CLI --version 0.24.1-dev.68
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local AutoSDK.CLI --version 0.24.1-dev.68
#tool dotnet:?package=AutoSDK.CLI&version=0.24.1-dev.68&prerelease
nuke :add-package AutoSDK.CLI --version 0.24.1-dev.68
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🔥
- 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
- Supports SSE (Server-Sent Events) through the
application/x-ndjson
content type - 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 | 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. |
This package has no dependencies.
Version | Downloads | Last updated |
---|---|---|
0.27.1-dev.37 | 1,343 | 11/19/2024 |
0.27.1-dev.35 | 1,516 | 11/14/2024 |
0.27.1-dev.33 | 158 | 11/13/2024 |
0.27.1-dev.32 | 62 | 11/13/2024 |
0.27.1-dev.30 | 48 | 11/13/2024 |
0.27.1-dev.26 | 71 | 11/13/2024 |
0.27.1-dev.25 | 52 | 11/13/2024 |
0.27.1-dev.22 | 284 | 11/12/2024 |
0.27.1-dev.21 | 35 | 11/12/2024 |
0.27.1-dev.20 | 36 | 11/12/2024 |
0.27.1-dev.9 | 1,538 | 11/6/2024 |
0.27.1-dev.3 | 1,072 | 11/2/2024 |
0.27.1-dev.2 | 74 | 11/2/2024 |
0.27.0 | 921 | 10/30/2024 |
0.26.1-dev.73 | 1,216 | 10/26/2024 |
0.26.1-dev.70 | 307 | 10/24/2024 |
0.26.1-dev.68 | 120 | 10/24/2024 |
0.26.1-dev.67 | 148 | 10/24/2024 |
0.26.1-dev.66 | 64 | 10/24/2024 |
0.26.1-dev.65 | 43 | 10/24/2024 |
0.26.1-dev.64 | 369 | 10/22/2024 |
0.26.1-dev.63 | 37 | 10/22/2024 |
0.26.1-dev.61 | 1,076 | 10/18/2024 |
0.26.1-dev.60 | 212 | 10/18/2024 |
0.26.1-dev.58 | 78 | 10/18/2024 |
0.26.1-dev.53 | 319 | 10/16/2024 |
0.26.1-dev.46 | 765 | 10/13/2024 |
0.26.1-dev.45 | 56 | 10/13/2024 |
0.26.1-dev.44 | 61 | 10/13/2024 |
0.26.1-dev.42 | 296 | 10/12/2024 |
0.26.1-dev.37 | 196 | 10/12/2024 |
0.26.1-dev.36 | 77 | 10/12/2024 |
0.26.1-dev.33 | 80 | 10/11/2024 |
0.26.1-dev.32 | 220 | 10/11/2024 |
0.26.1-dev.29 | 70 | 10/11/2024 |
0.26.1-dev.28 | 47 | 10/11/2024 |
0.26.1-dev.27 | 46 | 10/11/2024 |
0.26.1-dev.25 | 47 | 10/11/2024 |
0.26.1-dev.24 | 45 | 10/11/2024 |
0.26.1-dev.17 | 602 | 10/8/2024 |
0.26.1-dev.13 | 1,111 | 10/3/2024 |
0.26.1-dev.12 | 46 | 10/3/2024 |
0.26.1-dev.11 | 49 | 10/3/2024 |
0.26.1-dev.10 | 73 | 10/3/2024 |
0.26.1-dev.9 | 50 | 10/3/2024 |
0.26.1-dev.4 | 604 | 10/1/2024 |
0.26.1-dev.3 | 55 | 10/1/2024 |
0.26.1-dev.2 | 46 | 10/1/2024 |
0.26.1-dev.1 | 52 | 10/1/2024 |
0.26.0 | 135 | 10/1/2024 |
0.25.0 | 115 | 10/1/2024 |
0.24.1-dev.68 | 57 | 10/1/2024 |
0.24.1-dev.67 | 44 | 10/1/2024 |
0.24.1-dev.66 | 43 | 10/1/2024 |
0.24.1-dev.56 | 1,213 | 9/23/2024 |
0.24.1-dev.54 | 117 | 9/22/2024 |
0.24.1-dev.53 | 43 | 9/22/2024 |
0.24.1-dev.52 | 67 | 9/22/2024 |
0.24.1-dev.51 | 42 | 9/22/2024 |
0.24.1-dev.50 | 48 | 9/22/2024 |
0.24.1-dev.49 | 58 | 9/22/2024 |
0.24.1-dev.47 | 60 | 9/22/2024 |
0.24.1-dev.44 | 77 | 9/21/2024 |
0.24.1-dev.41 | 197 | 9/20/2024 |
0.24.1-dev.40 | 53 | 9/20/2024 |
0.24.1-dev.39 | 44 | 9/20/2024 |
0.24.1-dev.33 | 285 | 9/17/2024 |
0.24.1-dev.31 | 76 | 9/17/2024 |
0.24.1-dev.28 | 218 | 9/15/2024 |
0.24.1-dev.27 | 44 | 9/15/2024 |
0.24.1-dev.26 | 60 | 9/14/2024 |
0.24.1-dev.25 | 51 | 9/14/2024 |
0.24.1-dev.24 | 87 | 9/12/2024 |
0.24.1-dev.23 | 42 | 9/12/2024 |
0.24.1-dev.22 | 70 | 9/11/2024 |
0.24.1-dev.19 | 54 | 9/11/2024 |
0.24.1-dev.18 | 52 | 9/11/2024 |
0.24.1-dev.15 | 59 | 9/11/2024 |
0.24.1-dev.14 | 56 | 9/11/2024 |
0.24.1-dev.13 | 51 | 9/11/2024 |
0.24.1-dev.11 | 57 | 9/11/2024 |
0.24.1-dev.10 | 51 | 9/11/2024 |
0.24.1-dev.9 | 53 | 9/11/2024 |
0.24.1-dev.8 | 51 | 9/11/2024 |
0.24.1-dev.7 | 54 | 9/11/2024 |
0.24.1-dev.2 | 62 | 9/10/2024 |
0.24.1-dev.1 | 58 | 9/10/2024 |
0.24.0 | 112 | 9/10/2024 |
0.23.1-dev.3 | 52 | 9/10/2024 |
0.23.1-dev.2 | 52 | 9/10/2024 |
0.23.1-dev.1 | 60 | 9/9/2024 |
0.23.0 | 109 | 9/9/2024 |
0.22.6-dev.10 | 59 | 9/9/2024 |
⭐ Last 10 features:
- feat: Added apiKey authorization in query support. 2024-10-01
- feat: Compute AdditionalProperties schema type in context. 2024-10-01
- feat: Added Match method for AnyOf/OneOfs. 2024-10-01
- feat: Simplified some enums which includes EnumName. 2024-09-22
- feat: Added initial support for enum xml docs #30. 2024-09-22
- feat: Added in: header parameters support. 2024-09-22
- feat: Added native support for AllOf1 like wrappers. 2024-09-22
- feat: Added AllOf'1 simplification by default. 2024-09-20
- feat: Added some support for Objects in query parameters. 2024-09-20
- feat: Added PathBuilder to simplify Path/Query building. 2024-09-19
🐞 Last 10 bug fixes:
- fix: Fixed xml docs. 2024-10-01
- fix: Fixed xml warnings. 2024-10-01
- fix: Removed usage of HttpClient.DefaultRequestHeaders. 2024-10-01
- fix: Now header parameters will be specified in HttpRequestMessage.Headers instead HttpClient.DefaultRequestHeaders. 2024-10-01
- fix: Fixed missing .ToString() for parameters in headers. 2024-10-01
- fix: Fixed issue with enum header parameters. 2024-09-22
- fix: Removed duplicates in analyzers for SourceGenerators. 2024-09-22
- fix: Fixed issues with ReadOnly/WriteOnly schemas. 2024-09-22
- fix: Fixed issue with empty smart names for named AnyOfs. 2024-09-21
- fix: Fixed missing xml doc for PathBuilder. 2024-09-20