OpenApiGenerator.Cli 0.11.6

Suggested Alternatives

AutoSDK.CLI

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global OpenApiGenerator.Cli --version 0.11.6
                    
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 OpenApiGenerator.Cli --version 0.11.6
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=OpenApiGenerator.Cli&version=0.11.6
                    
nuke :add-package OpenApiGenerator.Cli --version 0.11.6
                    

OpenApiGenerator

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
  • Tested on GitHub 220k lines OpenAPI specification
  • Supports OneOf/AnyOf/AllOf/Not schemas
  • Supports Enums for System.Text.Json

🚀Quick start🚀

  • Install the package
dotnet add package OpenApiGenerator
  • Add the following optional settings to your csproj file to customize generation. You can check all settings here:


<ItemGroup Label="OpenApiGenerator">
    <AdditionalFiles Include="$(MSBuildThisFileDirectory)../../../docs/openapi.yaml" />
</ItemGroup>


<PropertyGroup Label="OpenApiGenerator">
    <OpenApiGenerator_Namespace>Ollama</OpenApiGenerator_Namespace>
    <OpenApiGenerator_ClassName>OllamaApi</OpenApiGenerator_ClassName>

    
    <OpenApiGenerator_GenerateSdk>false</OpenApiGenerator_GenerateSdk>
    <OpenApiGenerator_GenerateModels>true</OpenApiGenerator_GenerateModels>
    <OpenApiGenerator_GenerateMethods>true</OpenApiGenerator_GenerateMethods>
    <OpenApiGenerator_GenerateConstructors>true</OpenApiGenerator_GenerateConstructors>
    <OpenApiGenerator_IncludeOperationIds>getPet;deletePet</OpenApiGenerator_IncludeOperationIds>
    <OpenApiGenerator_ExcludeOperationIds>getPet;deletePet</OpenApiGenerator_ExcludeOperationIds>
    <OpenApiGenerator_IncludeModels>Pet;Model</OpenApiGenerator_IncludeModels>
    <OpenApiGenerator_ExcludeModels>Pet;Model</OpenApiGenerator_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

CLI

You can use the CLI to generate the code.

dotnet tool install --global openapigenerator.cli --prerelease
oag --help
oag generate openapi.yaml

It will generate the code in the "openapi" subdirectory.

Trimming support

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="OpenApiGenerator">
    <OpenApiGenerator_GenerateSdk>false</OpenApiGenerator_GenerateSdk>
    <OpenApiGenerator_GenerateModels>true</OpenApiGenerator_GenerateModels>
    <OpenApiGenerator_GenerateJsonSerializerContextTypes>true</OpenApiGenerator_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(OpenApiGeneratorTrimmableSupport))]
internal sealed partial class SourceGenerationContext : JsonSerializerContext;
  • Add the following settings to your main csproj file:
<PropertyGroup Label="OpenApiGenerator">
    <OpenApiGenerator_GenerateSdk>false</OpenApiGenerator_GenerateSdk>
    <OpenApiGenerator_GenerateMethods>true</OpenApiGenerator_GenerateMethods>
    <OpenApiGenerator_GenerateConstructors>true</OpenApiGenerator_GenerateConstructors>
    <OpenApiGenerator_JsonSerializerContext>Namespace.SourceGenerationContext</OpenApiGenerator_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.22.6-dev.7 1,557 7 months ago 0.22.6-dev.7 is deprecated because it is no longer maintained.
