Skip to content

Map Field(json_schema_extra) to extend:name / extend:descriptions - #80

Merged
jordanalexmeyer merged 1 commit into
masterfrom
jam/pydantic-extend-name-descriptions
Aug 10, 2026
Merged

Map Field(json_schema_extra) to extend:name / extend:descriptions#80
jordanalexmeyer merged 1 commit into
masterfrom
jam/pydantic-extend-name-descriptions

Conversation

@jordanalexmeyer

Copy link
Copy Markdown
Contributor

Summary

Python parity for extend-hq/extend-typescript-sdk#90 (zod .meta() support). pydantic_to_extend_schema now reads Field(json_schema_extra={...}):

  • extend:name (string) is emitted on every node type that carries a description: primitives, enums, dates, arrays, nested objects, and ExtendCurrency / ExtendSignature / ExtendDate
  • extend:descriptions (list of strings, one per enum value) is emitted on enum outputs — both Literal[...] and string Enum fields
  • Unrelated json_schema_extra keys and wrong-typed values are silently ignored, matching the TypeScript behavior
  • Works under pydantic v1 and v2 (v1 stashes unknown Field() kwargs in FieldInfo.extra, which is handled)
class Schema(pydantic.BaseModel):
    status: Optional[Literal["active", "inactive"]] = pydantic.Field(
        None,
        json_schema_extra={
            "extend:name": "AccountStatus",
            "extend:descriptions": ["Account is active", "Account is inactive"],
        },
    )

Test plan

  • 11 new tests mirroring the TypeScript PR's coverage, plus wrong-type / ignored-key / non-enum cases
  • Full suite passes (270 passed, 1 skipped), ruff clean
  • Schema conversion tests also run under pydantic 1.10.18 — all new tests pass (one pre-existing recursion test failure there reproduces on unmodified master)

Parity with extend-typescript-sdk#90, which reads zod .meta() for these
keywords: extend:name lands on every node type that carries a
description, extend:descriptions on enum outputs. Unrelated keys and
wrong-typed values are ignored.
@jordanalexmeyer
jordanalexmeyer merged commit 7156204 into master Aug 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants