Class JsonSchemaContext
- Namespace
- Nerdbank.Json
- Assembly
- Nerdbank.Json.dll
Drives generation of a JSON Schema document, resolving nested schemas, shared definitions, and recursive types. Provided to GetJsonSchema(JsonSchemaContext, ITypeShape) so custom converters can describe nested types consistently.
public sealed class JsonSchemaContext : ITypeShapeFunc
- Inheritance
-
JsonSchemaContext
- Implements
- Inherited Members
Properties
Dialect
Gets the dialect that converter-generated schema fragments must conform to.
public JsonSchemaDialect Dialect { get; }
Property Value
Methods
ApplyTupleSchema(JsonSchema, IReadOnlyList<JsonSchema>, JsonSchema?)
Adds positional array constraints to an existing schema using the selected dialect.
public void ApplyTupleSchema(JsonSchema schema, IReadOnlyList<JsonSchema> items, JsonSchema? additionalItemsSchema = null)
Parameters
schemaJsonSchemaThe schema to modify.
itemsIReadOnlyList<JsonSchema>The schema for each successive array position.
additionalItemsSchemaJsonSchemaThe schema for positions after those in
items, if permitted.
Exceptions
- ArgumentException
itemsis empty.
CreateTupleSchema(IReadOnlyList<JsonSchema>, JsonSchema?)
Creates an array schema with positional constraints using the selected dialect.
public JsonSchema CreateTupleSchema(IReadOnlyList<JsonSchema> items, JsonSchema? additionalItemsSchema = null)
Parameters
itemsIReadOnlyList<JsonSchema>The schema for each successive array position.
additionalItemsSchemaJsonSchemaThe schema for positions after those in
items, if permitted.
Returns
- JsonSchema
An array schema with the specified positional constraints.
Exceptions
- ArgumentException
itemsis empty.
GetSchema(ITypeShape)
Gets the schema for a type shape, resolving shared definitions and recursion.
public JsonSchema GetSchema(ITypeShape typeShape)
Parameters
typeShapeITypeShapeThe shape of the type.
Returns
- JsonSchema
The schema, which may be a
$refto a shared definition.