Contract Coverage
--check verifies that every [RivetContract] field is actually implemented, and that the implementation matches the declaration:
dotnet rivet --project path/to/Api.csproj --checkThe checker finds .Success(...), .Error(...), and .File(...) terminal calls for each contract field, including terminals reached through .Bind(input), in controller actions, minimal API handlers (whatever you hand MapGet/MapPost/ MapPut/MapDelete/MapPatch: a lambda, a local holding one, a local function, or a method group), and isolated Azure Functions using [Function], [HttpTrigger], and .ToActionResult(). Functions coverage reads the project's host.json HTTP prefix (default api) and honors the host environment override. See Azure Functions for conventions and a real-host test.
A Map* route can be a string constant or the contract field's own .Route, as in app.MapGet(MembersContract.Health.Route, …), and MapGroup prefixes count either way: the contract owns the full path, so a group prefix it doesn't declare is a RouteMismatch. A convention on the group doesn't lose it, so var api = app.MapGroup("/api").RequireAuthorization(); still prefixes api.MapGet(…).
Route-group helpers are followed both ways: into what a helper returns, and out of a helper's parameter to every call that passes it. So ASP.NET's own pattern, app.MapGroup("/todos").MapTodos() over static RouteGroupBuilder MapTodos(this RouteGroupBuilder group) { group.MapGet(…); return group; }, maps at /todos/…, and so does a this IEndpointRouteBuilder helper called on that group. A helper that returns a new group, as in static RouteGroupBuilder V2(this RouteGroupBuilder group) => group.MapGroup("/v2"), is that new group, /v2 and all, not the one it was handed. A helper you call from two groups maps its handlers twice, and each mapping is checked under its own prefix and its own group's authorization; when a handler has more than one mapping, each warning says which one it's about.
A builder handed in from outside the project is read as the app: an IEndpointRouteBuilder parameter nothing in the project passes (a framework-invoked AddRoutes(app), or Startup.Configure), or a lambda's. That's a limit, not a check: if such a builder is really a route group (a module called through an interface, say), its prefix and its conventions are out of sight. A RouteGroupBuilder parameter nothing passes is never read as the app, since its type says it's a group. Anything else (a variable, concatenation, interpolation, a MapGroup prefix that isn't a constant, or a builder --check can't follow to its MapGroup call or the app, such as a field, a group parameter nothing passes, or what a helper without source returns) is reported as an unresolved RouteMismatch, because --check won't guess a route.
--check reports eight kinds of finding on stderr. The first four are warnings; UnbindableEnumParameter (RIV4005), InputBindingMismatch (RIV4006), SecurityMismatch (RIV4008), and AuthorizationUnreadable (RIV4009) are errors:
| Finding | Meaning |
|---|---|
MissingImplementation | No contract response terminal found for the contract field. |
OrphanedBinding | The contract was bound in a route handler, but the handler neither returns a terminal built from that binding nor passes the binding to a helper whose answer it returns. |
HttpMethodMismatch | The implementing endpoint uses a different HTTP method than the contract declares. |
RouteMismatch | The implementing endpoint's route does not match the contract's route template. |
UnbindableEnumParameter | The handler binds an enum from the route, query, header or form (directly, or as a member of a complex parameter the host binds member by member), and its host would refuse one of the enum's advertised wire values. See below. |
InputBindingMismatch | The handler binds an input the contract doesn't declare, never binds one it does, or binds it from somewhere else. See below. |
SecurityMismatch | The spec says credentials are needed and anyone can call the handler, or the spec lets anonymous callers in and the handler turns them away. See below. |
AuthorizationUnreadable | Whether the handler requires authentication depends on setup --check can't read statically, such as a requirement applied only under an if. See below. |
A summary line is always printed:
Coverage: 6/6 endpoints covered. All OK.Enum parameters the host can't bind
One more check reads the handler's parameters rather than its terminals. When a handler binds an enum from the route, query, header or form, the spec lists the enum's wire values for that parameter, but it's ASP.NET doing the binding, not Rivet's JSON converter. Minimal APIs only take a value that equals the member name exactly. MVC takes one that equals it ignoring case. If any wire value won't bind on the handler's host, --check fails with RIV4005:
[JsonConverter(typeof(RivetCamelCaseEnumConverter<Kind>))]
public enum Kind { Footpath, RestrictedByway }
// The spec says ?kind=restrictedByway. Enum.TryParse is case-sensitive: 400.
app.MapGet(PathsContract.List.Route, (Kind kind) => …);The same handler as an MVC action passes, since restrictedByway matches ignoring case. Snake and kebab converters, and a [JsonStringEnumMemberName] that changes more than the casing, fail on both. A plain enum, the built-in JsonStringEnumConverter<T> with no renames, or a handler that binds a string and parses it itself are fine on both. Azure Functions is stricter still: the worker reads a route or query value as JSON, so no name binds at all, and only a plain enum or a string will do. The full story, including what the hosts accept beyond the spec, is in Limitations.
Inputs the handler doesn't bind where the contract says
The spec tells every client where to put each input: {id} in the path, ?q= in the query, X-Tenant in a header, the rest in the body. ASP.NET doesn't read the spec. It binds what the handler's parameters ask for, by their names and attributes. When the two drift apart the request still compiles, still routes, and quietly loses a value. --check lines them up and fails with RIV4006 when they disagree:
[RivetType]
public sealed record NoteSearch([property: JsonPropertyName("q")] string? Text);
// The spec says ?q=. [AsParameters] binds the member by its C# name: ?Text=.
app.MapGet(NotesContract.Search.Route, ([AsParameters] NoteSearch input) => …);That one reports twice: the handler binds a query parameter Text the contract never declares, and never binds the q it does. [FromQuery(Name = "q")] string? text fixes it. Three things are reported:
- An input the contract doesn't declare. No client generated from the spec sends it, so it's always missing, and a required one fails every request.
- An input the contract declares that the handler never binds. Clients send it and the handler ignores it. A route value counts too:
{id}in the contract wants anidin the handler. - The right name from the wrong place, such as
[FromHeader] string searchfor a query parametersearch.
The body counts as one input. An MVC action without [ApiController] binds an unattributed complex parameter from the route, query and form, never the body, so a contract body there needs [FromBody]; under [ApiController] the same parameter is the body, so a GET whose query record lacks [FromQuery] reads an empty body instead of the query. A .FormEncoded() body is different: its fields travel as named form values, so each one counts as an input of its own, under the name the spec gives it. The spec names a form field as both hosts' binders read the contract's own record (see Part names), so a handler binding that record is clean. A handler binding some other record, whose Body property the binder reads as Body where the spec says note_body, reports both halves, just like the query example above.
Names compare ignoring case, as ASP.NET's do, and the check follows the same binding rules as RIV4005: explicit [From*] attributes and their Name =, [AsParameters], and each host's inference. On MVC, a Name = on a complex parameter is the prefix its members are read under, so [FromQuery(Name = "f")] NoteSearch filter wants ?f.Search=, which no client sends. Minimal APIs read a StringValues like a string[], from the query on a GET, and never consult a [TypeConverter], so a type that only has one is a service or a body there. And because every MVC answer depends on whether [ApiController] infers binding sources, a SuppressInferBindingSourcesForParameters set to anything but a constant stops the check with RIV1115 instead of letting it guess. Members MVC reads under a prefix keep it when renamed (?f.q=), and header members never take one. [Bind(Prefix = "f")], on the parameter, its class, or a base class, sets the same prefix, and a member's [BindProperty(Name = ...)] renames it like a [FromQuery(Name = ...)] would.
MVC binds only what its filters let through, and so does the check. A [Bind("Title", "Body")] include list on the parameter and one on its class both apply, a nested member's class's own list applies wherever it's bound, and [BindNever] or [BindingBehavior(BindingBehavior.Never)] skips a member, whether it sits on the member or on its class (a member's own behaviour wins over its class's). The minimal-API form mapper reads none of them. Any other property filter (an IPropertyFilterProvider) stops the check with RIV1115, since MVC runs its code to choose the members. [ApiController] inference reads none of these filters either: an unattributed complex parameter is a body unless a property MVC lists for it carries its own binding source, and a positional record's constructor parameters don't count.
A minimal API's [FromForm] record plays by different rules, because it goes through the form mapper rather than model binding. The mapper reads every member from the form under its C# name, nested ones as Inner.Value, and the only rename it honours is [DataMember(Name = ...)]. It never prefixes, so a Name = on the parameter changes nothing, and it ignores the binding attributes on the members: a member's [FromForm(Name = "note_body")] still reads Body, and a [FromQuery] member is still a form field. --check reads the record the way the mapper does, so the [FromForm(Name = ...)] that fixes an MVC action is reported on a minimal API, and the fix there is the [DataMember].
A handler that can read the request itself is trusted to pick inputs out by hand: an HttpContext or HttpRequest parameter, a BindAsync type, a custom model binder, or a handler body that reads the request or route data through a property (a controller's Request or RouteData, ControllerContext.HttpContext.Request, an IHttpContextAccessor's HttpContext.Request), calls HttpContext.GetRouteValue, or hands the HttpContext or HttpRequest to a method only a package knows. Touching only HttpContext.User, Response, or RequestAborted doesn't count. A method or property the handler calls is read too when its source is in your project, as deep as the calls go, and it counts only when its own body reads the request. So a controller's private RouteId() that reads Request.RouteValues counts, and so do an extension it hands this (this.RouteId()), a static helper it hands an IHttpContextAccessor, and your own HttpContext.GetTenantId() that reads a request header. An Audit(HttpContext) that only looks at context.User doesn't, however much of the context it's handed. A method only a package knows can't be read, so it's judged by what it's handed. Such a handler is never told an input is unbound, though what it does bind is still checked. That's also the only way to read a cookie the contract declares: ASP.NET has no attribute that binds one, so --check reports a declared cookie unless the handler can read Request.Cookies. An unattributed complex parameter that could be a service counts as the body when the contract has one and as a service when it doesn't. The Authorization header, a .QueryAuth() token and the header or query parameter of an apiKey scheme the endpoint's security names (its own .Secure(...), or the document's global security, from attributes or --security) belong to the contract's security, not its inputs; --check takes the same --security values as generation.
An Azure Functions trigger hands the function the whole request, so a function is never told an input is unbound. Its other parameters are compared, though, because the worker fills each one by its name, ignoring case: from a route value first, then a query parameter, then a top-level property of a JSON body. It never looks at headers, cookies, or form fields, and a name nothing carries is null, or, for a value type, a failed call. So a misspelt route token is caught:
// The trigger's route is images/{format}/thumbnails/{size}. The worker looks sz up in the
// query, where no client sends it, so every call fails before the function runs.
public IActionResult Run([HttpTrigger(…, Route = ImagesContract.ThumbnailTriggerRoute)] HttpRequest _,
string format, ThumbnailSize sz, ThumbnailFit fit) => …That's RIV4006: the handler binds a query parameter sz the contract doesn't declare. A parameter named after a declared cookie, header, or form field is reported as the query parameter it really is, and the fix is to read the value from the request. A parameter named after one of a JSON body's top-level properties is fine, since that's the worker's third place to look. Azure Functions has the full binding rules, pinned against the real host.
Security the handler enforces
A contract's .Secure(...) is a promise about the wire: it tells every generated client to send credentials. Nothing in OpenAPI enforces it, though. That's the handler's job, and a spec that says "credentials needed" over a handler anyone can call is the most dangerous way for a spec to be looser than the truth. So --check compares the two.
It asks one question only: does a caller have to authenticate at all? Schemes and policies can't be matched ([Authorize(Policy = "Staff")] says nothing about bearer tokens), so --check doesn't try. Two disagreements are RIV4008:
- The spec has no anonymous alternative, but the handler is reachable anonymously.
- The spec admits anonymous callers (
.Anonymous(),.OrAnonymous(), or no security at all), but the handler requires authentication, so those callers get a 401.
The spec's security is the endpoint's own, else the document's default. Every operation that declares its security with attributes is compared too: a [RivetEndpoint] method or a [RivetClient] controller's action against its own [RivetSecure], [RivetOrAnonymous], and [RivetAnonymous], and a controller's override of an abstract [RivetContract] method against the contract method's. A static [RivetEndpoint] method is a minimal-API handler, so it's compared at each Map* call that names it as a method group. A handler that implements contract fields is compared under every field it serves, and not again for its own attributes: the merge already holds the two to one security (RIV2012). That catches [AllowAnonymous] sitting beside a [RivetSecure] that has no anonymous alternative.
No security declared means anyone may call
When neither the endpoint nor the document says anything about security, the emitted OpenAPI has no security at all, which OpenAPI reads as "no credentials needed". --check reads it the same way, so a handler that requires authentication under such a contract is a disagreement.
If the document declares no security scheme at all, those handlers have one cause, and you get one RIV4008 naming every endpoint instead of a page of them. The fix is to declare the document's default in source:
[assembly: RivetSecurityScheme("bearer", "http", scheme: "bearer")]
[assembly: RivetGlobalSecurity(0)]
[assembly: RivetGlobalSecurityScheme(0, "bearer", new string[0])]Then mark the endpoints anyone may call .Anonymous(). Declare it in source rather than only with --security: generation and --check are separate runs, and a check run without the generation flags would compare against a different spec from the one you ship. See Attributes for the assembly attributes.
What counts as authorization
--check reads ASP.NET's own authorization metadata, and nothing else:
IAuthorizeDataandIAllowAnonymousattributes ([Authorize],[AllowAnonymous], and your own attributes implementing them) on the action, its controller, and base controllers, or on a minimal-API handler (the lambda or the method a method group names);- an
AuthorizeFilteradded toMvcOptions.Filters, as an MVC-wide requirement that[AllowAnonymous]opts out of; RequireAuthorization()andAllowAnonymous()on the endpoint, on anyMapGroupit's mapped in, and onMapControllers();- the fallback policy, set by
AddAuthorization(o => o.FallbackPolicy = ...), orAddAuthorizationBuilder()'sSetFallbackPolicy(...)orAddFallbackPolicy(name, ...), which applies only to an endpoint with no authorization of its own; - the default policy, which is what
[Authorize],RequireAuthorization(), andnew AuthorizeFilter()mean when they name no policy or role of their own, and whato.FallbackPolicy = o.DefaultPolicycopies. ASP.NET's own requires an authenticated user; one you set (o.DefaultPolicy = ...,SetDefaultPolicy(...), orAddDefaultPolicy(name, ...)) is read like any other policy; - a named policy's registration, which is what a policy name means (
[Authorize(Policy = "Staff")],RequireAuthorization("Staff"), ornew AuthorizeFilter("Staff")); - for Azure Functions, the trigger's
AuthorizationLevel.Anonymouslets anyone in; any other level needs a key, and leaving the level out means the attribute's default,Function.
It weighs them the way ASP.NET does. An [AllowAnonymous] anywhere wins, over the controller's [Authorize], the global filter, RequireAuthorization(), and the fallback alike. So the usual MVC shape reads exactly as it runs:
builder.Services.AddControllers(options => options.Filters.Add(new AuthorizeFilter()));Every action requires an authenticated user, apart from the ones (or the controllers) marked [AllowAnonymous].
A policy counts as requiring authentication when it's built inline with one of AuthorizationPolicyBuilder's user requirements (RequireAuthenticatedUser, RequireRole, RequireClaim, RequireUserName), held in a local or not, as in new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()) or .RequireAuthorization(policy => policy.RequireRole("Staff")), and when an [Authorize]-style IAuthorizeData names roles. A blank Roles = "" counts too: ASP.NET still builds a role requirement from it, one nobody passes. A blank policy name is no name, so it means the default policy. A caller passes a policy only when every requirement in it passes, and each of those four turns an anonymous caller away, so one of them decides the policy whatever else it holds: an assertion, a custom requirement, or anything else --check can't read. In a configure lambda it counts only where it always runs, so policy => { if (strict) policy.RequireRole("Staff"); } is unknown. A policy whose only requirement is RequireAssertion(_ => true) lets anyone in: it's how an app says "open" under a fallback policy that requires a user. ASP.NET combines every policy on an endpoint into one that needs all their requirements, so a single policy that requires a user decides it.
A policy name means the policy registered under it, with AddAuthorization(o => o.AddPolicy("Staff", p => p.RequireRole("Staff"))) or AddAuthorizationBuilder()'s AddPolicy, AddDefaultPolicy, or AddFallbackPolicy, and looked up ignoring case, as ASP.NET does. So [Authorize(Policy = "open")] over a policy registered with RequireAssertion(_ => true) lets anyone in, and the fallback policy stays out of it, since the endpoint has authorization of its own. Under a secured contract that's RIV4008, and it names the policy that lets everyone through rather than asking for the [Authorize] the endpoint already has. A name without a registration --check can read is RIV4009: a name nothing registers, one registered only under a condition, one whose policy it can't read (AddPolicy("Staff", policyFromConfig)), and every name once the app registers a policy under a name it can't read (o.AddPolicy(config["Name"], ...)) or registers its own IAuthorizationPolicyProvider, since either may serve any name. A policy provider registered where --check can't see it, such as inside a library's extension method, is invisible, so names are read from their AddPolicy registrations as though it weren't there. An IAuthorizeData attribute of your own that takes constructor arguments may set its policy or roles in that constructor, where --check doesn't look, so it's unknown too.
Any other policy (one whose requirements, without a user requirement among them, include a RequireAssertion whose lambda isn't the constant true or a custom requirement, or a policy from a parameter, a field, or a method call) makes the verdict unknown rather than guessed.
--check follows a builder for authorization exactly as it does for a route: through a local, through convention calls that hand the builder back (.WithName(...), .RequireAuthorization()), into a helper that returns one, and out of a helper you pass it to, at each call site. A requirement on what a helper returns covers only that call's group: after var v2 = api.V2(); v2.RequireAuthorization();, what's mapped on v2 requires a user and what's mapped on api doesn't, and a group made inside a helper is a new group at every call. A requirement in the helper's own body reaches each of them. A convention on a builder it can't trace to its Map* call (a lambda's parameter, a field, a method handed on as a delegate, a delegate's answer, what an interface, abstract, or virtual method returns when an override or another implementation may run, or what a library call returns when it's handed a builder, as in Lib.Wrap(api).RequireAuthorization()) may cover any endpoint on that host, so those endpoints become RIV4009, and so does an endpoint mapped on a builder it can't follow to its MapGroup call or the app, or on a group a helper nests by calling itself, whose depth --check can't know. A framework call that maps endpoints of its own, such as MapHealthChecks or MapHub, is handed the app or a group but returns only a builder for what it mapped, never a route builder, so a requirement on it covers none of your contract's. --check tells the two apart by that return type: a call handed a builder that returns a route builder (the app or a group) may be handing back the one it was given.
App-wide setup in a helper (an AuthorizeFilter, or a fallback or default policy) applies where the helper is called: under that call's condition, unconditionally if any call is, and not at all if nothing calls it. A helper handed to a call as a method group, as in services.AddControllers(ConfigureMvc), runs where that call does; one stored in a delegate can't be followed, so it's unknown. A call through an interface the helper implements, or a method it overrides, runs whichever implementation the receiver turns out to be, so it counts only when --check can see that: IAppModule module = new AuthModule(); runs AuthModule.AddServices where module.AddServices(services) is called, and flag ? new AuthModule() : new OpenModule(), or a module that arrives as a parameter, is unknown.
Past your own calls, --check holds the host to the rules ASP.NET actually follows, and nothing friendlier. Top-level statements and the entry point run. Setup in a constructor, a property, or a field initializer runs wherever that type gets made, which --check doesn't follow, so it's unknown. A Startup class runs where UseStartup<Startup>(), UseStartup(typeof(Startup)), or UseStartup(context => new Startup(...)) hands it over, and only the methods StartupLoader looks for: ConfigureServices, Configure, and ConfigureContainer, or an environment's own ConfigureDevelopmentServices and friends. Those are found by reflection, so a base class's ConfigureServices counts when Startup inherits it, and not when Startup overrides or hides it. An environment's own method runs only in that environment, and the plain one only outside it, so either is unknown. A UseStartup whose type --check can't read (a Type from elsewhere, or the overload that takes an assembly name and finds the class by name at run time) may run any public Configure… method, so each of those is unknown.
A class the framework calls through its own interface, such as an IConfigureOptions<MvcOptions> or IPostConfigureOptions<MvcOptions> that adds the filter, runs where you register it with the framework under that interface: services.ConfigureOptions<RequireSignIn>() (or with typeof(RequireSignIn) or a new RequireSignIn()), or a service registration whose service type is the interface, such as AddSingleton<IPostConfigureOptions<MvcOptions>, RequireSignIn>() or TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<MvcOptions>, RequireSignIn>()). Nothing else counts. AddSingleton<RequireSignIn>() registers the class as itself, so the options system never asks for it, and a nameof(RequireSignIn) or a field of that type registers nothing at all. With no registration it can read, the class is unknown, since assembly scanning may still find it. One more wrinkle comes from the options system itself: on a class that implements IConfigureNamedOptions<MvcOptions>, only the named Configure(name, options) ever runs, so a filter added in the plain Configure(options) doesn't count. A public ConfigureAuthorization(this IServiceCollection services) that nothing calls runs nowhere: the Configure prefix means something to ASP.NET only on a Startup class.
What it can't see
Custom authorization filters and middleware are invisible. An IAsyncAuthorizationFilter that checks antiforgery tokens, or one that answers 403 to non-admins, doesn't change anything --check reports, and it never makes an endpoint unreadable either: --check can't tell what your code decides, so it doesn't pretend to. The same goes for IControllerModelConventions that add filters, and for authorization done by hand inside a handler.
When it can't decide
Some setup can't be read statically. A requirement applied only under a condition is the common one:
var controllerEndpoints = app.MapControllers();
if (entraEnabled)
{
controllerEndpoints.RequireAuthorization();
}Whether those actions need authentication depends on configuration --check never sees, so each one is RIV4009, naming the site and the condition. An if, an else, a ?: branch, a switch, a loop, a catch, the right of &&, ||, or ??, a ?., and a return that may leave before the call all count. A condition around both the endpoint and its requirement doesn't: the requirement holds whenever the endpoint exists. Nor does a return above a local function's declaration, the usual spot for one, since the function runs where it's called, not where it's written. That cuts both ways: a local function that applies a requirement to a group it captures counts under the condition of each place it's called, and applies nothing if nothing calls it.
It's never a guess, though, and it isn't blanket: --check works the verdict out for every way the unknowns could fall, and reports only when they disagree. An [AllowAnonymous] action under that conditional RequireAuthorization() is anonymous either way, and an [Authorize] one requires authentication either way, so neither is RIV4009. Neither is a conditional requirement on an endpoint that the fallback policy would secure anyway, nor a bare [Authorize] under a default policy set only when entraEnabled, if that policy requires an authenticated user just as ASP.NET's own default does.
Sites under one condition fall together. A group's RequireAuthorization() under if (entraEnabled) beside an endpoint's AllowAnonymous() under another if (entraEnabled) leaves the endpoint anonymous either way, and the two branches of one if that each require a user require one either way, so neither is RIV4009. Two conditions are one when they're the same if or ?:, whose two branches are each other's opposite, or when each reads the same const, static readonly field, or local with one known value, with or without a !. A fallback policy set under such a condition joins in when it's the only place the fallback is set and it requires a user, so if (entraEnabled) o.FallbackPolicy = … beside if (!entraEnabled) endpoint.RequireAuthorization() requires a user either way.
Anything else stays its own unknown: a site under two conditions, a switch, a loop, or && or ||. Two conditions that call a method or read a parameter are two unknowns, even when they read the same thing: only one if's own two branches share theirs. A condition inside a method that may run more than once, or under its callers' conditions as well as its own, is its own unknown too: a condition counts when the requirement and the group or endpoint it's applied to are made in the same method, which runs them together, or when it's in top-level statements or the entry point, which run exactly once. A const or static readonly field holds one value everywhere, so a requirement under one counts in any method. App-wide setup has no group of its own, so a filter or policy set under a condition falls together with the rest only in top-level statements or the entry point, configure lambdas included, and never in a ConfigureServices or an extension method. If you want --check to see a switch once, read it where the app starts.
The cure is to apply authorization unconditionally. If a development environment really does run without authentication, give it a development authentication handler that signs the dev user in, rather than switching authorization off. Then authorization is exercised everywhere the app runs, and --check can read it.
Helpers are fine
The spec comes from the contract, never from handler code. Every response is declared with .Returns(...) on the field, so moving an .Error(...) or a 404 guard into a helper changes nothing in the OpenAPI output. A helper can take the bound endpoint (BoundRouteDefinitionBase, or the bound definition type) and return a RivetResult. Rivet still checks the status against that endpoint's contract at runtime.
--check reads handler bodies for one thing only: each handler must return at least one terminal on its own contract field, usually the .Success(...). That's how it knows the endpoint is implemented on the right verb and route. The rest can live wherever you like:
app.MapGet(TasksContract.GetTask.Route, async (Guid id, TaskStore tasks) =>
{
var endpoint = TasksContract.GetTask.Bind(new TaskLookup(id));
return await tasks.Find(id) is { } task
? endpoint.Success(task).ToResult()
: NotFound(endpoint).ToResult();
});
app.MapGet(TasksContract.ListComments.Route, async (Guid id, TaskStore tasks) =>
{
var endpoint = TasksContract.ListComments.Bind(new TaskLookup(id));
return await tasks.Comments(id) is { } comments
? endpoint.Success(comments).ToResult()
: NotFound(endpoint).ToResult();
});
static RivetResult NotFound(BoundRouteDefinitionBase endpoint) =>
endpoint.Error(StatusCodes.Status404NotFound, new ErrorDto("Task not found"));Both fields declare .Returns<ErrorDto>(404). The helper doesn't care which endpoint it's answering for, because the bound endpoint carries its own contract.
Handing the bound endpoint to a helper also counts as using it, so the binding isn't orphaned. That holds when the helper call is part of what the handler returns, at any depth: NotFound(endpoint).ToResult(), your own extension in a Match arm such as refused: r => endpoint.Refuse(r), or one wrapped in another helper, as in Done(endpoint.Refuse(r)). An arm that binds its own input and hands it straight over counts too, as in missing: reason => TasksContract.CreateTask.Bind(new(reason)).Refuse(422). --check looks through the same things it does for terminals (see below): an await, a cast, a switch or ?:, and a local holding the helper's answer. A helper call whose answer is thrown away, or one inside a lambda that the returned call doesn't take directly, still leaves the binding orphaned.
Using the binding and covering the field are different things, though. --check gives a field credit only for a terminal that reaches .ToResult() or .ToActionResult() on the handler's way out. The handler can apply the adapter itself, or hand the terminal to a helper that does (see below). A terminal a helper builds for itself, like the NotFound(endpoint) above, belongs to the helper: it serves any endpoint it's handed, so it can't speak for one. A handler whose every answer is built inside helpers isn't tied to any field, and if nothing else implements that field, --check reports it as MissingImplementation, binding or no binding.
How a handler can return its terminal
"Return a terminal" covers the ways handlers actually get written. --check follows the value from the handler's return to the .ToResult() or .ToActionResult() call, and from there back to the terminal. All of these count:
// An adapter on each arm of a switch or ?:
return found ? endpoint.Success(task).ToResult() : endpoint.Error(404).ToResult();
// One adapter around the whole switch or ?:
return (result switch
{
Found found => endpoint.Success(found.Task),
NotFound => endpoint.Error(404),
}).ToResult();
// A local holding the terminal (or a switch of them), adapted on the way out
var response = result switch { /* ... */ };
return response.ToResult();
// Lambda arms, such as a result type's Match, sync or async
return outcome.Match(
found: task => endpoint.Success(task).ToResult(),
missing: _ => endpoint.Error(404).ToResult());A lambda counts when it's passed straight to the call the handler returns, such as Match or MatchAsync, awaited or not, including a Match that one of those arms returns. Naming the arm first changes nothing: a lambda in a local (var found = (TaskDto t) => ...;) or a local function passed as outcome.Match(found, ...) is still the handler's own code. A lambda buried in an argument doesn't count. In return Results.Ok(items.Select(t => endpoint.Success(t).ToResult())); the response is the Ok, not the terminal inside Select. Nor does a Match whose answer is thrown away. In a minimal API the handler is whatever you hand MapGet and friends, not the Match arm inside it, so that's whose route and parameters get checked. It doesn't have to be written in place:
app.MapGet(TasksContract.GetTask.Route, TaskHandlers.Get); // a method group
public static class TaskHandlers
{
public static async Task<IResult> Get(Guid id, TaskStore tasks)
{
var endpoint = TasksContract.GetTask.Bind(new TaskLookup(id));
return await tasks.Find(id) is { } task
? endpoint.Success(task).ToResult()
: NotFound(endpoint).ToResult();
}
}The method's parameters are what ASP.NET binds, so they're what RIV4006 compares, exactly as a lambda's would be. The same goes for a local function, or a local holding a lambda, handed over by name. Map one method twice and each mapping is checked on its own verb and route, so the one the contract doesn't declare is a RouteMismatch. A method group naming something with no source in the project (new object().ToString, say) has no body to read, so it implements nothing.
A helper can do the adapting, too. Handing the terminal to a helper counts when the helper returns the adapter applied to the parameter the terminal lands in:
return Done(endpoint.Success(task));
static IResult Done(RivetResult result) => result.ToResult();--check follows any helper whose source is in the project, local functions and extension methods included, through as many helpers as hand the terminal on, and reads each one once, so a recursive helper can't send it round in circles. A helper that throws the terminal away, or adapts a different argument, gives nothing: the field still needs a terminal from somewhere else. Either way, the helper uses the binding, so it isn't an OrphanedBinding.
Exit code
When --check is used, any finding makes the command exit with code 1 — suitable for CI, both with and without --output: coverage runs before emission, so a failed check prints the findings and writes nothing even when an output directory is requested. Combine with -q/--quiet to suppress generation output in CI logs.
