Skip to content

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

Merged
msyyc merged 10 commits into
mainfrom
copilot/add-test-case-for-pull-10875
Jul 16, 2026
Merged

feat(http-client-python): add encode/boolean Spector mock API tests + fix boolean-as-string encoding#11087
msyyc merged 10 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 updating multiple layers of the Python codegen stack.

Generator fixes

types.ts — property emission
Preserves boolean @encode(string) metadata from the compiler and maps it to the Python runtime’s "str" format token.

primitive_types.pyBooleanType
Detects yaml_data["encode"] == "string" and sets self.encode = "str", mirroring IntegerType.

model_base.py.jinja2
Adds _deserialize_bool_as_str for case-insensitive string-to-boolean deserialization:

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

Also dispatches to it when annotation is bool and rf._format == "str".

Test coverage

Adds sync and async tests for Azure and unbranded clients covering:

  • trueLower"true"True
  • falseLower"false"False
  • trueUpper"TRUE"True
  • falseMixed"FaLsE"False

Dependencies

  • Uses @typespec/compiler 1.14, which supports boolean @encode(string).
  • Uses @typespec/http-specs 0.1.0-alpha.39, containing the encode/boolean scenarios.
  • Adds encode/boolean to regenerate-common.ts.

Code diff:

Azure/azure-sdk-for-python#48067

…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: 238985a

@github-actions

github-actions Bot commented Jun 25, 2026

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)

@msyyc

msyyc commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Copilot AI and others added 2 commits July 15, 2026 06:16
…add-test-case-for-pull-10875

# Conflicts:
#	packages/http-client-python/package-lock.json
#	packages/http-client-python/package.json

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
@msyyc
msyyc marked this pull request as ready for review July 15, 2026 06:22
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Resolved the conflicts with current main in merge commit 8c6548c58. The merged compiler metadata compatibility fix is in 646a638c7; all 16 targeted encode/boolean mock API tests pass.

@l0lawrence

Copy link
Copy Markdown
Member

@msyyc

msyyc commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@msyyc
msyyc added this pull request to the merge queue Jul 16, 2026
Merged via the queue into main with commit 3806025 Jul 16, 2026
36 checks passed
@msyyc
msyyc deleted the copilot/add-test-case-for-pull-10875 branch July 16, 2026 02:20
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.

3 participants