From 9a55b3a593be49f29d7d4cd79f4d736158e69146 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez <6895254+AlitzelMendez@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:02:11 -0800 Subject: [PATCH] [HOTFIX] Fix @path decorator do not accurately reflect the options parameters (#5535) hotfix for issue: https://github.com/Azure/typespec-azure/issues/1962 --- .../fix-path-decorator-options-2025-0-8-11-34-19.md | 7 +++++++ packages/rest/src/resource.ts | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .chronus/changes/fix-path-decorator-options-2025-0-8-11-34-19.md diff --git a/.chronus/changes/fix-path-decorator-options-2025-0-8-11-34-19.md b/.chronus/changes/fix-path-decorator-options-2025-0-8-11-34-19.md new file mode 100644 index 0000000000..7cf606c5b6 --- /dev/null +++ b/.chronus/changes/fix-path-decorator-options-2025-0-8-11-34-19.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/rest" +--- + +In some scenarios, the options for the `@path` decorator do not accurately reflect the provided parameters, including the `#{allowReserved: true}` which is the `x-ms-skip-url-encoding` option. This change addresses and fixes this issue. diff --git a/packages/rest/src/resource.ts b/packages/rest/src/resource.ts index 13de2131a4..d65d1f3d61 100644 --- a/packages/rest/src/resource.ts +++ b/packages/rest/src/resource.ts @@ -116,16 +116,19 @@ function cloneKeyProperties(context: DecoratorContext, target: Model, resourceTy // filtering. NOTE: Check for name equality instead of function equality // to deal with multiple copies of core being used. ...keyProperty.decorators.filter((d) => d.decorator.name !== $visibility.name), - { - decorator: $path, - args: [], - }, { decorator: $resourceTypeForKeyParam, args: [{ node: target.node, value: resourceType, jsValue: resourceType }], }, ]; + if (!keyProperty.decorators.some((d) => d.decorator.name === $path.name)) { + decorators.push({ + decorator: $path, + args: [], + }); + } + // Clone the key property and ensure that an optional key property doesn't // become an optional path parameter const newProp = program.checker.cloneType(keyProperty, {