Skip to content

Add Pydantic support (PydanticClassDeclaration)#10623

Open
mauriciogardini wants to merge 3 commits intomicrosoft:mainfrom
pinterest:feature/pydantic-support
Open

Add Pydantic support (PydanticClassDeclaration)#10623
mauriciogardini wants to merge 3 commits intomicrosoft:mainfrom
pinterest:feature/pydantic-support

Conversation

@mauriciogardini
Copy link
Copy Markdown
Contributor

@mauriciogardini mauriciogardini commented May 7, 2026

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).

Temporary dependency note

This branch currently points @alloy-js/python to the Alloy PR build (pkg.pr.new) so CI can consume the new APIs before Alloy is merged.

Remark: this dependency pin is temporary and should be reverted to the standard catalog/published Alloy dependency once Alloy PR branch changes are merged and released.

@mauriciogardini mauriciogardini changed the title Feature/pydantic support Add Pydantic support (PydanticClassDeclaration) May 7, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter-framework Issues for the emitter framework label May 7, 2026
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.

1 participant