Target Options
A TypeScript Target in generation.py takes these options. Each one ends as Orval config or generated code, not
as a runtime switch an app sets by hand. A target that sets none keeps exactly the output it had. TypeScript-specific settings are refused on other languages when set away from their defaults.
| Option | Type, default | Effect |
|---|---|---|
typescript_profile | "web" | "cli", "web" | "cli": standalone Fetch operations and Zod models without frontend hooks, session runtime or mocks. Supply the API origin explicitly per call. |
auth_mode | "default" | "public", "default" | "public": the generated mutator sends every request with auth: 'none', after the caller’s options, so no call of this client can carry the session. For a client of public endpoints only. |
direct_origin_tags | list[str], [] | Raw OpenAPI tags whose operations get origin: 'direct': they go to the API host, never through a same-origin proxy or a static-build relative URL. A tag that no operation of the target carries stops generation. |
infinite | bool, False | Adds use<Op>Infinite, get<Op>InfiniteQueryOptions and get<Op>InfiniteQueryKey to every GET with a page (else cursor) query parameter. Other GETs and all other files are unchanged. |
In the default web profile, two more settings are on for a Target and are not fields of it:
- mock: MSW handlers and Faker factories in
endpoints/<tag>/<tag>.msw.ts. - prettier: the tree is formatted with the prettier config a file in the consumer folder gets (the
.prettierrcof your frontend), whatever folder the generator wrote into.
Both exist only as internal pipeline options (GenerationTarget.options). Target(mock=False) is not an error: an
unknown keyword is ignored, so it changes nothing.
from django_cfg.modules.django_generator import Language, Target, TargetType
catalog = Target(
lang=Language.TYPESCRIPT,
type=TargetType.WEB,
path=FRONTEND / "packages" / "catalog-api" / "src" / "generated",
groups=["catalog"],
direct_origin_tags=["listings", "api_keys"], # these skip the /apix proxy
infinite=True,
)auth_mode
This section describes the web profile. CLI clients have no session store: protected calls use explicitly supplied headers; public calls strip Authorization/Cookie. Whole-target auth_mode="public" enforces this regardless of caller options.
The default client sends the session’s Bearer token on every operation except those the spec marks public
(security: [{}]), which get auth: 'none' one by one. "public" forces it for the whole client. Use it for a
client that a signed-in user’s token must never reach, such as a proxy that injects its own API key.
direct_origin_tags
For an app whose browser requests normally go through a same-origin proxy (NEXT_PUBLIC_API_PROXY_URL), while some
groups must reach the API host directly. On the server every request goes to the API host anyway. How the origin is
resolved: API origin modes.
infinite
Orval does not write initialPageParam or getNextPageParam. Spread the runtime’s helper into query:
import { drfPageParams } from '@djangocfg/api';
const coins = useCryptoCoinsListInfinite({ page_size: 20 }, { query: { ...drfPageParams } });drfPageParams fits every Paginated* envelope (next_page, else page + 1 while has_next). drfCursorParams
fits a cursor list (next_cursor, or the cursor of a DRF next URL). Infinite keys start with 'infinite':
a mutation invalidates get<Op>InfiniteQueryKey(params) as well as get<Op>QueryKey(params).
typescript_profile="cli"
Use the CLI profile for a command-line tool or another consumer that needs generated operations without React Query, React, Next.js, MSW/Faker or the frontend @djangocfg/api runtime:
Target(
lang=Language.TYPESCRIPT,
type="cli",
path=ROOT / "contracts" / "generated" / "typescript",
groups=["your_api_group"],
typescript_profile="cli",
)The profile retains generated operation paths, DTOs, Zod schemas and contract stamps. Its standalone transport requires an explicit absolute HTTP(S) origin in each call’s baseUrl option. It reads no environment variables, tokens, browser identity or shared session. An absent/invalid origin fails before Fetch. Pass an AbortSignal to cancel the request and body read. The caller owns any overall deadline.
Success responses are JSON, or empty for 204/HEAD. HTTP, network, invalid-JSON, schema-validation and configuration failures use the generated ApiClientError; no refresh or retry occurs. Public operations default to anonymous request metadata; an explicitly public whole target strips Authorization/Cookie even if supplied. Keep the default auth mode for mixed protected/public groups and configure protected headers deliberately.
infinite and direct_origin_tags are refused for CLI targets. Realtime adapters and mocks are omitted. Generation still uses the pinned Orval/TypeScript workspace; runtime consumers need only a Fetch-capable environment and their generated Zod model dependency. Generate/package the shared contract once per revision and reuse it across tools. No Django service or frontend library is needed by the generated client at runtime.
rust_crate (Rust)
A Rust Target writes one Cargo crate. rust_crate is its package name; the default is the target folder’s name,
kebab-cased. Setting it on a non-Rust target is an error.
Target(
lang=Language.RUST,
type=TargetType.SDK,
path=ROOT.parent / "rust" / "djangocfg-api",
groups=["cfg_accounts", "cfg_totp"],
rust_crate="djangocfg-api",
)The base URL environment variable is derived from it: djangocfg-api reads DJANGOCFG_API_BASE_URL.
rust_workspace (Rust)
rust_workspace=True makes the crate a member of the Cargo workspace above path:
- package keys the root’s
[workspace.package]defines (version,edition,rust-version,publish,license, …) are inherited, the others keep progenitor’s values; - every dependency is
dep = { workspace = true, features = [...] }(features are additive, so the root’s own features stay); [lints] workspace = true; the generatedlib.rsopens with one#![allow(clippy::all, clippy::pedantic, …, reason = "…")], so a strict workspace (pedantic,unwrap_used,allow_attributes_without_reason,unreachable_pub) judges your code, not progenitor’s;workspace-dependencies.tomlin the crate lists the entries the root’s[workspace.dependencies]needs, with the versions progenitor chose.make gennames the ones the root does not declare yet;- no TLS feature is on (
default = []): the consumer enablesdefault-tls(rustls on aws-lc-rs),native-tlsorrustls-no-providerand installs a provider, e.g.rustls::crypto::ring::default_provider().install_default(), so a ring-only workspace never pullsaws-lc-sys.
The inner #![allow] covers every module of the crate and lowers a workspace deny; only forbid cannot be
lowered, and the generated code has no unsafe.
A path with no [workspace] manifest above it fails the target.
What is not an option
- The API origin. It is decided at run time; see Runtime. A generated base URL would enter every query key and differ between server and browser.
- Per-operation auth. It comes from the view’s OpenAPI
security, and sign-in steps fromextend_schema(extensions=SIGN_IN_STEP). - QueryClient defaults (retry, stale time). They belong to
BaseApp; see State management.