Skip to content

AspNetCore Expo OpenAPI

SteffenBlake edited this page Sep 28, 2026 · 1 revision

Expo OpenAPI

Expo's ASP.NET Core OpenAPI integration adds validation constraints to generated API documents. It describes the rules that API consumers need when constructing requests. Runtime validation still comes from [ExpoSystemBundle].

Install and register

In the ASP.NET Core project, install the generator integration:

dotnet add package Brigade.Net.Partie.Extensions.Expo.Engines.AspNetCore

Configure ASP.NET Core OpenAPI with the generated AddExpo helper:

builder.Services.AddOpenApi(options =>
{
    options.AddExpo();
});

...

var app = builder.Build();

app.UsePartieRoutes();
app.MapOpenApi();

The generated helper is in Microsoft.AspNetCore.OpenApi. Keep [Expo] on models whose rules should appear in schemas. The generator also discovers marked models in referenced assemblies.

Published constraints

Expo rule OpenAPI representation
[IsRequired] Required property or request body
Inclusive constant comparisons Minimum or maximum
Exclusive constant comparisons Exclusive minimum or maximum
Equality to a constant Constant constraint
Inequality to a constant Negated constant constraint
String length rules Minimum and maximum string length
Collection size rules Minimum and maximum item count
Built-in formats Format or regex pattern
Generated regex rules Regex pattern

Rules placed on collection items apply to the item schema. A minimum string length on List<string> constrains each string, while [ItemsHasMinimumLength] constrains the array length.

For path, query, and metadata binding, the integration adds rules to the matching parameter schema. JSON payload requiredness applies to the request body. Form payload rules apply to body properties, including required form fields.

Rules without an exact schema equivalent

Custom rules, comparisons between properties, whitespace checks, and defined-enum checks can require runtime logic that a schema constraint does not fully express. The integration adds a description naming the Expo rule for those cases.

A description does not make an API client enforce that rule. Keep runtime validation enabled, and provide clear messages for input that passes a client's schema checks but fails a model rule.

See Expo validation in ASP.NET Core for enforcement and Errors and metadata for the model's rule descriptions and field paths.

Clone this wiki locally