Skip to content

Allow @encode(string) on boolean, define case-insensitive true|false string semantics, and add Spector coverage#10875

Draft
Copilot wants to merge 10 commits into
mainfrom
copilot/relax-encode-for-boolean
Draft

Allow @encode(string) on boolean, define case-insensitive true|false string semantics, and add Spector coverage#10875
Copilot wants to merge 10 commits into
mainfrom
copilot/relax-encode-for-boolean

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 3, 2026

@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

    • Relaxed @encode validation so the implicit string encoding path (@encode(string)) is valid for boolean in addition to numeric.
    • Updated related diagnostic wording to reflect numeric-or-boolean applicability.
  • Standard library/docs contract

    • Updated @encode decorator docs to state boolean string encoding uses case-insensitive true / false values.
    • Added a boolean-focused @encode(string) example.
    • Removed parsing-specific wording from the boolean string semantics text.
  • Coverage

    • Added a focused compiler decorator test that validates @encode(string) on a boolean model property.
    • Updated the non-supported-type expectation to match the new allowed target set.
    • Added/updated Spector coverage in packages/http-specs/specs/encode/boolean with matching mock API and regenerated packages/http-specs/spec-summary.md.
    • Boolean property scenarios now cover multiple casings/values via:
      • /encode/boolean/property/true-lower
      • /encode/boolean/property/false-lower
      • /encode/boolean/property/true-upper
      • /encode/boolean/property/false-mixed
    • Updated boolean mock API request validation to use an asymmetric matcher so request boolean-string values are accepted case-insensitively (true/false), while still returning varied response casings for coverage.
model FeatureFlags {
  @encode(string)
  enabled: boolean;
}

Copilot AI linked an issue Jun 3, 2026 that may be closed by this pull request
3 tasks
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates labels Jun 3, 2026
Copilot AI changed the title [WIP] Update encode decorator to support boolean values Allow @encode(string) on boolean and define true|false string semantics Jun 3, 2026
Copilot AI requested a review from timotheeguerin June 3, 2026 16:36
Comment thread website/src/content/docs/docs/standard-library/built-in-decorators.md Outdated
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot add a spector test in http-specs packages

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 8237396.

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the lib:http-specs For issues/prs related to the @typespec/http-specs package label Jun 3, 2026
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Comment thread packages/http-specs/specs/encode/numeric/main.tsp Outdated
Copilot AI and others added 2 commits June 3, 2026 18:06
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title Allow @encode(string) on boolean and define true|false string semantics Allow @encode(string) on boolean, define true|false string semantics, and add Spector coverage Jun 3, 2026
Copilot AI requested a review from timotheeguerin June 3, 2026 18:09
Comment thread packages/http-specs/specs/encode/boolean/main.tsp Outdated
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title Allow @encode(string) on boolean, define true|false string semantics, and add Spector coverage Allow @encode(string) on boolean, define case-insensitive true|false string semantics, and add Spector coverage Jun 3, 2026
Copilot AI requested a review from timotheeguerin June 3, 2026 18:18
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Comment thread packages/http-specs/specs/encode/boolean/mockapi.ts
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler lib:http-specs For issues/prs related to the @typespec/http-specs package meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Encode decorator applicable to boolean

2 participants