How It Works
Rivet is a Roslyn-based extractor, not a runtime reflector. The pipeline, as implemented in Rivet.Tool:
- Load —
--project x.csprojloads the project through MSBuild and gets the full RoslynCompilation; bare.csarguments are compiled directly. Compilation errors abort the run. - Discover — a single pass over the source assembly finds
[RivetContract]classes,[RivetClient]classes,[RivetEndpoint]methods, and[RivetType]types. - Walk —
TypeWalkerlowers C# types into an internal type model (primitives with formats, brands, monomorphised generics, enums, nullability);ContractWalkerreadsDefine.*builder chains from contract fields;EndpointWalkerreads controller/minimal-API endpoints (routes, parameter binding,[ProducesResponseType], typed results). Contract endpoints win when both describe the same endpoint. - Emit —
EmitPipelineextracts repeated inline object types into named components, thenOpenApiEmitterwrites the OpenAPI 3.1 document with thex-rivet-*vendor extensions.
Two side doors feed the same emit pipeline:
--from contract.json— a contract JSON document produced by the sibling runtimes (rivet-ts, rivet-php). This is an internal IR, not a public format.--from-openapi spec.json— the one-shot importer generates C# contracts/DTOs which then go through the normal Roslyn path.
There is no runtime spec generation and no middleware: the Rivet.Attributes package contains only the attributes, the Define/RouteDefinition builder, and contract-owned Bind/terminal APIs with first-party host adapters. Their enforcement scope is described in Runtime Validation.
