AvroSchemaGenerator 2.8.0

AvroSchemaGenerator

Use to generate Avro Schema with support for RECURSIVE SCHEMA

Getting Started

Install the NuGet package AvroSchemaGenerator and copy/paste the code below

using AvroSchemaGenerator;
public class Course
{
    public string Level { get; set; }
        
    public int Year { get; set; }
        
    public string State { get; set; }
        
    public string Gender { get; set; }
}
var avroSchema = typeof(Course).GetSchema();

By default, AvroSchemaGenerator generates schema with optional fields. The code below is an example of how to mark fields as required

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using AvroSchemaGenerator;
public class Course
{
    [Required]
    public string Level { get; set; }

    [Required]
    public int Year { get; set; }

    [Required]
    public string State { get; set; }
        
    [Required]
    public string Gender { get; set; }
}
var avroSchema = typeof(Course).GetSchema();

You can assign a default value as well

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using AvroSchemaGenerator;
public class Course
{
    [DefaultValue("200")]
    [Required]
    public string Level { get; set; }

    [Required]
    public int Year { get; set; }

    [DefaultValue("Closed")]
    public string State { get; set; }

    public string Gender { get; set; }
}
var avroSchema = typeof(Course).GetSchema();

Aliases

[Aliases("OldCourse")]
public class Course
{
    [Aliases("Level")]
    public string NewLevel { get; set; }
}

Logical Types

public class MessageTimeKind
{
    [LogicalType(LogicalTypeKind.TimeMicrosecond)]
    public TimeSpan TimeMicros { get; set; }

    [LogicalType(LogicalTypeKind.TimeMillisecond)]
    public TimeSpan TimeMillis { get; set; }
}
	
public class MessageTimestampKind
{
    [LogicalType(LogicalTypeKind.TimestampMicrosecond)]
    public DateTime StampMicros { get; set; }

    [LogicalType(LogicalTypeKind.TimestampMillisecond)]
    public DateTime StampMillis { get; set; }
}
	
public class MessageDateKind
{
    [LogicalType(LogicalTypeKind.Date)]
    public DateTime CreatedTime { get; set; }
        
    public AvroDecimal Size { get; set; }
        
	public string DayOfWeek { get; set; }
}

Custom Avro Definition

public class CustomDefinition
{
    [AvroSchema("{\n" +
                "  \"type\": \"bytes\",\n" +
                "  \"logicalType\": \"decimal\",\n" +
                "  \"precision\": 10,\n" +
                "  \"scale\": 6\n" +
                "}")]
    public AvroDecimal DecimalAvro { get; set; }
}

NOTE

  • Don't use same declaring type as dictionary value
  • Don't use same declaring type as list argument
  • Dictionary key must be a string type

Showing the top 20 packages that depend on AvroSchemaGenerator.

Packages Downloads
Pulsar.Client
.NET client library for Apache Pulsar
3
Pulsar.Client
.NET client library for Apache Pulsar
4
Pulsar.Client
.NET client library for Apache Pulsar
5

• [update] .NET 7 • [fix] Resolves #64 Fixed that the same enum can be used multiple times in the schema @danny-krueger [https://github.com/eaba/AvroSchemaGenerator/pull/74/commits/ba622efc263f89ed8d5bc826493cf8a33637b580] Full changelog at https://github.com/eaba/AvroSchemaGenerator/blob/main/CHANGELOG.md

Version Downloads Last updated
2.10.0 4 2026/4/12
2.9.2 5 2025/4/29
2.9.1 3 2026/4/13
2.9.0 2 2026/4/13
2.9.0-rc.39 3 2026/4/13
2.9.0-rc.15 2 2026/4/13
2.9.0-rc.6 2 2026/4/13
2.8.1 4 2026/4/13
2.8.0 2 2026/4/13
2.8.0-rc.22 2 2026/4/13
2.8.0-rc.21 1 2026/4/13
2.8.0-rc.13 1 2026/4/13
2.8.0-rc.6 3 2026/4/13
2.7.0 2 2026/4/13
2.7.0-rc.139 2 2026/4/13
2.7.0-rc.138 1 2026/4/13
2.6.0 3 2026/4/13
2.6.0-rc.136 1 2026/4/13
2.5.2-alpha.2 3 2026/4/13
2.5.2-Alpha.1 2 2026/4/13
2.5.1 3 2026/4/13
2.5.0 3 2026/4/13
2.4.1 2 2026/4/13
2.4.0 2 2026/4/13
2.4.0-beta 2 2026/4/8
2.3.3 3 2026/4/13
2.3.3-beta 3 2026/4/13
2.3.2 2 2026/4/13
2.3.1-beta 3 2026/4/13
2.3.0 2 2026/4/13
2.2.0 3 2026/4/13
2.2.0-beta.17 2 2026/4/13
2.1.0 3 2026/4/13
2.1.0-beta.16 3 2026/4/13
2.1.0-beta.15 2 2026/4/13
2.0.0 3 2026/4/13
2.0.0-beta.14 1 2026/4/13
1.9.0 3 2026/4/13
1.9.0-beta.13 1 2026/4/13
1.9.0-beta.12 2 2026/4/13
1.9.0-beta.11 1 2026/4/13
1.9.0-beta.10 2 2026/4/13
1.9.0-beta.9 2 2026/4/13
1.9.0-beta.5 2 2026/4/10
1.9.0-beta.3 3 2026/4/10
1.9.0-beta.2 2 2026/4/10
1.8.0 2 2026/4/13
1.7.0 3 2026/4/13
1.6.0 3 2026/4/13
1.5.4 2 2026/4/13
1.5.3 4 2026/4/13
1.5.2 4 2026/4/12
1.5.1 2 2026/4/13
1.5.0 4 2026/4/13
1.4.1 2 2026/4/13
1.4.0 3 2026/4/13
1.3.0 4 2026/4/13
1.2.0 4 2026/4/13
1.1.0 4 2026/4/13
1.0.0 3 2026/4/13
0.1.2 5 2026/4/13
0.1.1 4 2026/4/13
0.1.0 4 2026/4/13