SharpSchema 0.1.602-rc
This is a prerelease version of SharpSchema.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SharpSchema --version 0.1.602-rc
NuGet\Install-Package SharpSchema -Version 0.1.602-rc
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="0.1.602-rc" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpSchema --version 0.1.602-rc
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SharpSchema, 0.1.602-rc"
#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=0.1.602-rc&prerelease // Install SharpSchema as a Cake Tool #tool nuget:?package=SharpSchema&version=0.1.602-rc&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SharpSchema (Core Library)
Conversion Rules
General
- Object graph depth is limited to 50 levels by default. This can be overridden using the
MaxDepth
property ofConveterContext
. - Preference is for tight schemas with no extra properties or items.
Names
- Property names are camelCased.
- Enum values are kebab-cased.
- '+' and '`' are replaced with '_'.
- Overrides can be provided using the
System.Text.Json.JsonPropertyNameAttribute
.
Schema Root
A schema root class or struct must be annotated with SharpSchema.Annotations.SchemaRootAttribute
.
Objects
Whether a property is required is determined by the nullability of the property.
- It is assumed that nullable reference types are enabled for all input assemblies.
- A
Nullable<T>
will be optional. - A
T?
will be optional. - Use
SharpSchema.Annotations.SchemaRequiredAttribute
to make a property with a nullable type required.- This will generate a
OneOf
schema, allowing either the schema of the type, ornull
. The property will also be listed asrequired
.
- This will generate a
- Use
SharpSchema.Annotations.SchemaRequiredAttribute(false)
to make a property with a non-nullable type optional.
All public properties with a public getter will be part of the generated schema.
- Private properties can be included using
System.Text.Json.JsonIncludeAttribute
. - Public properties can be excluded using
SharpSchema.Annotations.SchemaIgnoreAttribute
.
- Private properties can be included using
Example
using System.Text.Json;
using SharpSchema.Annotations;
public class Example
{
public bool? Optional { get; set; }
public bool Required { get; set; }
[SchemaRequired(false)]
public bool OptionalWithRequiredAttribute { get; set; }
[JsonInclude]
[SchemaRequired]
private bool? RequiredWithRequiredAttribute { get; set; }
[SchemaIgnore]
public bool Ignored { get; set; }
}
{
"type": "object",
"properties": {
"optional": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "null"
}
]"
},
"required": {
"type": "boolean"
},
"optionalWithRequiredAttribute": {
"type": "boolean"
},
"requiredWithRequiredAttribute": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "null"
}
]
}"
},
"required": [
"required",
"requiredWithRequiredAttribute"
]
}
Arrays and Enumerable
Dictionaries
- Only dictionaries with string keys are supported.
Numbers
- All integral types are emitted as
integers
. - Floating point types and
decimal
are emitted asnumber
. - All number schema also have min/max values clamped to the valid .NET range for the type.
- The range can be overridden using the
SharpSchema.Annotations.ValueRangeAttribute
.
Abstract Types & Interfaces
- Abstract types and interfaces are emitted without properties, as OneOf schemas with all discovered implementing types.
- Interfaces are not emitted by default.
- Only types in the same assembly as the abstract type are added to the schema for the abstract type.
- Only types discovered while enumerating the root objects are added to the schema for the interface type.
Title and Description
- The default title of a property is derived from the property name.
- Title, Description and Comment can be overridden using the
SharpSchema.Annotations.SchemaMetaAttribute
.
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- JsonSchema.Net (>= 7.0.2)
- Microsoft.VisualStudio.Validation (>= 17.8.8)
- SharpSchema.Annotations (>= 0.1.602-rc)
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 |