AutoSDK.CLI 0.24.1-dev.13

This is a prerelease version of AutoSDK.CLI.
There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global AutoSDK.CLI --version 0.24.1-dev.13
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local AutoSDK.CLI --version 0.24.1-dev.13
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=AutoSDK.CLI&version=0.24.1-dev.13&prerelease
                    
nuke :add-package AutoSDK.CLI --version 0.24.1-dev.13
                    

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📚

Product 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.28.1-dev.16 2,701 10 days ago
0.28.1-dev.15 107 10 days ago
0.28.1-dev.8 2,390 19 days ago
0.28.1-dev.7 100 19 days ago
0.28.1-dev.4 1,923 a month ago
0.28.1-dev.2 2,376 a month ago
0.28.0 620 a month ago
0.27.1-dev.89 1,571 a month ago
0.27.1-dev.88 125 a month ago
0.27.1-dev.87 471 a month ago
0.27.1-dev.86 131 a month ago
0.27.1-dev.85 83 a month ago
0.27.1-dev.84 88 a month ago
0.27.1-dev.76 5,251 2 months ago
0.27.1-dev.70 8,404 3 months ago
0.27.1-dev.69 59 3 months ago
0.27.1-dev.68 165 3 months ago
0.27.1-dev.65 4,467 4 months ago
0.27.1-dev.64 1,290 4 months ago
0.27.1-dev.59 2,467 4 months ago
0.27.1-dev.57 160 4 months ago
0.27.1-dev.53 1,196 4 months ago
0.27.1-dev.52 593 4 months ago
0.27.1-dev.44 1,550 4 months ago
0.27.1-dev.43 65 4 months ago
0.27.1-dev.37 2,263 5 months ago
0.27.1-dev.35 1,548 5 months ago
0.27.1-dev.33 181 5 months ago
0.27.1-dev.32 91 5 months ago
0.27.1-dev.30 69 5 months ago
0.27.1-dev.26 89 5 months ago
0.27.1-dev.25 76 5 months ago
0.27.1-dev.22 303 5 months ago
0.27.1-dev.21 53 5 months ago
0.27.1-dev.20 55 5 months ago
0.27.1-dev.9 1,553 5 months ago
0.27.1-dev.3 1,091 5 months ago
0.27.1-dev.2 88 5 months ago
0.27.0 982 5 months ago
0.26.1-dev.73 1,234 5 months ago
0.26.1-dev.70 320 5 months ago
0.26.1-dev.68 133 5 months ago
0.26.1-dev.67 160 6 months ago
0.26.1-dev.66 78 6 months ago
0.26.1-dev.65 56 6 months ago
0.26.1-dev.64 380 6 months ago
0.26.1-dev.63 46 6 months ago
0.26.1-dev.61 1,089 6 months ago
0.26.1-dev.60 222 6 months ago
0.26.1-dev.58 88 6 months ago
0.26.1-dev.53 328 6 months ago
0.26.1-dev.46 777 6 months ago
0.26.1-dev.45 66 6 months ago
0.26.1-dev.44 76 6 months ago
0.26.1-dev.42 310 6 months ago
0.26.1-dev.37 209 6 months ago
0.26.1-dev.36 88 6 months ago
0.26.1-dev.33 91 6 months ago
0.26.1-dev.32 231 6 months ago
0.26.1-dev.29 81 6 months ago
0.26.1-dev.28 57 6 months ago
0.26.1-dev.27 57 6 months ago
0.26.1-dev.25 58 6 months ago
0.26.1-dev.24 56 6 months ago
0.26.1-dev.17 611 6 months ago
0.26.1-dev.13 1,124 6 months ago
0.26.1-dev.12 65 6 months ago
0.26.1-dev.11 56 6 months ago
0.26.1-dev.10 84 6 months ago
0.26.1-dev.9 63 6 months ago
0.26.1-dev.4 614 6 months ago
0.26.1-dev.3 68 6 months ago
0.26.1-dev.2 56 6 months ago
0.26.1-dev.1 65 6 months ago
0.26.0 153 6 months ago
0.25.0 128 6 months ago
0.24.1-dev.68 67 6 months ago
0.24.1-dev.67 54 6 months ago
0.24.1-dev.66 57 6 months ago
0.24.1-dev.56 1,225 7 months ago
0.24.1-dev.54 130 7 months ago
0.24.1-dev.53 55 7 months ago
0.24.1-dev.52 78 7 months ago
0.24.1-dev.51 56 7 months ago
0.24.1-dev.50 58 7 months ago
0.24.1-dev.49 73 7 months ago
0.24.1-dev.47 72 7 months ago
0.24.1-dev.44 91 7 months ago
0.24.1-dev.41 208 7 months ago
0.24.1-dev.40 67 7 months ago
0.24.1-dev.39 58 7 months ago
0.24.1-dev.33 299 7 months ago
0.24.1-dev.31 89 7 months ago
0.24.1-dev.28 229 7 months ago
0.24.1-dev.27 57 7 months ago
0.24.1-dev.26 73 7 months ago
0.24.1-dev.25 62 7 months ago
0.24.1-dev.24 97 7 months ago
0.24.1-dev.23 51 7 months ago
0.24.1-dev.22 81 7 months ago
0.24.1-dev.19 67 7 months ago
0.24.1-dev.18 63 7 months ago
0.24.1-dev.15 70 7 months ago
0.24.1-dev.14 67 7 months ago
0.24.1-dev.13 64 7 months ago
0.24.1-dev.11 67 7 months ago
0.24.1-dev.10 60 7 months ago
0.24.1-dev.9 63 7 months ago
0.24.1-dev.8 69 7 months ago
0.24.1-dev.7 65 7 months ago
0.24.1-dev.2 73 7 months ago
0.24.1-dev.1 69 7 months ago
0.24.0 125 7 months ago
0.23.1-dev.3 60 7 months ago
0.23.1-dev.2 62 7 months ago
0.23.1-dev.1 68 7 months ago
0.23.0 122 7 months ago
0.22.6-dev.10 68 7 months ago

⭐ Last 10 features:
- 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
- feat: Added generation of main constructor with apiKey/username. 2024-08-24
- feat: To MinVer. 2024-08-22
🐞 Last 10 bug fixes:
- 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
- fix: Fixed build. 2024-09-09
- fix: Fixed SourceGenerators project build. 2024-09-09
- fix: Fixed issues after update NuGet packages. 2024-09-08
- fix: Fixed GenerateDocs in init command. 2024-09-07
- fix: Fixed small issues with cli init command. 2024-09-07
- fix: Fixed init command issue with binary files. 2024-09-07
- fix: Fixed init command cicd files path. 2024-09-07