Allow @encode(string) on boolean, define case-insensitive true|false string semantics, and add Spector coverage + generic string matcher support - #10875
Conversation
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@encode(string) on boolean and define true|false string semantics
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@encode(string) on boolean and define true|false string semantics@encode(string) on boolean, define true|false string semantics, and add Spector coverage
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Fixed in f095d13: I regenerated compiler definitions ( |
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
|
@copilot add changelogs |
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
|
All changed packages have been documented.
Show changes
|
|
@copilot need to regen docs shows as modified. Also show an example of usage in the changelog entry as per comment |
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
… fix boolean-as-string encoding (microsoft#11087) Adds Python SDK mock API test coverage for the `encode/boolean` Spector scenarios from microsoft#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.py` — `BooleanType`** 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: ```python 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 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
|
Any service uses it? When asking agent to impl in Java emitter (thought it be an easy fix, but...), it instead sees TCGC support is not yet ready. If this is true, TCGC require some work first. <-- never mind, TCGC is doing a fix |
@encode(string)was restricted to numeric targets, blocking APIs that model booleans as strings (for example"true"/"false"in payloads or query values). This change extends support to boolean targets, clarifies the docs contract, and adds http-specs Spector coverage.Compiler validation
@encodevalidation so the implicit string encoding path (@encode(string)) is valid forbooleanin addition tonumeric.Standard library/docs contract
@encodedecorator docs to state boolean string encoding uses case-insensitivetrue/falsevalues.@encode(string)example.Coverage
@encode(string)on a boolean model property.packages/http-specs/specs/encode/booleanwith matching mock API and regeneratedpackages/http-specs/spec-summary.md./encode/boolean/property/true-lower/encode/boolean/property/false-lower/encode/boolean/property/true-upper/encode/boolean/property/false-mixedtrue/false), while still returning varied response casings for coverage.Spector standard matcher support
@typespec/spec-api:match.string.caseInsensitive(string).match.string.caseInsensitive(String(requestValue))).packages/spec-api/test/matchers/string.test.ts.