OpenApiGenerator 0.22.6-dev.2
See the version list below for details.
dotnet add package OpenApiGenerator --version 0.22.6-dev.2
NuGet\Install-Package OpenApiGenerator -Version 0.22.6-dev.2
<PackageReference Include="OpenApiGenerator" Version="0.22.6-dev.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add OpenApiGenerator --version 0.22.6-dev.2
#r "nuget: OpenApiGenerator, 0.22.6-dev.2"
// Install OpenApiGenerator as a Cake Addin #addin nuget:?package=OpenApiGenerator&version=0.22.6-dev.2&prerelease // Install OpenApiGenerator as a Cake Tool #tool nuget:?package=OpenApiGenerator&version=0.22.6-dev.2&prerelease
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/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🚀
CLI (Recommended)
You can use the CLI to generate the code.
dotnet tool install --global openapigenerator.cli --prerelease
rm -rf Generated
oag 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 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:
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="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📚
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.22.6-dev.7 | 188 | 9/9/2024 | |
0.22.6-dev.6 | 54 | 9/9/2024 | |
0.22.6-dev.4 | 61 | 9/7/2024 | |
0.22.6-dev.2 | 56 | 9/7/2024 | |
0.22.6-dev.1 | 54 | 9/7/2024 | |
0.22.5 | 208 | 9/7/2024 | |
0.22.4 | 104 | 9/7/2024 | |
0.22.3 | 118 | 9/7/2024 | |
0.22.2 | 113 | 9/7/2024 | |
0.22.1 | 112 | 9/7/2024 | |
0.22.0 | 104 | 9/7/2024 | |
0.21.1 | 106 | 9/6/2024 | |
0.21.0 | 113 | 9/6/2024 | |
0.20.2 | 118 | 8/31/2024 | |
0.20.1 | 107 | 8/31/2024 | |
0.20.0 | 108 | 8/30/2024 | |
0.19.0 | 106 | 8/30/2024 | |
0.18.0 | 105 | 8/29/2024 | |
0.17.1 | 111 | 8/28/2024 | |
0.17.0 | 123 | 8/28/2024 | |
0.16.4-dev.7 | 58 | 8/28/2024 | |
0.16.3 | 149 | 8/24/2024 | |
0.16.2 | 125 | 8/24/2024 | |
0.16.1 | 136 | 8/23/2024 | |
0.16.0 | 135 | 8/22/2024 | |
0.15.8 | 135 | 8/22/2024 | |
0.15.7 | 140 | 8/19/2024 | |
0.15.6 | 132 | 8/18/2024 | |
0.15.5 | 130 | 8/18/2024 | |
0.15.4 | 125 | 8/15/2024 | |
0.15.3 | 132 | 8/13/2024 | |
0.15.2 | 140 | 8/13/2024 | |
0.15.1 | 122 | 8/12/2024 | |
0.15.0 | 128 | 8/11/2024 | |
0.14.3 | 103 | 8/6/2024 | |
0.14.2 | 101 | 8/5/2024 | |
0.14.1 | 100 | 8/5/2024 | |
0.14.0 | 99 | 8/5/2024 | |
0.13.11 | 745 | 7/22/2024 | |
0.13.10 | 138 | 7/21/2024 | |
0.13.9 | 112 | 7/18/2024 | |
0.13.8 | 111 | 7/15/2024 | |
0.13.7 | 100 | 7/15/2024 | |
0.13.6 | 119 | 7/14/2024 | |
0.13.5 | 99 | 7/14/2024 | |
0.13.4 | 105 | 7/13/2024 | |
0.13.3 | 93 | 7/9/2024 | |
0.13.2 | 97 | 7/8/2024 | |
0.13.1 | 105 | 7/8/2024 | |
0.13.0 | 95 | 7/8/2024 | |
0.12.2 | 97 | 7/8/2024 | |
0.12.1 | 109 | 7/6/2024 | |
0.12.0 | 100 | 7/6/2024 | |
0.11.11 | 107 | 7/6/2024 | |
0.11.10 | 96 | 7/6/2024 | |
0.11.9 | 171 | 6/30/2024 | |
0.11.8 | 121 | 6/30/2024 | |
0.11.7 | 113 | 6/30/2024 | |
0.11.6 | 130 | 6/29/2024 | |
0.11.4 | 120 | 6/27/2024 | |
0.11.3 | 114 | 6/27/2024 | |
0.11.1 | 142 | 6/20/2024 | |
0.11.0 | 137 | 6/16/2024 | |
0.10.8 | 119 | 6/15/2024 | |
0.10.7 | 121 | 6/15/2024 | |
0.10.6 | 108 | 6/15/2024 | |
0.10.4 | 108 | 6/13/2024 | |
0.10.2 | 102 | 6/13/2024 | |
0.10.1 | 97 | 6/13/2024 | |
0.10.0 | 112 | 6/13/2024 | |
0.9.12 | 137 | 6/6/2024 | |
0.9.11 | 114 | 6/6/2024 | |
0.9.10 | 122 | 6/5/2024 | |
0.9.9 | 119 | 6/5/2024 | |
0.9.8 | 109 | 6/4/2024 | |
0.9.7 | 127 | 6/1/2024 | |
0.9.5 | 122 | 5/31/2024 | |
0.9.4 | 115 | 5/31/2024 | |
0.9.3 | 115 | 5/31/2024 | |
0.9.1 | 123 | 5/30/2024 | |
0.9.0 | 112 | 5/30/2024 | |
0.8.8 | 109 | 5/28/2024 | |
0.8.6 | 117 | 5/27/2024 | |
0.8.5 | 108 | 5/27/2024 | |
0.8.4 | 108 | 5/27/2024 | |
0.8.3 | 116 | 5/27/2024 | |
0.8.1 | 124 | 5/25/2024 | |
0.8.0 | 119 | 5/25/2024 | |
0.7.2 | 116 | 5/23/2024 | |
0.7.1 | 121 | 5/22/2024 | |
0.7.0 | 112 | 5/22/2024 | |
0.6.9 | 116 | 5/22/2024 | |
0.6.8 | 120 | 5/21/2024 | |
0.6.7 | 121 | 5/21/2024 | |
0.6.6 | 134 | 5/19/2024 | |
0.6.5 | 113 | 5/19/2024 | |
0.6.4 | 113 | 5/19/2024 | |
0.6.3 | 111 | 5/19/2024 | |
0.6.2 | 117 | 5/19/2024 | |
0.6.1 | 111 | 5/19/2024 | |
0.6.0 | 116 | 5/19/2024 | |
0.5.0 | 117 | 5/19/2024 | |
0.4.0 | 125 | 5/19/2024 | |
0.3.2 | 113 | 5/13/2024 | |
0.3.1 | 125 | 5/13/2024 | |
0.3.0 | 112 | 5/13/2024 | |
0.2.0 | 126 | 5/11/2024 | |
0.1.5 | 116 | 5/10/2024 | |
0.1.4 | 114 | 5/10/2024 | |
0.1.3 | 364 | 1/8/2024 | |
0.1.2 | 224 | 1/8/2024 | |
0.1.1 | 191 | 1/8/2024 | |
0.1.0-dev.37 | 89 | 1/8/2024 | |
0.1.0-dev.35 | 88 | 1/8/2024 | |
0.1.0-dev.34 | 76 | 1/8/2024 | |
0.1.0-dev.33 | 82 | 1/7/2024 | |
0.1.0-dev.10 | 140 | 12/6/2023 | |
0.1.0-dev.5 | 91 | 12/4/2023 | |
0.1.0-dev.4 | 95 | 11/27/2023 | |
0.1.0-dev.3 | 84 | 11/25/2023 |
⭐ Last 10 features:
- 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
- feat: Make SourceGenerationContext public. 2024-08-19
- feat: Removed Required from enum properties with single value. 2024-08-18
🐞 Last 10 bug fixes:
- 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
- fix: Fixed init command solution tests. 2024-09-07
- fix: Fixed init command directory creation. 2024-09-07
- fix: Added missing .gitignore for init command. 2024-09-07
- fix: Fixed init command separator. 2024-09-07
- fix: Fixed type detection for assemblyAI spec. 2024-09-06
- fix: Fixed response deserialization when response type is just string. 2024-08-31