Skip to content

Add Pydantic support (PydanticClassDeclaration)#11243

Open
mauriciogardini wants to merge 11 commits into
microsoft:mainfrom
pinterest:feature/pydantic-support
Open

Add Pydantic support (PydanticClassDeclaration)#11243
mauriciogardini wants to merge 11 commits into
microsoft:mainfrom
pinterest:feature/pydantic-support

Conversation

@mauriciogardini

@mauriciogardini mauriciogardini commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

This branch adds Pydantic-oriented Python emitter support in @typespec/emitter-framework by aligning with the new APIs introduced in Alloy Python (PydanticClassDeclaration, richer pydantic/typing/pydantic_settings externals, and decorator ordering for class/static methods).

What changed

  • Added a new emitter-framework wrapper:
    • python/components/class-declaration/PydanticClassDeclaration
    • Converts TypeSpec models to Pydantic classes (BaseModel default base)
    • Supports:
      • modelConfig (structured ConfigDict(...) generation)
      • modelConfigExpression (verbatim model_config = ... expression)
  • Expanded Python builtins used by emitter-framework:
    • pydanticModule (including validators/serializers, ConfigDict, RootModel, subpaths)
    • typingModule (additional annotation symbols)
    • pydanticSettingsModule (BaseSettings, SettingsConfigDict)
  • Added decorator support for typed class methods in emitter-framework:
    • Method now accepts decorators?: Children[]
    • Decorators render before intrinsic method decorators (@classmethod / @staticmethod) to support Pydantic validator stacking order.
  • Updated Python test harness externals:
    • includes Pydantic and settings modules in externals.
  • Added focused tests for new behavior:
    • pydantic-class-declaration.test.tsx
    • Covers pydantic model emission, model_config, validator ordering, and settings base usage.

Validation

  • @typespec/emitter-framework build passes.
  • Focused Python tests related to this work pass (including new Pydantic tests and class method decorator ordering tests).

mauriciogardini and others added 7 commits July 13, 2026 20:51
…and docs

Adds first-class Pydantic support helpers to the Python emitter framework, including convenience class declarations for BaseModel, BaseSettings, and RootModel, plus typed decorator builders for common validator/serializer patterns. Also expands tests and adds package-level documentation with practical usage examples.

Co-authored-by: Cursor <cursoragent@cursor.com>
Regenerate pnpm-lock.yaml after rebasing the pydantic-support branch onto upstream main so dependency resolution is consistent in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove the temporary emitter-framework readme added during pydantic helper iteration to keep this PR focused on code and tests only.

Co-authored-by: Cursor <cursoragent@cursor.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter-framework Issues for the emitter framework label Jul 13, 2026
@mauriciogardini mauriciogardini marked this pull request as ready for review July 13, 2026 21:16
Comment thread packages/emitter-framework/package.json Outdated
@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/emitter-framework@11243

commit: fba5aa3

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/emitter-framework
Show changes

@typespec/emitter-framework - feature ✏️

Add Python Pydantic helpers to the emitter framework: PydanticClassDeclaration, PydanticSettingsClassDeclaration, and PydanticRootModelDeclaration components, along with field_validator, model_validator, field_serializer, and computed_field decorator helpers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter-framework Issues for the emitter framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants