Class ValueObjectJsonSchema
Namespace: AdCodicem.ValueObjects.Json
Assembly: AdCodicem.ValueObjects.Json.dll
Describes a value object in a JSON Schema exported by System.Text.Json as its underlying value, carrying the rules declared on it.
public static class ValueObjectJsonSchema
Inheritance
object ← ValueObjectJsonSchema
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
true, the schema that accepts anything, leaves
items out of a collection of them, and loses the null a nullable one accepts. Plugged into
Validate enforces:
var schema = JsonSchemaExporter.GetJsonSchemaAsNode(
AppJsonContext.Default.Options,
typeof(Order),
new JsonSchemaExporterOptions { TransformSchemaNode = ValueObjectJsonSchema.TransformSchemaNode });
The underlying type gives type, and "null" joins it, and the enum, for a nullable value object.
MinLength and MaxLength give minLength and maxLength, one character both for a
pattern, and a bound minimum or maximum on a number; on a value
written as a string, a date, a time or a character, which those keywords cannot bound, a sentence of the description
states it. A duration, a enum, and the
example goes to examples, each written by the value object's own converter. The description and the format
follow, the format as the profile says (
A collection or a dictionary of value objects gets its items or additionalProperties, which the
exporter leaves out when the element's schema is true, and a dictionary keyed by a value object gets the key's
rules in propertyNames, as the key is written: always text, the text of a number for a value object over a
number. A value object is described in place, never as a reference.
The schema a host hands over is completed rather than replaced: a description it already wrote comes first, the
value object's following it, and a keyword the value object does not declare, such as a default, stays.
Every host built on the exporter exposes the
A value object is looked up in
Methods
Apply(JsonTypeInfo, JsonNode, ValueObjectJsonSchemaProfile)
Describes the value object a schema node stands for, or the value objects a collection or a dictionary holds.
public static JsonNode Apply(JsonTypeInfo typeInfo, JsonNode schema, ValueObjectJsonSchemaProfile profile = ValueObjectJsonSchemaProfile.OpenApi)
Parameters
typeInfo JsonTypeInfo
The contract of the node's type, under the options the schema describes the wire with.
schema JsonNode
The schema built so far for the node, true for a value object.
profile ValueObjectJsonSchemaProfile
Whom the schema describes a value object for.
Returns
The schema: a new object in place of true, the same object completed otherwise, or the schema unchanged when
the node is neither a value object nor a container of them, or the schema false.
Remarks
This is the piece every host shares: each one that builds on
var options = new AIJsonSchemaCreateOptions
{
TransformSchemaNode = (context, schema) => ValueObjectJsonSchema.Apply(
context.TypeInfo, schema, ValueObjectJsonSchemaProfile.LanguageModel),
};
The node of a value object is
Exceptions
typeInfo or schema is
null.
profile is not a defined profile.
CreateTransform(ValueObjectJsonSchemaProfile)
Creates the transform
public static Func<JsonSchemaExporterContext, JsonNode, JsonNode> CreateTransform(ValueObjectJsonSchemaProfile profile)
Parameters
profile ValueObjectJsonSchemaProfile
Whom the schema describes a value object for.
Returns
Func<JsonSchemaExporterContext, JsonNode, JsonNode>
The transform, the same instance for a given profile.
Remarks
var options = new JsonSchemaExporterOptions
{
TransformSchemaNode = ValueObjectJsonSchema.CreateTransform(ValueObjectJsonSchemaProfile.LanguageModel),
};
Exceptions
profile is not a defined profile.
TransformSchemaNode(JsonSchemaExporterContext, JsonNode)
Describes the value objects of a schema the exporter builds, under the
public static JsonNode TransformSchemaNode(JsonSchemaExporterContext context, JsonNode schema)
Parameters
context JsonSchemaExporterContext
The context of the node, which names its type.
schema JsonNode
The schema the exporter built for the node.
Returns
The schema, completed when it describes a value object or a container of value objects.
Exceptions
schema is null.