SharpSchema 1.2.9-beta
dotnet add package SharpSchema --version 1.2.9-beta
NuGet\Install-Package SharpSchema -Version 1.2.9-beta
<PackageReference Include="SharpSchema" Version="1.2.9-beta" />
paket add SharpSchema --version 1.2.9-beta
#r "nuget: SharpSchema, 1.2.9-beta"
// Install SharpSchema as a Cake Addin #addin nuget:?package=SharpSchema&version=1.2.9-beta&prerelease // Install SharpSchema as a Cake Tool #tool nuget:?package=SharpSchema&version=1.2.9-beta&prerelease
SharpSchema
SharpSchema is a very opiniated tool for transforming C# class hierarchies into JSON schema.
It is designed to work with your System.Text.Json
deserialization library. SchemaSharp.Annotations
provides
attributes you can apply to your DTOs to express JSON-Schema validation constraints that aren't possible
to express with pure C#.
Examples
SimplePerson
namespace SharpSchema.Tests;
public record SimplePerson(
string Surname,
string? FamilyName,
DateTime DateOfBirth,
SimplePerson.RoleKind Role)
{
public enum RoleKind
{
User,
SectionAdmin,
SystemAdmin,
}
[SchemaIgnore]
public int Age => (int)((DateTime.Now - this.DateOfBirth).TotalDays / 365.25);
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"surname": {
"$comment": "string",
"type": "string",
"title": "Surname"
},
"familyName": {
"oneOf": [
{
"$comment": "string",
"type": "string"
},
{
"type": "null"
}
],
"title": "Family Name"
},
"dateOfBirth": {
"$comment": "DateTime",
"type": "string",
"format": "date-time",
"title": "Date of Birth"
},
"role": {
"$comment": "RoleKind",
"type": "string",
"enum": [
"user",
"section-admin",
"system-admin"
],
"title": "Role"
}
},
"required": [
"surname",
"dateOfBirth",
"role"
],
"additionalProperties": false
}
$schema
Currently, only draft-07 is supported.
properties
Each property name is camel-cased by default.
surname
$comment
By default, the comment is the .NET type name.
title
By default, the title is the property name converted to title case.
Product | Versions 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 was computed. 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. |
-
net8.0
- JsonSchema.Net (>= 7.3.1)
- libanvl.opt (>= 2.7.7-beta)
- Microsoft.VisualStudio.Validation (>= 17.8.8)
- SharpMeta (>= 2.1.5-alpha)
- SharpSchema.Annotations (>= 1.2.9-beta)
- System.Reflection.MetadataLoadContext (>= 9.0.0)
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 |
---|---|---|
1.2.9-beta | 35 | 1/7/2025 |
1.2.1-alpha | 39 | 1/6/2025 |
0.3.33-rc | 57 | 11/10/2024 |
0.3.32-rc | 52 | 11/3/2024 |
0.2.6-rc | 69 | 5/29/2024 |
0.1.602-rc | 62 | 5/28/2024 |