From 34af566eca9855ad21a12d8af9918ef292da99ab Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 7 Nov 2024 13:37:59 -0800 Subject: [PATCH] Fix resolve allowed resolved even if @path is used explicitly (#5016) fix #4967 --- ...explicit-allow-reserved-2024-10-7-20-13-23.md | 8 ++++++++ packages/http/src/http-property.ts | 16 +++++++++------- packages/http/test/routes.test.ts | 8 ++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 .chronus/changes/fix-path-explicit-allow-reserved-2024-10-7-20-13-23.md diff --git a/.chronus/changes/fix-path-explicit-allow-reserved-2024-10-7-20-13-23.md b/.chronus/changes/fix-path-explicit-allow-reserved-2024-10-7-20-13-23.md new file mode 100644 index 00000000000..e8d36271d6b --- /dev/null +++ b/.chronus/changes/fix-path-explicit-allow-reserved-2024-10-7-20-13-23.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/http" +--- + +Uri template attributes were not extracted when parameter was explicitly mark with `@path` or `@query` as well diff --git a/packages/http/src/http-property.ts b/packages/http/src/http-property.ts index e44da5575ef..04bfdd88483 100644 --- a/packages/http/src/http-property.ts +++ b/packages/http/src/http-property.ts @@ -100,6 +100,7 @@ function getHttpProperty( options: GetHttpPropertyOptions = {}, ): [HttpProperty, readonly Diagnostic[]] { const diagnostics: Diagnostic[] = []; + function createResult>( opts: T, ): [HttpProperty & T, readonly Diagnostic[]] { @@ -162,14 +163,15 @@ function getHttpProperty( ); } } + // if implicit just returns as it is. Validation above would have checked nothing was set explicitly apart from the type and that the type match + if (implicit) { + return createResult({ + kind: implicit.type, + options: implicit as any, + property, + }); + } if (defined.length === 0) { - if (implicit) { - return createResult({ - kind: implicit.type, - options: implicit as any, - property, - }); - } return createResult({ kind: "bodyProperty" }); } else if (defined.length > 1) { diagnostics.push( diff --git a/packages/http/test/routes.test.ts b/packages/http/test/routes.test.ts index babc7bddc44..060d637f85a 100644 --- a/packages/http/test/routes.test.ts +++ b/packages/http/test/routes.test.ts @@ -540,6 +540,14 @@ describe("uri template", () => { expectPathParameter(param, { style: "simple", allowReserved: true, explode: false }); }); + it("+ operator map to allowReserved even with @path set", async () => { + const param = await getParameter( + `@route("/bar/{+foo}") op foo(@path foo: string): void;`, + "foo", + ); + expectPathParameter(param, { style: "simple", allowReserved: true, explode: false }); + }); + it.each([ [";", "matrix"], ["#", "fragment"],