OpenApiGenerator.Core
0.13.7
See the version list below for details.
dotnet add package OpenApiGenerator.Core --version 0.13.7
NuGet\Install-Package OpenApiGenerator.Core -Version 0.13.7
<PackageReference Include="OpenApiGenerator.Core" Version="0.13.7" />
paket add OpenApiGenerator.Core --version 0.13.7
#r "nuget: OpenApiGenerator.Core, 0.13.7"
// Install OpenApiGenerator.Core as a Cake Addin #addin nuget:?package=OpenApiGenerator.Core&version=0.13.7 // Install OpenApiGenerator.Core as a Cake Tool #tool nuget:?package=OpenApiGenerator.Core&version=0.13.7
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🚀
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📚
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.OpenApi.Readers (>= 1.6.15)
- System.Collections.Immutable (>= 8.0.0)
-
.NETStandard 2.0
- Microsoft.OpenApi.Readers (>= 1.6.15)
- System.Collections.Immutable (>= 8.0.0)
-
net6.0
- Microsoft.OpenApi.Readers (>= 1.6.15)
- System.Collections.Immutable (>= 8.0.0)
-
net8.0
- Microsoft.OpenApi.Readers (>= 1.6.15)
- System.Collections.Immutable (>= 8.0.0)
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.4 | 22 | 9/7/2024 |
0.22.6-dev.2 | 23 | 9/7/2024 |
0.22.6-dev.1 | 20 | 9/7/2024 |
0.22.5 | 34 | 9/7/2024 |
0.22.4 | 22 | 9/7/2024 |
0.22.3 | 28 | 9/7/2024 |
0.22.2 | 28 | 9/7/2024 |
0.22.1 | 22 | 9/7/2024 |
0.22.0 | 23 | 9/7/2024 |
0.21.1 | 28 | 9/6/2024 |
0.21.0 | 28 | 9/6/2024 |
0.20.2 | 77 | 8/31/2024 |
0.20.1 | 63 | 8/31/2024 |
0.20.0 | 64 | 8/30/2024 |
0.19.0 | 69 | 8/30/2024 |
0.18.0 | 59 | 8/29/2024 |
0.17.1 | 76 | 8/28/2024 |
0.17.0 | 82 | 8/28/2024 |
0.16.4-dev.7 | 33 | 8/28/2024 |
0.16.3 | 83 | 8/24/2024 |
0.16.2 | 79 | 8/24/2024 |
0.16.1 | 80 | 8/23/2024 |
0.16.0 | 83 | 8/22/2024 |
0.15.8 | 79 | 8/22/2024 |
0.15.7 | 76 | 8/19/2024 |
0.15.6 | 77 | 8/18/2024 |
0.15.5 | 70 | 8/18/2024 |
0.15.4 | 72 | 8/15/2024 |
0.15.3 | 66 | 8/13/2024 |
0.15.2 | 64 | 8/13/2024 |
0.15.1 | 64 | 8/12/2024 |
0.15.0 | 73 | 8/11/2024 |
0.14.3 | 25 | 8/6/2024 |
0.14.2 | 28 | 8/5/2024 |
0.14.1 | 33 | 8/5/2024 |
0.14.0 | 28 | 8/5/2024 |
0.13.11 | 78 | 7/22/2024 |
0.13.10 | 92 | 7/21/2024 |
0.13.9 | 69 | 7/18/2024 |
0.13.8 | 78 | 7/15/2024 |
0.13.7 | 70 | 7/15/2024 |
0.13.6 | 71 | 7/14/2024 |
0.13.5 | 71 | 7/14/2024 |
0.13.4 | 77 | 7/13/2024 |
0.13.3 | 74 | 7/9/2024 |
0.13.2 | 69 | 7/8/2024 |
0.13.1 | 70 | 7/8/2024 |
0.13.0 | 58 | 7/8/2024 |
0.12.2 | 73 | 7/8/2024 |
0.12.1 | 78 | 7/6/2024 |
0.12.0 | 71 | 7/6/2024 |
0.11.11 | 77 | 7/6/2024 |
0.11.10 | 74 | 7/6/2024 |
0.11.9 | 89 | 6/30/2024 |
0.11.8 | 90 | 6/30/2024 |
0.11.7 | 83 | 6/30/2024 |
0.11.6 | 87 | 6/29/2024 |
0.11.4 | 86 | 6/27/2024 |
0.11.3 | 87 | 6/27/2024 |
0.11.1 | 75 | 6/20/2024 |
0.11.0 | 83 | 6/16/2024 |
0.10.8 | 80 | 6/15/2024 |
0.10.7 | 83 | 6/15/2024 |
0.10.6 | 76 | 6/15/2024 |
0.10.4 | 75 | 6/13/2024 |
0.10.2 | 73 | 6/13/2024 |
0.10.1 | 69 | 6/13/2024 |
0.10.0 | 73 | 6/13/2024 |
0.9.12 | 80 | 6/6/2024 |
0.9.11 | 71 | 6/6/2024 |
0.9.10 | 77 | 6/5/2024 |
0.9.9 | 73 | 6/5/2024 |
0.9.8 | 76 | 6/4/2024 |
0.9.7 | 84 | 6/1/2024 |
0.9.5 | 90 | 5/31/2024 |
0.9.4 | 87 | 5/31/2024 |
0.9.3 | 81 | 5/31/2024 |
0.9.1 | 84 | 5/30/2024 |
0.9.0 | 80 | 5/30/2024 |
0.8.8 | 80 | 5/28/2024 |
0.8.6 | 77 | 5/27/2024 |
0.8.5 | 77 | 5/27/2024 |
0.8.4 | 80 | 5/27/2024 |
0.8.3 | 77 | 5/27/2024 |
0.8.1 | 102 | 5/25/2024 |
0.8.0 | 80 | 5/25/2024 |
0.7.2 | 92 | 5/23/2024 |
0.7.1 | 90 | 5/22/2024 |
0.7.0 | 83 | 5/22/2024 |
0.6.9 | 80 | 5/22/2024 |
0.6.8 | 79 | 5/21/2024 |
0.6.7 | 87 | 5/21/2024 |
0.6.6 | 84 | 5/19/2024 |
0.6.5 | 77 | 5/19/2024 |
0.6.4 | 78 | 5/19/2024 |
0.6.3 | 80 | 5/19/2024 |
0.6.2 | 83 | 5/19/2024 |
0.6.1 | 80 | 5/19/2024 |
0.6.0 | 78 | 5/19/2024 |
0.5.0 | 88 | 5/19/2024 |
0.4.0 | 87 | 5/19/2024 |
0.3.2 | 86 | 5/13/2024 |
0.3.1 | 79 | 5/13/2024 |
0.3.0 | 80 | 5/13/2024 |
0.2.0 | 89 | 5/11/2024 |
0.1.5 | 90 | 5/10/2024 |
0.1.4 | 86 | 5/10/2024 |
0.1.3 | 107 | 4/5/2024 |
⭐ Last 10 features:
- feat: Added xml docs for params. 2024-07-14
- feat: Implemented partial methods. 2024-07-09
- feat: Initial support of partial methods for methods. 2024-07-09
- feat: Added MimeUtility. 2024-07-06
- feat: Added polyfill generation. 2024-07-06
- 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
🐞 Last 10 bug fixes:
- fix: Small fixes. 2024-07-16
- fix: Added missing polyfill. 2024-07-14
- fix: Fixed some responses with byte[]. 2024-07-14
- fix: Fixed MethodAndPath OperationId generation for some cases. 2024-07-09
- fix: Fixed CS3016 in generated code. 2024-07-09
- fix: Fixed issue with trimming and response value types. 2024-07-08
- fix: Fixed OpenAI issues. 2024-07-06
- fix: Fixed small issues with Polyfills. 2024-07-06
- fix: Fixed BaseUrl concat issue. 2024-07-06
- fix: Fixed CLI issues. 2024-07-06