Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectSchema

Namespace: AdCodicem.ValueObjects.Metadata
Assembly: AdCodicem.ValueObjects.Abstractions.dll

The declarative constraints of a value object, captured once at compile time.

public sealed record ValueObjectSchema : IEquatable<ValueObjectSchema>

Inheritance​

object ← ValueObjectSchema

Implements​

IEquatable<ValueObjectSchema>

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

The generator fills this from the ValueObjectAttribute so that the rules enforced by Validate and the rules published in the OpenAPI schema or applied to an EF Core column can never drift apart: they all read the same instance.

That instance is the value object's , which generic code reads through its type parameter and the registration hands the descriptor. A value object written by hand builds its own, stating the rules its Validate enforces.

Properties​

Comparison​

Gets how the value object compares two values of its text, if the schema states it.

public StringComparison? Comparison { get; init; }

Property Value​

StringComparison?

Remarks​

The generator states here the Comparison of the ValueObjectAttribute on every value object over text, where the attribute declares none, and leaves it null on a value object over any other type. Equality, ordering and hashing compare this way, and so does the lookup of a closed set's .

A check written from the known values alone and compared exactly, the enum of the MongoDB collection validator or the IN of an Entity Framework Core CHECK constraint, reads it: a closed set compared stores each value as its known value is spelled and gets one; a set compared as a culture compares may store another spelling of a known value, longer, shorter or of the same length, and gets none; a set compared gets one when its normalizer spells every other case back.

A schema built by hand states the comparison its Validate looks the known values up with. Left null, those checks try the spellings a comparison ignoring case, or a culture's ignoring a soft hyphen, would take for a known value, and write one when the type stores none of them; a culture's comparison takes other spellings still, so a schema over such a set states it.

Description​

Gets the human-readable description of the value object, if any.

public string? Description { get; init; }

Property Value​

string?

Example​

Gets an example value, boxed, if any.

public object? Example { get; init; }

Property Value​

object?

Remarks​

The generator holds here the underlying value of the example the value object declares through , as holds its known values, and the schemas write it as the type writes it in JSON. A schema built by hand may hold the text of the value instead, which they read in the invariant culture as the type parses it.

Format​

Gets the OpenAPI format keyword for the value, if any.

public string? Format { get; init; }

Property Value​

string?

IsClosedValueSet​

Gets a value indicating whether only are accepted.

public bool IsClosedValueSet { get; init; }

Property Value​

bool

IsUnicode​

Gets whether the text is stored as Unicode text, if the schema states it: false for a value object declaring Unicode = false.

public bool? IsUnicode { get; init; }

Property Value​

bool?

Remarks​

The generator states false where the declaration does, and leaves it null otherwise, an entity identifier's included. The Entity Framework Core conventions map such a value object to non-Unicode text, and the Dapper handler declares its parameters DbType.AnsiString; true and null leave both to the provider. It is no rule: nothing validates the text against it. A schema built by hand states it as the option would.

KnownValueDetails​

Gets the declared known values with the name and the description each was declared with, in declaration order.

public ImmutableArray<KnownValueInfo> KnownValueDetails { get; init; }

Property Value​

ImmutableArray<KnownValueInfo>

Remarks​

The generator lists here the values of , in the same order, each the same value, with the name of the static property it creates for it and the Description its attribute gives, if any. The OpenAPI integration publishes the names of a closed value set beside its enum, as x-enum-varnames, x-enumNames and x-ms-enum, which client generators name the members of their enumeration after.

A schema built by hand fills it as well, listing the values of in the same order, each equal to its counterpart. The OpenAPI integration publishes no name otherwise, rather than one beside the wrong value, and the contract kit of AdCodicem.ValueObjects.Testing fails a schema that leaves it empty beside known values, or out of step with them.

KnownValues​

Gets the declared known underlying values, boxed, in declaration order.

public ImmutableArray<object> KnownValues { get; init; }

Property Value​

ImmutableArray<object>

Remarks​

Surfaced as the enum keyword of the OpenAPI schema. lists the same values with their names and descriptions.

MaxLength​

Gets the maximum accepted length, if any.

public int? MaxLength { get; init; }

Property Value​

int?

Remarks​

Used by the EF Core integration to size the mapped column.

Maximum​

Gets the inclusive upper bound in invariant culture, if any.

public string? Maximum { get; init; }

Property Value​

string?

MinLength​

Gets the minimum accepted length, if any.

public int? MinLength { get; init; }

Property Value​

int?

Minimum​

Gets the inclusive lower bound in invariant culture, if any.

public string? Minimum { get; init; }

Property Value​

string?

Pattern​

Gets the regular expression the value must match, if any.

public string? Pattern { get; init; }

Property Value​

string?

Unconstrained​

Gets the schema of a value object that declares no constraint.

public static ValueObjectSchema Unconstrained { get; }

Property Value​

ValueObjectSchema