WebApiGenerator.OpenAPI 0.3.0-pre-e220edb2

This is a prerelease version of WebApiGenerator.OpenAPI.
dotnet add package WebApiGenerator.OpenAPI --version 0.3.0-pre-e220edb2
                    
NuGet\Install-Package WebApiGenerator.OpenAPI -Version 0.3.0-pre-e220edb2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WebApiGenerator.OpenAPI" Version="0.3.0-pre-e220edb2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WebApiGenerator.OpenAPI" Version="0.3.0-pre-e220edb2" />
                    
Directory.Packages.props
<PackageReference Include="WebApiGenerator.OpenAPI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WebApiGenerator.OpenAPI --version 0.3.0-pre-e220edb2
                    
#r "nuget: WebApiGenerator.OpenAPI, 0.3.0-pre-e220edb2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WebApiGenerator.OpenAPI@0.3.0-pre-e220edb2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WebApiGenerator.OpenAPI&version=0.3.0-pre-e220edb2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=WebApiGenerator.OpenAPI&version=0.3.0-pre-e220edb2&prerelease
                    
Install as a Cake Tool

OpenApi.WebApiGenerator

Generates scaffolding for Web APIs from OpenAPI specifications.

The generated functionality will route, serialize/deserialize and validate payloads according to the specification.

API frameworks supported:

.NET versions supported:

  • >=9.0

Installation

dotnet add package WebApiGenerator.OpenAPI

https://www.nuget.org/packages/WebApiGenerator.OpenAPI

Getting Started

  1. Add a reference to the generator in the project file where the API should exist:
<ItemGroup>
    <PackageReference Include="WebApiGenerator.OpenAPITest" Version="x.y.z" PrivateAssets="all" />
</ItemGroup>
  1. Add a reference to your OpenAPI specification:
<ItemGroup>
    <AdditionalFiles Include="path/to/OpenAPI_Specification.json"/>
</ItemGroup>
  1. Add references to Corvus.Json.ExtendedTypes and ParameterStyleParsers.OpenAPI.
<ItemGroup>
    <PackageReference Include="Corvus.Json.ExtendedTypes" Version="4.3.13" />
    <PackageReference Include="ParameterStyleParsers.OpenAPI" Version="1.4.0" />
</ItemGroup>
  • Corvus.Json.ExtendedTypes >= 4.0.0
  • ParameterStyleParsers.OpenAPI >= 1.4.0
  1. Compile the project.

  2. Register API operations in Program.cs.

var builder = WebApplication.CreateBuilder(args);
builder.AddOperations();
var app = builder.Build();
app.MapOperations();
app.Run();

See Example.Api as an example.

Note: The Example.Api references the generator through a project reference. Use a package reference instead as described above.

Implementing an API Operation

The generator generates stubbed partial classes for any operation handlers (Foo.Bar.Operation.Handler.cs) if there are none existing in the project and logs it with a compiler warning (AF1001). The classes should be copied into source control and the operation methods implemented. The operation methods have a familiar request/response design:

internal partial Task<Response> HandleAsync(Request request, CancellationToken cancellationToken);

The generated stubbed operation handler classes can be copied either manually or automatically.

Manually

Copy the content using the Solution Explorer in the IDE and create a proper file to paste it into:

  • JetBrains Rider: MyProject/Dependencies/.NET X.0/Source Generators/OpenAPI.Generator/Foo.Bar.Operation.Handler.cs
  • Visual Studio: MyProject/Dependencies/Analyzers/OpenAPI.Generator/OpenAPI.Generator.OpenApiGenerator/Foo.Bar.Operation.Handler.cs

Automatically

Let the compiler output all generated files to a directory during compilation by adding these directives to the project:

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>GeneratedFiles</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

Make sure to not include the files outputted when compiling again:

<ItemGroup>
    <Compile Remove="$(CompilerGeneratedFilesOutputPath)/**" />
</ItemGroup>

To copy the operation handlers add the following target:

<Target Name="CopyMissingOperationHandlers" 
        AfterTargets="Build" 
        Condition="'$(EmitCompilerGeneratedFiles)'=='true'">
    <ItemGroup>
        <TextFiles Include="$(CompilerGeneratedFilesOutputPath)\**\Operation.Handler.g.cs" />
    </ItemGroup>
    <Copy
        SourceFiles="@(TextFiles)"
        DestinationFiles="@(TextFiles->'generated-api-handlers\%(RecursiveDir)%(Filename)%(Extension)')"
        ContinueOnError="true" />
</Target>

Exchange generated-api-handlers to any directory.

These handlers will not be generated in subsequent compilations as the generator will detect that they already exist, but the output directory should be cleaned before compiling to avoid the same files to be copied again (and overwrite any changes done):

<Target Name="CleanSourceGeneratedFiles"
        BeforeTargets="BeforeBuild"
        DependsOnTargets="$(BeforeBuildDependsOn)"
        Condition="'$(EmitCompilerGeneratedFiles)'=='true'">
    <RemoveDir Directories="$(CompilerGeneratedFilesOutputPath)" />
</Target>

Dependency Injection

Operations are registered as scoped dependencies. Any dependencies can be injected into them as usual via the app builder's IServiceCollection.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

There are no supported framework assets in this package.

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.3.0-pre-e220edb2 38 1/13/2026
0.3.0-pre-d257b09b 28 1/15/2026
0.3.0-pre-846fa347 82 1/9/2026
0.3.0-pre-31d12661 79 1/10/2026
0.2.0 81 1/9/2026
0.2.0-pre-81b856b0 84 1/8/2026
0.1.6 81 1/6/2026
0.1.6-pre-d5c9c0fd 86 1/6/2026
0.1.6-pre-5187da5c 80 1/6/2026
0.1.5 80 1/5/2026
0.1.5-pre-bc441477 78 1/3/2026
0.1.5-pre-3a06bd2a 85 1/5/2026
0.1.5-pre-3503ab7a 82 1/5/2026
0.1.4 85 1/2/2026
0.1.4-pre-ca5353f2 84 1/2/2026
0.1.3 83 12/31/2025
0.1.3-pre-6e2a9fbd 85 12/31/2025
0.1.2 88 12/31/2025
0.1.2-pre-ca6d2392 170 12/24/2025
0.1.2-pre-af5bdadc 85 12/28/2025
0.1.2-pre-904a3238 163 12/22/2025
0.1.2-pre-84af6191 87 12/30/2025
0.1.2-pre-6a30f51a 84 12/28/2025
0.1.2-pre-635436bd 172 12/25/2025
0.1.2-pre-5ab70e05 121 12/26/2025
0.1.2-pre-182db3fc 168 12/23/2025
0.1.1 275 12/17/2025
0.1.1-pre-82bcb300 253 12/17/2025
0.1.1-pre-1bbb4929 256 12/17/2025
0.1.0 130 12/11/2025
0.1.0-pre-9c6dc78e 411 12/11/2025
0.1.0-pre-165f6b4d 412 12/10/2025
0.1.0-pre-0011d44b 116 12/11/2025
0.0.2 123 11/29/2025
0.0.2-pre-ecdd98c5 116 11/29/2025
0.0.1 107 11/29/2025
0.0.1-pre-da75883f 187 11/26/2025
0.0.1-pre-8dcdc6d0 280 11/12/2025