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
|
1 |
• Add netstandard2.0
• [update] NUKE 7.0.2
Full changelog at https://github.com/eaba/AvroSchemaGenerator/blob/refs/tags/2.9.2/CHANGELOG.md
.NET 7.0
- System.ComponentModel.Annotations (>= 5.0.0)
- System.Text.Json (>= 7.0.3)
.NET Standard 2.0
- System.ComponentModel.Annotations (>= 5.0.0)
- System.Text.Json (>= 7.0.3)
| Version | Downloads | Last updated |
|---|---|---|
| 2.10.0 | 1 | 2026/4/12 |
| 2.9.2 | 1 | 2025/4/29 |
| 2.9.1 | 0 | 2023/3/19 |
| 2.9.0 | 0 | 2023/2/4 |
| 2.9.0-rc.39 | 0 | 2023/2/3 |
| 2.9.0-rc.15 | 0 | 2023/1/9 |
| 2.9.0-rc.6 | 0 | 2023/1/9 |
| 2.8.1 | 0 | 2023/1/9 |
| 2.8.0 | 0 | 2022/12/24 |
| 2.8.0-rc.22 | 0 | 2022/12/24 |
| 2.8.0-rc.21 | 0 | 2022/12/24 |
| 2.8.0-rc.13 | 0 | 2022/12/24 |
| 2.8.0-rc.6 | 0 | 2022/12/24 |
| 2.7.0 | 0 | 2022/7/20 |
| 2.7.0-rc.139 | 0 | 2022/7/20 |
| 2.7.0-rc.138 | 0 | 2022/7/20 |
| 2.6.0 | 0 | 2022/2/20 |
| 2.6.0-rc.136 | 0 | 2022/7/19 |
| 2.5.2-alpha.2 | 0 | 2022/1/16 |
| 2.5.2-Alpha.1 | 0 | 2022/1/16 |
| 2.5.1 | 0 | 2022/1/13 |
| 2.5.0 | 0 | 2021/12/26 |
| 2.4.1 | 0 | 2021/10/27 |
| 2.4.0 | 0 | 2021/9/28 |
| 2.4.0-beta | 1 | 2026/4/8 |
| 2.3.3 | 0 | 2021/9/15 |
| 2.3.3-beta | 0 | 2021/9/15 |
| 2.3.2 | 0 | 2021/9/15 |
| 2.3.1-beta | 0 | 2021/9/15 |
| 2.3.0 | 0 | 2021/9/15 |
| 2.2.0 | 0 | 2021/9/13 |
| 2.2.0-beta.17 | 0 | 2021/9/13 |
| 2.1.0 | 0 | 2021/9/11 |
| 2.1.0-beta.16 | 0 | 2021/9/13 |
| 2.1.0-beta.15 | 0 | 2021/9/11 |
| 2.0.0 | 0 | 2021/9/10 |
| 2.0.0-beta.14 | 0 | 2021/9/9 |
| 1.9.0 | 0 | 2021/4/14 |
| 1.9.0-beta.13 | 0 | 2021/9/9 |
| 1.9.0-beta.12 | 0 | 2021/4/14 |
| 1.9.0-beta.11 | 0 | 2021/4/14 |
| 1.9.0-beta.10 | 0 | 2021/4/13 |
| 1.9.0-beta.9 | 0 | 2021/4/13 |
| 1.9.0-beta.5 | 1 | 2026/4/10 |
| 1.9.0-beta.3 | 1 | 2026/4/10 |
| 1.9.0-beta.2 | 1 | 2026/4/10 |
| 1.8.0 | 0 | 2020/12/10 |
| 1.7.0 | 0 | 2020/11/4 |
| 1.6.0 | 0 | 2020/6/26 |
| 1.5.4 | 0 | 2020/6/21 |
| 1.5.3 | 0 | 2020/5/27 |
| 1.5.2 | 0 | 2020/5/13 |
| 1.5.1 | 0 | 2020/5/13 |
| 1.5.0 | 0 | 2020/5/13 |
| 1.4.1 | 0 | 2020/5/11 |
| 1.4.0 | 0 | 2020/5/11 |
| 1.3.0 | 0 | 2020/4/30 |
| 1.2.0 | 0 | 2020/4/28 |
| 1.1.0 | 0 | 2020/4/27 |
| 1.0.0 | 0 | 2020/4/27 |
| 0.1.2 | 0 | 2020/4/14 |
| 0.1.1 | 0 | 2020/4/14 |
| 0.1.0 | 0 | 2020/4/11 |