0.22.6-dev.6 63 7 months ago 0.22.6-dev.6 is deprecated because it is no longer maintained.
0.22.6-dev.4 235 7 months ago 0.22.6-dev.4 is deprecated because it is no longer maintained.
0.22.6-dev.2 93 7 months ago 0.22.6-dev.2 is deprecated because it is no longer maintained.
0.22.6-dev.1 61 7 months ago 0.22.6-dev.1 is deprecated because it is no longer maintained.
0.22.5 191 7 months ago 0.22.5 is deprecated because it is no longer maintained.
0.22.4 121 7 months ago 0.22.4 is deprecated because it is no longer maintained.
0.22.3 118 7 months ago 0.22.3 is deprecated because it is no longer maintained.
0.22.2 135 7 months ago 0.22.2 is deprecated because it is no longer maintained.
0.22.1 121 7 months ago 0.22.1 is deprecated because it is no longer maintained.
0.22.0 118 7 months ago 0.22.0 is deprecated because it is no longer maintained.
0.21.1 180 7 months ago 0.21.1 is deprecated because it is no longer maintained.
0.21.0 129 7 months ago 0.21.0 is deprecated because it is no longer maintained.
0.20.2 753 7 months ago 0.20.2 is deprecated because it is no longer maintained.
0.20.1 127 7 months ago 0.20.1 is deprecated because it is no longer maintained.
0.20.0 136 7 months ago 0.20.0 is deprecated because it is no longer maintained.
0.19.0 143 7 months ago 0.19.0 is deprecated because it is no longer maintained.
0.18.0 225 7 months ago 0.18.0 is deprecated because it is no longer maintained.
0.17.1 151 7 months ago 0.17.1 is deprecated because it is no longer maintained.
0.17.0 129 7 months ago 0.17.0 is deprecated because it is no longer maintained.
0.16.4-dev.7 69 7 months ago 0.16.4-dev.7 is deprecated because it is no longer maintained.
0.16.3 485 7 months ago 0.16.3 is deprecated because it is no longer maintained.
0.16.2 152 7 months ago 0.16.2 is deprecated because it is no longer maintained.
0.16.1 225 7 months ago 0.16.1 is deprecated because it is no longer maintained.
0.16.0 196 7 months ago 0.16.0 is deprecated because it is no longer maintained.
0.15.8 151 7 months ago 0.15.8 is deprecated because it is no longer maintained.
0.15.7 277 7 months ago 0.15.7 is deprecated because it is no longer maintained.
0.15.6 194 8 months ago 0.15.6 is deprecated because it is no longer maintained.
0.15.5 139 8 months ago 0.15.5 is deprecated because it is no longer maintained.
0.15.4 262 8 months ago 0.15.4 is deprecated because it is no longer maintained.
0.15.3 200 8 months ago 0.15.3 is deprecated because it is no longer maintained.
0.15.2 174 8 months ago 0.15.2 is deprecated because it is no longer maintained.
0.15.1 158 8 months ago 0.15.1 is deprecated because it is no longer maintained.
0.15.0 168 8 months ago 0.15.0 is deprecated because it is no longer maintained.
0.14.3 298 8 months ago 0.14.3 is deprecated because it is no longer maintained.
0.14.2 106 8 months ago 0.14.2 is deprecated because it is no longer maintained.
0.14.1 96 8 months ago 0.14.1 is deprecated because it is no longer maintained.
0.14.0 86 8 months ago 0.14.0 is deprecated because it is no longer maintained.
0.13.11 409 8 months ago 0.13.11 is deprecated because it is no longer maintained.
0.13.10 149 8 months ago 0.13.10 is deprecated because it is no longer maintained.
0.13.9 150 9 months ago 0.13.9 is deprecated because it is no longer maintained.
0.13.8 137 9 months ago 0.13.8 is deprecated because it is no longer maintained.
0.13.7 122 9 months ago 0.13.7 is deprecated because it is no longer maintained.
0.13.6 127 9 months ago 0.13.6 is deprecated because it is no longer maintained.
0.13.5 125 9 months ago 0.13.5 is deprecated because it is no longer maintained.
0.13.4 126 9 months ago 0.13.4 is deprecated because it is no longer maintained.
0.13.3 140 9 months ago 0.13.3 is deprecated because it is no longer maintained.
0.13.2 104 9 months ago 0.13.2 is deprecated because it is no longer maintained.
0.13.1 119 9 months ago 0.13.1 is deprecated because it is no longer maintained.
0.13.0 128 9 months ago 0.13.0 is deprecated because it is no longer maintained.
0.12.2 131 9 months ago 0.12.2 is deprecated because it is no longer maintained.
0.12.1 148 9 months ago 0.12.1 is deprecated because it is no longer maintained.
0.12.0 138 9 months ago 0.12.0 is deprecated because it is no longer maintained.
0.11.11 136 9 months ago 0.11.11 is deprecated because it is no longer maintained.
0.11.10 127 9 months ago 0.11.10 is deprecated because it is no longer maintained.
0.11.9 158 9 months ago 0.11.9 is deprecated because it is no longer maintained.
0.11.8 146 9 months ago 0.11.8 is deprecated because it is no longer maintained.
0.11.7 137 9 months ago 0.11.7 is deprecated because it is no longer maintained.
0.11.6 140 9 months ago 0.11.6 is deprecated because it is no longer maintained.
0.11.4 132 9 months ago 0.11.4 is deprecated because it is no longer maintained.
0.11.3 152 9 months ago 0.11.3 is deprecated because it is no longer maintained.
0.11.1 129 9 months ago 0.11.1 is deprecated because it is no longer maintained.
0.11.0 135 10 months ago 0.11.0 is deprecated because it is no longer maintained.
0.10.8 136 10 months ago 0.10.8 is deprecated because it is no longer maintained.
0.10.7 133 10 months ago 0.10.7 is deprecated because it is no longer maintained.
0.10.6 127 10 months ago 0.10.6 is deprecated because it is no longer maintained.
0.10.4 130 10 months ago 0.10.4 is deprecated because it is no longer maintained.
0.10.2 127 10 months ago 0.10.2 is deprecated because it is no longer maintained.
0.10.1 125 10 months ago 0.10.1 is deprecated because it is no longer maintained.
0.10.0 125 10 months ago 0.10.0 is deprecated because it is no longer maintained.
0.9.12 122 10 months ago 0.9.12 is deprecated because it is no longer maintained.
0.9.11 123 10 months ago 0.9.11 is deprecated because it is no longer maintained.
0.9.10 130 10 months ago 0.9.10 is deprecated because it is no longer maintained.
0.9.9 125 10 months ago 0.9.9 is deprecated because it is no longer maintained.
0.9.8 138 10 months ago 0.9.8 is deprecated because it is no longer maintained.
0.9.7 157 6/1/2024 0.9.7 is deprecated because it is no longer maintained.
0.9.5 136 5/31/2024 0.9.5 is deprecated because it is no longer maintained.
0.9.4 131 5/31/2024 0.9.4 is deprecated because it is no longer maintained.
0.9.3 140 5/31/2024 0.9.3 is deprecated because it is no longer maintained.
0.9.1 137 5/30/2024 0.9.1 is deprecated because it is no longer maintained.
0.9.0 136 5/30/2024 0.9.0 is deprecated because it is no longer maintained.
0.8.8 140 5/28/2024 0.8.8 is deprecated because it is no longer maintained.
0.8.6 129 5/27/2024 0.8.6 is deprecated because it is no longer maintained.
0.8.5 130 5/27/2024 0.8.5 is deprecated because it is no longer maintained.
0.8.4 146 5/27/2024 0.8.4 is deprecated because it is no longer maintained.
0.8.3 148 5/27/2024 0.8.3 is deprecated because it is no longer maintained.
0.8.1 148 5/25/2024 0.8.1 is deprecated because it is no longer maintained.
0.8.0 139 5/25/2024 0.8.0 is deprecated because it is no longer maintained.
0.7.2 138 5/23/2024 0.7.2 is deprecated because it is no longer maintained.
0.7.1 145 5/22/2024 0.7.1 is deprecated because it is no longer maintained.
0.7.0 159 5/22/2024 0.7.0 is deprecated because it is no longer maintained.
0.6.9 134 5/22/2024 0.6.9 is deprecated because it is no longer maintained.
0.6.8 137 5/21/2024 0.6.8 is deprecated because it is no longer maintained.
0.6.7 123 5/21/2024 0.6.7 is deprecated because it is no longer maintained.
0.6.6 134 5/19/2024 0.6.6 is deprecated because it is no longer maintained.
0.6.5 128 5/19/2024 0.6.5 is deprecated because it is no longer maintained.
0.6.4 142 5/19/2024 0.6.4 is deprecated because it is no longer maintained.
0.6.3 125 5/19/2024 0.6.3 is deprecated because it is no longer maintained.
0.6.2 130 5/19/2024 0.6.2 is deprecated because it is no longer maintained.
0.6.1 125 5/19/2024 0.6.1 is deprecated because it is no longer maintained.
0.6.0 126 5/19/2024 0.6.0 is deprecated because it is no longer maintained.
0.5.0 134 5/19/2024 0.5.0 is deprecated because it is no longer maintained.
0.4.0 136 5/19/2024 0.4.0 is deprecated because it is no longer maintained.
0.3.2 121 5/13/2024 0.3.2 is deprecated because it is no longer maintained.
0.3.1 115 5/13/2024 0.3.1 is deprecated because it is no longer maintained.
0.3.0 110 5/13/2024 0.3.0 is deprecated because it is no longer maintained.
0.2.0 119 5/11/2024 0.2.0 is deprecated because it is no longer maintained.

