From 0f8ba61c607ff6356e137ca503b9c321ceede66a Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 13 Apr 2023 08:20:09 -0700 Subject: [PATCH 1/2] Fix query format restriction --- packages/http/src/decorators.ts | 4 +--- packages/http/test/http-decorators.test.ts | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/http/src/decorators.ts b/packages/http/src/decorators.ts index c7e5506ceaf..bfc5d4523a5 100644 --- a/packages/http/src/decorators.ts +++ b/packages/http/src/decorators.ts @@ -104,9 +104,7 @@ export function $query( } const format = queryNameOrOptions.properties.get("format")?.type; if (format?.kind === "String") { - if (format.value === "multi" || format.value === "csv") { - options.format = format.value; - } + options.format = format.value as any; // That value should have already been validated by the TypeSpec dec } } } diff --git a/packages/http/test/http-decorators.test.ts b/packages/http/test/http-decorators.test.ts index 129c9dc60a3..c43eae583ef 100644 --- a/packages/http/test/http-decorators.test.ts +++ b/packages/http/test/http-decorators.test.ts @@ -210,16 +210,19 @@ describe("http: decorators", () => { strictEqual(getQueryParamName(runner.program, select), "$select"); }); - it("override query with QueryOptions", async () => { - const { selects } = await runner.compile(` - @put op test(@test @query({name: "$select", format: "csv"}) selects: string[]): string; - `); - deepStrictEqual(getQueryParamOptions(runner.program, selects), { - type: "query", - name: "$select", - format: "csv", + describe("change format for array value", () => { + ["csv", "tsv", "ssv", "pipes"].forEach((format) => { + it(`set query format to "${format}"`, async () => { + const { selects } = await runner.compile(` + op test(@test @query({name: "$select", format: "${format}"}) selects: string[]): string; + `); + deepStrictEqual(getQueryParamOptions(runner.program, selects), { + type: "query", + name: "$select", + format, + }); + }); }); - strictEqual(getQueryParamName(runner.program, selects), "$select"); }); }); From 2d2176c5d7879af187dbcf36e47c966cb3abc4be Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 13 Apr 2023 08:20:50 -0700 Subject: [PATCH 2/2] Changelog --- .../http/fix-query-format_2023-04-13-15-20.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@typespec/http/fix-query-format_2023-04-13-15-20.json diff --git a/common/changes/@typespec/http/fix-query-format_2023-04-13-15-20.json b/common/changes/@typespec/http/fix-query-format_2023-04-13-15-20.json new file mode 100644 index 00000000000..3d87b68851e --- /dev/null +++ b/common/changes/@typespec/http/fix-query-format_2023-04-13-15-20.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/http", + "comment": "**Fix** query format not accepting anything other than `csv` and `multi`", + "type": "none" + } + ], + "packageName": "@typespec/http" +} \ No newline at end of file