Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-client-python"
---

Don't hardcode client in sample to first client in list
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _imports(self) -> FileImportSerializer:
def _client_params(self) -> Dict[str, Any]:
# client params
special_param = {}
credential_type = getattr(self.code_model.clients[0].credential, "type", None)
credential_type = getattr(self.operation_group.client.credential, "type", None)
if isinstance(credential_type, TokenCredentialType):
special_param.update({"credential": "DefaultAzureCredential()"})
elif isinstance(credential_type, KeyCredentialType):
Expand All @@ -78,7 +78,7 @@ def _client_params(self) -> Dict[str, Any]:
params = [
p
for p in (
self.code_model.clients[0].parameters.positional + self.code_model.clients[0].parameters.keyword_only
self.operation_group.client.parameters.positional + self.operation_group.client.parameters.keyword_only
)
if not p.optional and p.client_default_value is None
]
Expand Down Expand Up @@ -153,6 +153,7 @@ def serialize(self) -> str:
operation_result, return_var = self._operation_result()
return self.env.get_template("sample.py.jinja2").render(
code_model=self.code_model,
client=self.operation_group.client,
file_name=self.file_name,
operation_result=operation_result,
operation_params=self._operation_params(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% endif %}
"""
def main():
client = {{ code_model.clients[0].name }}(
client = {{ client.name }}(
{% for key,value in client_params.items() %}
{{ key }}={{ value }},
{% endfor %}
Expand Down
Loading