-
Notifications
You must be signed in to change notification settings - Fork 373
Allow @encode(string) on boolean, define case-insensitive true|false string semantics, and add Spector coverage + generic string matcher support
#10875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
16
commits into
main
Choose a base branch
from
copilot/relax-encode-for-boolean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0fb96cb
Initial plan
Copilot 26d634d
feat(compiler): allow @encode(string) on boolean
Copilot dbd1269
docs: simplify boolean @encode(string) wording
Copilot 8237396
test(http-specs): add boolean @encode(string) spector scenario
Copilot ab2b2d1
test(http-specs): refine boolean encode scenario naming
Copilot 2e01d67
test(http-specs): clarify boolean string encode route
Copilot 1f88780
test(http-specs): move boolean encode scenario to encode/boolean
Copilot d015290
Address encode boolean docs and scenario feedback
Copilot 888a49e
test(http-specs): use doc comment in boolean encode spec
Copilot 397cbd1
test(http-specs): accept case-insensitive boolean request casing
Copilot 5df2924
feat(spec-api): add case-insensitive boolean string matcher
Copilot 4c3aba6
refactor(spec-api): generalize case-insensitive string matcher
Copilot 8cfc913
chore(spec-api): simplify string matcher error messages
Copilot f095d13
chore(compiler): regenerate generated defs
Copilot 7d5c391
style: format boolean encode spec and string matcher tests
Copilot c58089f
chore: add chronus changelog entries for encode boolean updates
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
.chronus/changes/copilot-encode-string-boolean-changelog-2026-6-5-17-25-0.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/compiler" | ||
| - "@typespec/spec-api" | ||
| - "@typespec/http-specs" | ||
| --- | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import "@typespec/http"; | ||
| import "@typespec/spector"; | ||
|
|
||
| using Http; | ||
| using Spector; | ||
|
|
||
| /** Test for encode decorator on boolean. */ | ||
| @scenarioService("/encode/boolean") | ||
| namespace Encode.Boolean; | ||
|
|
||
| @route("/property") | ||
| namespace Property { | ||
| model BoolAsStringProperty { | ||
| @encode(string) | ||
| value: boolean; | ||
| } | ||
|
|
||
| alias SendBoolTrueLower = SendBoolAsString<"true">; | ||
|
|
||
| @route("/true-lower") | ||
| op trueLower is SendBoolTrueLower.sendBoolAsString; | ||
|
|
||
| alias SendBoolFalseLower = SendBoolAsString<"false">; | ||
|
|
||
| @route("/false-lower") | ||
| op falseLower is SendBoolFalseLower.sendBoolAsString; | ||
|
|
||
| alias SendBoolTrueUpper = SendBoolAsString<"TRUE">; | ||
|
|
||
| @route("/true-upper") | ||
| op trueUpper is SendBoolTrueUpper.sendBoolAsString; | ||
|
|
||
| alias SendBoolFalseMixed = SendBoolAsString<"FaLsE">; | ||
|
|
||
| @route("/false-mixed") | ||
| op falseMixed is SendBoolFalseMixed.sendBoolAsString; | ||
|
|
||
| interface SendBoolAsString<StringValue extends string> { | ||
| @scenario | ||
| @scenarioDoc( | ||
| """ | ||
| Test operation with request and response model containing a property of boolean type with string encode. | ||
| Expected request body: | ||
| ```json | ||
| { | ||
| "value": "{value}" | ||
| } | ||
| ``` | ||
| Expected response body: | ||
| ```json | ||
| { | ||
| "value": "{value}" | ||
| } | ||
| ``` | ||
| """, | ||
| { | ||
| value: StringValue, | ||
| } | ||
| ) | ||
| @post | ||
| sendBoolAsString(@body value: BoolAsStringProperty): BoolAsStringProperty; | ||
| } | ||
| } |
|
timotheeguerin marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { json, match, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"; | ||
|
|
||
| export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
|
||
| function createBodyServerTests(uri: string, responseValue: string, requestValue: boolean) { | ||
| return passOnSuccess({ | ||
| uri, | ||
| method: "post", | ||
| request: { | ||
| body: json({ | ||
| value: match.string.caseInsensitive(String(requestValue)), | ||
| }), | ||
| }, | ||
| response: { | ||
| status: 200, | ||
| body: json({ | ||
| value: responseValue, | ||
| }), | ||
| }, | ||
| kind: "MockApiDefinition", | ||
| }); | ||
| } | ||
|
|
||
| Scenarios.Encode_Boolean_Property_trueLower = createBodyServerTests( | ||
| "/encode/boolean/property/true-lower", | ||
| "true", | ||
| true, | ||
| ); | ||
| Scenarios.Encode_Boolean_Property_falseLower = createBodyServerTests( | ||
| "/encode/boolean/property/false-lower", | ||
| "false", | ||
| false, | ||
| ); | ||
| Scenarios.Encode_Boolean_Property_trueUpper = createBodyServerTests( | ||
| "/encode/boolean/property/true-upper", | ||
| "TRUE", | ||
| true, | ||
| ); | ||
| Scenarios.Encode_Boolean_Property_falseMixed = createBodyServerTests( | ||
| "/encode/boolean/property/false-mixed", | ||
| "FaLsE", | ||
| false, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { createMatcher, err, type MockValueMatcher, ok } from "../match-engine.js"; | ||
|
|
||
| export const stringMatcher = { | ||
| caseInsensitive(value: string): MockValueMatcher<string> { | ||
| const normalized = value.toLowerCase(); | ||
| return createMatcher({ | ||
| check(actual: unknown) { | ||
| if (typeof actual !== "string") { | ||
| return err(`expected a string but got ${typeof actual}`); | ||
| } | ||
| if (actual.toLowerCase() !== normalized) { | ||
| return err(`expected case-insensitive "${value}" but got "${actual}"`); | ||
| } | ||
| return ok(); | ||
| }, | ||
| serialize() { | ||
| return value; | ||
| }, | ||
| toString() { | ||
| return `match.string.caseInsensitive("${value}")`; | ||
| }, | ||
| }); | ||
| }, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.