Skip to content
Open
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
14 changes: 14 additions & 0 deletions generators/python/core_utilities/shared/pydantic_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ def json(self, **kwargs: Any) -> str:
return super().model_dump_json(**kwargs_with_defaults) # type: ignore[misc]
return super().json(**kwargs_with_defaults)

def model_dump_json(self, **kwargs: Any) -> str:
"""
Override model_dump_json to use our custom dict() method which properly
handles FieldMetadata aliases, then serialize to JSON.
"""
import json

data = self.dict(**kwargs)
if IS_PYDANTIC_V2:
from pydantic_core import to_jsonable_python

return json.dumps(to_jsonable_python(data, fallback=encode_by_type))
return json.dumps(data, default=encode_by_type)

def dict(self, **kwargs: Any) -> Dict[str, Any]:
"""
Override the default dict method to `exclude_unset` by default. This function patches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def json(self, **kwargs: Any) -> str:
}
return super().json(**kwargs_with_defaults)

def model_dump_json(self, **kwargs: Any) -> str:
"""
Override model_dump_json to use our custom dict() method which properly
handles FieldMetadata aliases, then serialize to JSON.
"""
import json

data = self.dict(**kwargs)
return json.dumps(data, default=encode_by_type)

def dict(self, **kwargs: Any) -> Dict[str, Any]:
"""
Override the default dict method to `exclude_unset` by default. This function patches
Expand Down
10 changes: 10 additions & 0 deletions generators/python/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# yaml-language-server: $schema=../../../fern-versions-yml.schema.json
# For unreleased changes, use unreleased.yml
- version: 4.43.0
changelogEntry:
- summary: |
Add `model_dump_json()` override to `UniversalBaseModel` that properly handles `FieldMetadata` aliases.
When using the default `FieldMetadata` aliasing (not native Pydantic aliases), calling `model_dump_json()`
now correctly serializes field names to their camelCase aliases, matching the behavior of `dict()`.
type: feat
createdAt: "2025-12-05"
irVersion: 61

- version: 4.42.0
changelogEntry:
- summary: |
Expand Down
Loading