⭐ Last 10 features:
- feat: Added CLI url support. 2024-06-28
- fix: Fixed GroupByTags feature if tags for endpoint was missing. 2024-06-27
- feat: Updated Ollama spec. 2024-06-27
- feat: Added support for Basic Authorization. 2024-06-24
- feat: Added SchemaContext. 2024-06-23
- feat: Added ability to see error json for non 200 responses. 2024-06-20
- feat: Added net8 cancellationToken for ReadAsync calls. 2024-06-20
- feat: Added smart names for Named AnyOf with all referenced properties. 2024-06-16
- feat: Added Trimming support for CLI generated code. 2024-06-16
- feat: Added FromCli setting. 2024-06-16
🐞 Last 10 bug fixes:
- fix: Fixed issue with base64 requests. 2024-06-29
- fix: Fixed issue with base url without path. 2024-06-27
- fix: Fixed invalid generation of authorizations for models only. 2024-06-27
- fix: Fixed GroupByTags feature if tags for endpoint was missing. 2024-06-27
- fix: Fixed nullable warnings. 2024-06-27
- fix: Fixed some nullability warnings. 2024-06-23
- fix: Fixed some nullability issues. 2024-06-23
- fix: Added some missing JsonConverters to settings. 2024-06-20
- fix: Moved request json to separate variable for debug purposes. 2024-06-20
- fix: AnyOf/OneOf will be nullable if not required. 2024-06-20