SharpSchema 1.3.21-beta

This is a prerelease version of SharpSchema.
dotnet add package SharpSchema --version 1.3.21-beta
                    
NuGet\Install-Package SharpSchema -Version 1.3.21-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.3.21-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpSchema" Version="1.3.21-beta" />
                    
Directory.Packages.props
<PackageReference Include="SharpSchema" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SharpSchema --version 1.3.21-beta
                    
#r "nuget: SharpSchema, 1.3.21-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.
#:package SharpSchema@1.3.21-beta
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SharpSchema&version=1.3.21-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SharpSchema&version=1.3.21-beta&prerelease
                    
Install as a Cake Tool

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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.3.21-beta 60 1/16/2025
1.2.9-beta 71 1/7/2025
1.2.1-alpha 69 1/6/2025
0.3.33-rc 77 11/10/2024
0.3.32-rc 66 11/3/2024
0.2.6-rc 78 5/29/2024
0.1.602-rc 76 5/28/2024