Skip to content

feat(http-client-python): add encode/boolean Spector mock API tests + fix boolean-as-string encoding#11087

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/add-test-case-for-pull-10875
Draft

feat(http-client-python): add encode/boolean Spector mock API tests + fix boolean-as-string encoding#11087
Copilot wants to merge 5 commits into
mainfrom
copilot/add-test-case-for-pull-10875

Conversation

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Adds Python SDK mock API test coverage for the encode/boolean Spector scenarios from #10875 (@encode(string) on boolean types). This required fixing multiple layers of the Python codegen stack that were not yet aware of boolean string encoding.

Generator fixes

primitive_types.pyBooleanType
Added __init__ to detect yaml_data["encode"] == "string" and set self.encode = "str", mirroring the existing IntegerType behavior.

model_base.py.jinja2
Added _deserialize_bool_as_str to correctly handle case-insensitive string→bool deserialization. Python's built-in bool("false") returns True (any non-empty string is truthy), so a dedicated deserializer is required:

def _deserialize_bool_as_str(attr: str) -> bool:
    return attr.lower() == "true"

Also added the corresponding dispatch in get_deserializer for annotation is bool and rf._format == "str".

Test coverage

4 new test files (sync + async × azure + unbranded) covering all Spector scenarios:

  • trueLower — sends/receives "true", deserializes to True
  • falseLower — sends/receives "false", deserializes to False
  • trueUpper — sends/receives "TRUE", deserializes to True
  • falseMixed — sends/receives "FaLsE", deserializes to False

Dependencies

  • Bumped @typespec/http-specs to 0.1.0-alpha.39-dev.4 (first version containing the encode/boolean spec)
  • Added encode/boolean to regenerate-common.ts

…oolean string encode support

- Add `encode/boolean` to regenerate-common.ts spec list
- Bump @typespec/http-specs to 0.1.0-alpha.39-dev.4 (includes encode/boolean spec)
- Fix TCGC to propagate encode=string for boolean types
- Fix Python generator BooleanType to set encode="str" when @encode(string) is used
- Add _deserialize_bool_as_str to model_base.py.jinja2 template
- Add sync and async mock API tests for azure and unbranded flavors
- Add changelog entry

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Jun 24, 2026
…n assertions

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot AI changed the title [WIP] Add test case for pull request 10875 feat(http-client-python): add encode/boolean Spector mock API tests + fix boolean-as-string encoding Jun 24, 2026
Copilot finished work on behalf of msyyc June 24, 2026 23:44
Copilot AI requested a review from msyyc June 24, 2026 23:44
@msyyc

msyyc commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Need new compiler version to support this feature.

Comment thread .chronus/changes/python-encode-boolean-test-2026-6-24-23-0-0.md Outdated
… feature

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot finished work on behalf of msyyc June 25, 2026 02:10
Copilot AI requested a review from msyyc June 25, 2026 02:10
@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@11087

commit: 3e6bfb1

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - feature ✏️

Add mock API test coverage for @encode(string) on boolean properties (encode/boolean Spector scenarios). Fix Python generator to correctly serialize and deserialize boolean values encoded as strings (case-insensitive true/false).

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

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants