Skip to content

Commit f5aa181

Browse files
feat(python): add environment_class_name config option (#10712)
* feat: add environment_class_name config option to Python and Java generators Co-Authored-By: adi@buildwithfern.com <aditya.arolkar@berkeley.edu> * feat(python): revert Java changes and keep default as {ClientName}Environment Co-Authored-By: adi@buildwithfern.com <aditya.arolkar@berkeley.edu> * Reset generators/java to match main branch --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: adi@buildwithfern.com <aditya.arolkar@berkeley.edu>
1 parent 132549a commit f5aa181

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

generators/python/sdk/versions.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# yaml-language-server: $schema=../../../fern-versions-yml.schema.json
22
# For unreleased changes, use unreleased.yml
3+
- version: 4.39.0
4+
changelogEntry:
5+
- summary: Add environment_class_name config option to customize the environment class name. Default remains {ClientName}Environment.
6+
type: feat
7+
createdAt: "2025-11-25"
8+
irVersion: 61
9+
310
- version: 4.38.5
411
changelogEntry:
512
- summary: Fix discriminated union Field(discriminator=...) and UnionMetadata(discriminant=...) to use Python field names instead of JSON aliases for Pydantic v2 compatibility.

generators/python/src/fern_python/generators/sdk/context/sdk_generator_context_impl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def __init__(
7575
self._error_declaration_referencer = ErrorDeclarationReferencer(
7676
skip_resources_module=custom_config.improved_imports
7777
)
78+
default_env_class_name = f"{exported_client_class_name}Environment"
79+
final_env_class_name = custom_config.environment_class_name or default_env_class_name
7880
self._environments_enum_declaration_referencer = EnvironmentsEnumDeclarationReferencer(
79-
client_class_name=exported_client_class_name,
81+
environment_class_name=final_env_class_name,
8082
skip_resources_module=custom_config.improved_imports,
8183
)
8284
self._subpackage_client_declaration_referencer = SubpackageClientDeclarationReferencer(

generators/python/src/fern_python/generators/sdk/custom_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class SDKCustomConfig(pydantic.BaseModel):
6464

6565
follow_redirects_by_default: Optional[bool] = True
6666

67+
environment_class_name: Optional[str] = None
68+
6769
# Feature flag that removes the usage of request objects, and instead
6870
# parameters in function signatures where possible.
6971
inline_request_params: bool = True

generators/python/src/fern_python/generators/sdk/declaration_referencers/environments_enum_declaration_referencer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44

55
class EnvironmentsEnumDeclarationReferencer(SdkDeclarationReferencer[None]):
6-
def __init__(self, client_class_name: str, skip_resources_module: bool):
6+
def __init__(self, environment_class_name: str, skip_resources_module: bool):
77
super().__init__(skip_resources_module=skip_resources_module)
8-
self._client_class_name = client_class_name
8+
self._environment_class_name = environment_class_name
99

1010
def get_filepath(self, *, name: None, as_request: bool = False) -> Filepath:
1111
return Filepath(
@@ -14,4 +14,4 @@ def get_filepath(self, *, name: None, as_request: bool = False) -> Filepath:
1414
)
1515

1616
def get_class_name(self, *, name: None, as_request: bool = False) -> str:
17-
return self._client_class_name + "Environment"
17+
return self._environment_class_name

0 commit comments

Comments
 (0)