OpenApiGenerator 0.11.6
See the version list below for details.
dotnet add package OpenApiGenerator --version 0.11.6
NuGet\Install-Package OpenApiGenerator -Version 0.11.6
<PackageReference Include="OpenApiGenerator" Version="0.11.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
paket add OpenApiGenerator --version 0.11.6
#r "nuget: OpenApiGenerator, 0.11.6"
// Install OpenApiGenerator as a Cake Addin
#addin nuget:?package=OpenApiGenerator&version=0.11.6
// Install OpenApiGenerator as a Cake Tool
#tool nuget:?package=OpenApiGenerator&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:
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📚
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.11.9 | 32 | 6/30/2024 |
0.11.8 | 26 | 6/30/2024 |
0.11.7 | 24 | 6/30/2024 |
0.11.6 | 37 | 6/29/2024 |
0.11.4 | 31 | 6/27/2024 |
0.11.3 | 38 | 6/27/2024 |
0.11.1 | 90 | 6/20/2024 |
0.11.0 | 92 | 6/16/2024 |
0.10.8 | 72 | 6/15/2024 |
0.10.7 | 70 | 6/15/2024 |
0.10.6 | 65 | 6/15/2024 |
0.10.4 | 62 | 6/13/2024 |
0.10.2 | 59 | 6/13/2024 |
0.10.1 | 56 | 6/13/2024 |
0.10.0 | 61 | 6/13/2024 |
0.9.12 | 87 | 6/6/2024 |
0.9.11 | 62 | 6/6/2024 |
0.9.10 | 73 | 6/5/2024 |
0.9.9 | 72 | 6/5/2024 |
0.9.8 | 64 | 6/4/2024 |
0.9.7 | 84 | 6/1/2024 |
0.9.5 | 77 | 5/31/2024 |
0.9.4 | 70 | 5/31/2024 |
0.9.3 | 72 | 5/31/2024 |
0.9.1 | 73 | 5/30/2024 |
0.9.0 | 68 | 5/30/2024 |
0.8.8 | 65 | 5/28/2024 |
0.8.6 | 74 | 5/27/2024 |
0.8.5 | 67 | 5/27/2024 |
0.8.4 | 68 | 5/27/2024 |
0.8.3 | 70 | 5/27/2024 |
0.8.1 | 77 | 5/25/2024 |
0.8.0 | 69 | 5/25/2024 |
0.7.2 | 72 | 5/23/2024 |
0.7.1 | 75 | 5/22/2024 |
0.7.0 | 70 | 5/22/2024 |
0.6.9 | 70 | 5/22/2024 |
0.6.8 | 71 | 5/21/2024 |
0.6.7 | 71 | 5/21/2024 |
0.6.6 | 87 | 5/19/2024 |
0.6.5 | 68 | 5/19/2024 |
0.6.4 | 66 | 5/19/2024 |
0.6.3 | 68 | 5/19/2024 |
0.6.2 | 66 | 5/19/2024 |
0.6.1 | 66 | 5/19/2024 |
0.6.0 | 68 | 5/19/2024 |
0.5.0 | 73 | 5/19/2024 |
0.4.0 | 80 | 5/19/2024 |
0.3.2 | 76 | 5/13/2024 |
0.3.1 | 81 | 5/13/2024 |
0.3.0 | 68 | 5/13/2024 |
0.2.0 | 75 | 5/11/2024 |
0.1.5 | 72 | 5/10/2024 |
0.1.4 | 71 | 5/10/2024 |
0.1.3 | 297 | 1/8/2024 |
0.1.2 | 163 | 1/8/2024 |
0.1.1 | 130 | 1/8/2024 |
0.1.0-dev.37 | 62 | 1/8/2024 |
0.1.0-dev.35 | 62 | 1/8/2024 |
0.1.0-dev.34 | 50 | 1/8/2024 |
0.1.0-dev.33 | 54 | 1/7/2024 |
0.1.0-dev.10 | 112 | 12/6/2023 |
0.1.0-dev.5 | 64 | 12/4/2023 |
0.1.0-dev.4 | 64 | 11/27/2023 |
0.1.0-dev.3 | 55 | 11/25/2023 |
⭐ 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