Table of Contents

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

JsonSchemaDialect

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

schema JsonSchema

The schema to modify.

items IReadOnlyList<JsonSchema>

The schema for each successive array position.

additionalItemsSchema JsonSchema

The schema for positions after those in items, if permitted.

Exceptions

ArgumentException

items is 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

items IReadOnlyList<JsonSchema>

The schema for each successive array position.

additionalItemsSchema JsonSchema

The schema for positions after those in items, if permitted.

Returns

JsonSchema

An array schema with the specified positional constraints.

Exceptions

ArgumentException

items is empty.

GetSchema(ITypeShape)

Gets the schema for a type shape, resolving shared definitions and recursion.

public JsonSchema GetSchema(ITypeShape typeShape)

Parameters

typeShape ITypeShape

The shape of the type.

Returns

JsonSchema

The schema, which may be a $ref to a shared definition.