Skip to content

An MSBuild task to generate json schema validation for .NET POCO classes

Notifications You must be signed in to change notification settings

JeffBarnard/JsonSchemaTask.NET

Repository files navigation

JsonSchemaTask.NET

An MSBuild task to generate json schema validation for .NET POCO classes. Compatible with full .NET Framework MSBuild (Visual Studio).

Supports both Newtonsoft JsonSchema.NET and NJsonSchema generation libraries.

Usage

<UsingTask TaskName = "JsonSchemaTask" AssemblyFile="..\JsonSchemaTask.NET\bin\Debug\netstandard2.0\JsonSchemaTask.dll" />
<Target Name = "SchemaTarget" AfterTargets="Build">
	 <JsonSchemaTask AssemblyName = "$(AssemblyName)" AssemblyPath="$(OutputPath)" ModelDirectory="Models\" ConvertDirectory="JsonSchema\" />
</Target>

Models can be annotated for validation rules using standard System.ComponentModel.DataAnnotations attributes.

[Required]
[ReadOnly]
[Description]
[DisplayName]
[DefaultValue]
[MaxLength]
[Range]
[RegularExpression]
[Url]
[EnumDataType]

Model properties can be opt-in for json schema generation by adding the [JsonSchemaInclude] annotation.

[JsonSchemaInclude]
string Name { get; set; }

TODO

Create a nuget package for easy integration into projects

https://learn.microsoft.com/en-us/visualstudio/msbuild/tutorial-custom-task-code-generation?view=vs-2022

About

An MSBuild task to generate json schema validation for .NET POCO classes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages