SchemeGenerator 10.1.0

dotnet add package SchemeGenerator --version 10.1.0
                    
NuGet\Install-Package SchemeGenerator -Version 10.1.0
                    
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="SchemeGenerator" Version="10.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SchemeGenerator" Version="10.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SchemeGenerator" />
                    
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 SchemeGenerator --version 10.1.0
                    
#r "nuget: SchemeGenerator, 10.1.0"
                    
#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 SchemeGenerator@10.1.0
                    
#: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=SchemeGenerator&version=10.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SchemeGenerator&version=10.1.0
                    
Install as a Cake Tool

Scheme Generator

NuGet CI .NET License: MIT

Scheme Generator builds default object graphs and JSON for any .NET type. Use it for unit tests, OpenAPI examples, and quick fixtures without hand-writing sample data.

Packages

Package Description
SchemeGenerator Core reflection-based generator
SchemeGenerator.SourceGenerators Roslyn source generator for compile-time defaults
SchemeGenerator.Xunit xUnit [Theory] data attributes
SchemeGenerator.AspNetCore Swashbuckle schema example filter

All packages are version 10.1.0 and target net8.0, net9.0, and net10.0 (except the analyzer, which is a Roslyn component).

Requirements

Installation

Core package:

dotnet add package SchemeGenerator --version 10.1.0

With source generator:

dotnet add package SchemeGenerator --version 10.1.0
dotnet add package SchemeGenerator.SourceGenerators --version 10.1.0

Quick start

var generator = new SchemeGenerator();
var json = generator.GetDefaultJson(typeof(ComplexType));

// or with generics
var model = generator.GetDefault<ComplexType>();
var json2 = generator.GetDefaultJson<ComplexType>();

Dependency injection

builder.Services.AddSchemeGenerator(options =>
{
    options.CollectionItemCount = 2;
    options.PrimitiveMode = PrimitiveDefaultsMode.Sample;
});

// inject ISchemeGenerator

Options

Property Default Description
CollectionItemCount 1 Items in arrays and collections
MaxDepth 32 Max recursion depth (cycle safety)
PrimitiveMode Zero Zero = CLR defaults; Sample = realistic primitives
JsonSerializerOptions null Passed to GetDefaultJson

Attributes

Attribute Target Description
[SchemeIgnore] Property Skip property
[SchemeCount(n)] Property Override collection size
[SchemeValue(x)] Property Fixed value
[GenerateSchemeDefaults] Type Enable source generator (type must be partial)

Populate existing instances

var target = new SimpleType();
generator.Populate(target);

Source generator

Mark a partial type and reference the analyzer package:

[GenerateSchemeDefaults]
public partial class OrderDto
{
    public int Id { get; set; }
    public string Sku { get; set; } = string.Empty;
}

var order = OrderDto.OrderDtoSchemeDefaults.Create();
var json = OrderDto.OrderDtoSchemeDefaults.CreateJson();

Nested user types without [GenerateSchemeDefaults] fall back to the reflection-based SchemeGenerator at runtime.

xUnit integration

dotnet add package SchemeGenerator.Xunit --version 10.1.0
[Theory, AutoSchemeData<ComplexType>]
public void MyTest(ComplexType model) => Assert.NotNull(model);

[Theory, SchemeGeneratorData(typeof(SimpleType))]
public void OtherTest(SimpleType model) => Assert.NotNull(model);

ASP.NET Core / Swashbuckle

dotnet add package SchemeGenerator.AspNetCore --version 10.1.0
builder.Services.AddSchemeGenerator();

builder.Services.AddSwaggerGen(options =>
{
    options.AddSchemeGeneratorExamples();
});

Register SchemeGeneratorSchemaFilter via DI (Swashbuckle resolves it from the container when using AddSchemeGeneratorExamples).

Example output

public class SimpleType
{
    public int Number { get; set; }
    public string Text { get; set; }
}

public class ComplexType
{
    public List<int> Numbers { get; set; }
    public List<SimpleType> Objects { get; set; }
}

Default JSON (PrimitiveMode.Zero):

{
  "Numbers": [0],
  "Objects": [{ "Number": 0, "Text": "" }]
}

Benchmarks

See SchemeGenerator.Benchmarks:

dotnet run -c Release --project SchemeGenerator.Benchmarks

Compares reflection vs source-generated creation for the same DTO.

Building locally

dotnet restore
dotnet test -c Release
dotnet pack SchemeGenerator/SchemeGenerator.csproj -c Release
dotnet pack SchemeGenerator.SourceGenerators/SchemeGenerator.SourceGenerators.csproj -c Release
dotnet pack SchemeGenerator.Xunit/SchemeGenerator.Xunit.csproj -c Release
dotnet pack SchemeGenerator.AspNetCore/SchemeGenerator.AspNetCore.csproj -c Release

Contributing

See CONTRIBUTING.md. Release notes: CHANGELOG.md.

License

MIT — see LICENSE.

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 is compatible.  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.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
10.1.0 92 6/4/2026
9.0.0 242 1/2/2025
1.0.1 218 2/16/2024
1.0.0 209 2/14/2024