Skip to content

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

Merged
timotheeguerin merged 19 commits into
mainfrom
copilot/relax-encode-for-boolean
Jun 24, 2026
Merged

Allow @encode(string) on boolean, define case-insensitive true|false string semantics, and add Spector coverage + generic string matcher support#10875
timotheeguerin merged 19 commits into
mainfrom
copilot/relax-encode-for-boolean

Conversation

Copilot AI commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@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 a standard matcher so request boolean-string values are accepted case-insensitively (true/false), while still returning varied response casings for coverage.
  • Spector standard matcher support

    • Added a built-in generic string matcher in @typespec/spec-api: match.string.caseInsensitive(string).
    • Replaced the encode/boolean scenario’s local custom matcher with this shared matcher (match.string.caseInsensitive(String(requestValue))).
    • Added matcher unit tests under packages/spec-api/test/matchers/string.test.ts.
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>
Comment thread packages/compiler/generated-defs/TypeSpec.ts
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>
@timotheeguerin

Copy link
Copy Markdown
Member

@copilot formatting also failing run formatter

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot need to regenerate the definitions

git status --porcelain
ERROR: Files above were changed during PR validation, but not included in the PR.
...

Fixed in f095d13: I regenerated compiler definitions (pnpm gen-compiler-extern-signature) and committed the updated packages/compiler/generated-defs/TypeSpec.ts. I also ran package builds during validation (@typespec/compiler, @typespec/spec-api, and repository pnpm build).

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot formatting also failing run formatter

Fixed in 7d5c391. I ran the formatter and committed the formatting updates for the two files flagged by CI; pnpm run format:check now passes.

@timotheeguerin

Copy link
Copy Markdown
Member

@copilot add changelogs

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add changelogs

Fixed in c58089f. I added the Chronus changelog entry covering @typespec/compiler, @typespec/spec-api, and @typespec/http-specs, and chronus verify --since main now passes.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label Jun 23, 2026
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
  • @typespec/http-specs
  • @typespec/spec-api
Show changes

@typespec/compiler - feature ✏️

Allow @encode(string) on boolean targets, define case-insensitive true/false string semantics, and add shared case-insensitive string matcher support with encode/boolean Spector coverage.,> ,> tsp,> model FeatureFlags {,> @encode(string),> enabled: boolean;,> },>

@typespec/spec-api - feature ✏️

Allow @encode(string) on boolean targets, define case-insensitive true/false string semantics, and add shared case-insensitive string matcher support with encode/boolean Spector coverage.,> ,> tsp,> model FeatureFlags {,> @encode(string),> enabled: boolean;,> },>

@typespec/http-specs - feature ✏️

Allow @encode(string) on boolean targets, define case-insensitive true/false string semantics, and add shared case-insensitive string matcher support with encode/boolean Spector coverage.,> ,> tsp,> model FeatureFlags {,> @encode(string),> enabled: boolean;,> },>

@timotheeguerin

Copy link
Copy Markdown
Member

@copilot need to regen docs

website/src/content/docs/docs/standard-library/built-in-decorators.md

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>

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot need to regen docs

website/src/content/docs/docs/standard-library/built-in-decorators.md

...

Done in da8cac9. I regenerated the docs so website/src/content/docs/docs/standard-library/built-in-decorators.md is included, and I updated the changelog entry to include a TypeSpec usage example.

@timotheeguerin timotheeguerin added this pull request to the merge queue Jun 24, 2026
Merged via the queue into main with commit 85ff828 Jun 24, 2026
28 checks passed
@timotheeguerin timotheeguerin deleted the copilot/relax-encode-for-boolean branch June 24, 2026 18:23
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 stale Mark a PR that hasn't been recently updated and will be closed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Encode decorator applicable to boolean

3 participants