Skip to content

CLI Reference ​

Forward Generation (OpenAPI) ​

OpenAPI 3.1 is the tool's output. --output <dir> writes <dir>/openapi.json; omit it to preview the spec on stdout.

bash
dotnet rivet --project path/to/Api.csproj --output ./generated
dotnet rivet Contracts.cs Types.cs --output ./generated
dotnet rivet ./src/generated --output ./generated   # a directory = every .cs under it

Explicit spec path ​

--openapi <path> overrides where the spec is written (relative paths resolve against --output). When given, it is the sole writer.

bash
dotnet rivet --project path/to/Api.csproj --output ./generated --openapi ../spec/openapi.json

Spec metadata and security ​

--title, --version, and --server set the spec's info.title, info.version, and servers entries; --security sets the default security scheme. All four are CLI data — they describe the deployment, not the contracts, and are not recovered by --from-openapi import. --check reads --security too: to know which apiKey headers and query parameters belong to security, and to hold every handler's authorization against the security the spec would carry.

bash
dotnet rivet --project path/to/Api.csproj --output ./generated \
  --title "Orders API" --version 2.3.0 \
  --server https://api.example.com --server https://staging.example.com \
  --security bearer
  • --title <text> — info.title (default API).
  • --version <text> — info.version (default 1.0.0). It always means the spec version; --tool-version prints Rivet's own.
  • --server <url> — adds a servers entry; repeat for multiple. Accepts absolute http(s) URLs or paths starting with /. With no --server, no servers block is emitted at all.
  • --security <[name=]spec> — accepted forms: bearer, bearer:jwt, cookie:<name>, and apikey:<in>:<name>, where <in> is query, header, or cookie. Scheme kinds and API-key locations are case-insensitive and are emitted in canonical lowercase. Prefix a form with an explicit component name when contracts use .Secure("..."), for example --security admin=bearer or --security internal=apikey:header:X-API-Key. Explicit component names retain their casing. Repeat --security to define multiple schemes; the first is the document-wide default and the remaining schemes are available to endpoint-level .Secure() and .AndSecure() calls, which carry their own scopes and alternatives. The flag only defines schemes and that one default; a document-level requirement with alternatives or scopes comes from the [assembly: RivetGlobalSecurity(...)] and [assembly: RivetGlobalSecurityScheme(...)] attributes an import writes, and an explicit --security replaces those wholesale. With --from, a contract's top-level security is the default instead, and --security only defines the schemes.

With --from-openapi, --security retains its importer override behavior and accepts one existing OpenAPI component name, such as --security admin. Emit-time definitions (admin=bearer) and repeated values are rejected in import mode.

From Contract JSON ​

--from consumes a Rivet contract JSON document (produced by the sibling runtime, rivet-ts) and emits the same OpenAPI spec. The contract JSON is an internal intermediate representation, not a public format — OpenAPI is the only public output:

bash
dotnet rivet --from contract.json --output ./generated

The reader is strict: a property it doesn't know, or a required member left out or written as null, stops the run with the JSON path of the offending spot instead of quietly dropping out of the spec, and rivet-contract-schema.json in the repo root is the authority on what belongs where.

A contract can say what the whole document requires with a top-level security, the shape an endpoint's security takes. It becomes the spec's root security and wins over the default your first --security would supply; --security still defines the schemes, since contract JSON has no scheme definitions of its own. { "alternatives": [] } is security: []. Route tokens are written bare ({id}): the template is the path key as given, so a constraint, ?, default, or catch-all is refused with RIV2017, and the param's type says what the token holds.

An inline-object property without an optional flag is required, whether or not its value type is nullable.

Checks And Listing ​

bash
dotnet rivet --project path/to/Api.csproj --check
dotnet rivet --project path/to/Api.csproj --routes

--check verifies contract coverage: missing implementations, route and method mismatches, inputs the handler binds somewhere other than where the contract declares them (RIV4006), enum parameters the host can't bind (RIV4005), and handlers whose authorization disagrees with the spec's security (RIV4008, or RIV4009 when the setup can't be read statically) — see Contract Coverage. It reads security exactly as generation does, so declare the scheme and the document's default in source ([assembly: RivetSecurityScheme(...)], RivetGlobalSecurity, RivetGlobalSecurityScheme); if you do pass --security, pass the same flags you generate with. Any finding, warning or error, exits with code 1, with or without --output. --routes lists every discovered endpoint (method, route, handler) and exits. -q/--quiet suppresses generation output (useful with --check in CI). -h/--help prints usage to stdout and exits 0, whatever else is on the command line. --tool-version prints Rivet's own release (0.50.0, no build metadata) to stdout and exits 0; only --help beats it. rivet-ts runs it to check a binary it didn't download itself.

Drift gate (--verify) ​

If you commit the generated spec (and artifacts derived from it, like schema.d.ts), nothing otherwise stops the C# and the committed spec drifting apart when someone forgets to regenerate. --verify is the CI gate: it derives the spec exactly as a normal run would, compares it against the existing file (--output <dir>/openapi.json, or the --openapi override), and exits 1 on any difference — without writing anything. Emission is deterministic, so a checkout where someone regenerated and committed always passes.

bash
# CI step — fails the build when the committed openapi.json is stale
dotnet rivet --project src/Api/Api.csproj --output ./generated --verify

Pass the same --title/--version/--server/--security flags you generate with, or the comparison will (correctly) flag the metadata difference.

Diagnostics ​

Every warning the tool writes to stderr, and every error it stops on except a command-line usage error, carries a stable RIV-prefixed ID in the canonical format warning RIV1003: <message> or error RIV2002: <message> — grep or baseline by ID, never by message text. A usage error (an unknown flag, a missing value, a combination that can't run) is about the command line rather than your code, so it stays a plain error: … beside the usage text. An invalid --security value isn't one of those: it's error RIV2018: invalid --security value …. See the Diagnostics Reference for the full table of IDs, triggers, and remediations.

Import (onboarding scaffold) ​

One-shot scaffold for adopting Rivet on an existing API — the generated C# becomes the source of truth afterwards. See the Import Profile for what imports cleanly, every diagnostic category, and what is out of scope.

bash
dotnet rivet --from-openapi spec.json --namespace MyApp.Contracts --output ./src/

Omit --output to preview generated output to stdout.

Removed in v2 ​

--compile and --jsonschema (TypeScript/Zod generation) were removed in v2: TS/Zod generation moved to the OpenAPI ecosystem. Generate types with openapi-typescript, a client with openapi-fetch, and Zod schemas with openapi-zod-client. Invoking either flag exits with an error explaining the replacement.