Skip to main content
Version: 0.2.x (0.2.1)

Document in OpenAPI

dotnet add package AdCodicem.ValueObjects.OpenApi
builder.Services.AddOpenApi(options => options.AddValueObjects());

That registers a schema transformer on the built-in .NET OpenAPI stack (Microsoft.AspNetCore.OpenApi). A value object is then documented as what it is on the wire — its underlying type — carrying every rule declared on it:

Declared on the typeIn the schema
The underlying typetype
SchemaFormat, or the natural format of the type (uuid, date, int64…)format
MinLength, MaxLengthminLength, maxLength
Patternpattern
Minimum, Maximumminimum, maximum
[KnownValue] on a closed setenum
Examplean example
Description, or the type's XML <summary>description

So this declaration:

[ValueObject<string>(
MinLength = 15,
MaxLength = 34,
Pattern = "^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$",
SchemaFormat = "iban",
Example = "FR7630006000011234567890189")]
public readonly partial struct Iban;

is documented as a string of format iban, between 15 and 34 characters, matching the pattern — never as an object with a value property. There is nothing to restate in an annotation, and nothing to keep in sync: the schema comes from the declaration that validates.

The transformer targets the built-in OpenAPI stack. Swashbuckle is not supported.