AvroSchemaGenerator 2.9.2

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

License

This project is licensed under the Apache License Version 2.0 - see the LICENSE file for details.

Showing the top 20 packages that depend on AvroSchemaGenerator.

Packages Downloads
Pulsar.Client
.NET client library for Apache Pulsar
2

• Add netstandard2.0 • [update] NUKE 7.0.2

Full changelog at https://github.com/eaba/AvroSchemaGenerator/blob/refs/tags/2.9.2/CHANGELOG.md

Version Downloads Last updated
2.10.0 0 12/16/2023
2.9.2 2 04/16/2026
2.9.1 0 03/19/2023
2.9.0 0 02/04/2023
2.9.0-rc.39 0 02/03/2023
2.9.0-rc.15 0 01/09/2023
2.9.0-rc.6 0 01/09/2023
2.8.1 0 01/09/2023
2.8.0 0 12/24/2022
2.8.0-rc.22 0 12/24/2022
2.8.0-rc.21 0 12/24/2022
2.8.0-rc.13 0 12/24/2022
2.8.0-rc.6 0 12/24/2022
2.7.0 0 07/20/2022
2.7.0-rc.139 0 07/20/2022
2.7.0-rc.138 0 07/20/2022
2.6.0 0 02/20/2022
2.6.0-rc.136 0 07/19/2022
2.5.2-alpha.2 0 01/16/2022
2.5.2-Alpha.1 0 01/16/2022
2.5.1 0 01/13/2022
2.5.0 0 12/26/2021
2.4.1 0 10/27/2021
2.4.0 0 09/28/2021
2.4.0-beta 0 09/28/2021
2.3.3 0 09/15/2021
2.3.3-beta 0 09/15/2021
2.3.2 0 09/15/2021
2.3.1-beta 0 09/15/2021
2.3.0 0 09/15/2021
2.2.0 0 09/13/2021
2.2.0-beta.17 0 09/13/2021
2.1.0 0 09/11/2021
2.1.0-beta.16 0 09/13/2021
2.1.0-beta.15 0 09/11/2021
2.0.0 0 09/10/2021
2.0.0-beta.14 0 09/09/2021
1.9.0 0 04/14/2021
1.9.0-beta.13 0 09/09/2021
1.9.0-beta.12 0 04/14/2021
1.9.0-beta.11 0 04/14/2021
1.9.0-beta.10 0 04/13/2021
1.9.0-beta.9 0 04/13/2021
1.9.0-beta.5 0 04/13/2021
1.9.0-beta.3 0 04/13/2021
1.9.0-beta.2 0 04/11/2021
1.8.0 0 12/10/2020
1.7.0 0 11/04/2020
1.6.0 0 06/26/2020
1.5.4 0 06/21/2020
1.5.3 0 05/27/2020
1.5.2 0 05/13/2020
1.5.1 0 05/13/2020
1.5.0 0 05/13/2020
1.4.1 0 05/11/2020
1.4.0 0 05/11/2020
1.3.0 0 04/30/2020
1.2.0 0 04/28/2020
1.1.0 0 04/27/2020
1.0.0 0 04/27/2020
0.1.2 0 04/14/2020
0.1.1 0 04/14/2020
0.1.0 0 04/11/2020