SharpSchema 1.2.9-beta

This is a prerelease version of SharpSchema.
dotnet add package SharpSchema --version 1.2.9-beta                
NuGet\Install-Package SharpSchema -Version 1.2.9-beta                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SharpSchema" Version="1.2.9-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpSchema --version 1.2.9-beta                
#r "nuget: SharpSchema, 1.2.9-beta"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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