Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions scripts/typegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,22 @@ uv run datamodel-codegen \
--use-annotated \
--field-constraints \
--snake-case-field \
--enum-field-as-literal one \
--use-one-literal-as-default \
--input-file-type openapi \
--formatters ruff-format

# Why --enum-field-as-literal=one + --use-one-literal-as-default?
#
# Without these, single-value enums (used as discriminators on sealed unions
# like AuditMetadata.kind) generate as `kind: Kind` where `Kind(StrEnum)` has
# one entry. Pydantic 2.12+ rejects this when the parent is a discriminated
# union: "Model 'X' needs field 'kind' to be of type `Literal`".
#
# These flags make the codegen emit `kind: Literal["..."] = "..."` instead,
# satisfying the discriminator requirement and making the field optional at
# construction (callers don't need to repeat the discriminator value).

# Post-process: inject `model_config = ConfigDict(extra='forbid')` into every
# generated class so that requests with unknown fields and responses with
# unknown fields BOTH fail loudly. Implements P1 + P2 from
Expand Down
Loading
Loading