Skip to content

Commit

Permalink
Fix resolve allowed resolved even if @path is used explicitly (#5016)
Browse files Browse the repository at this point in the history
fix #4967
  • Loading branch information
timotheeguerin authored Nov 7, 2024
1 parent fdd69d6 commit 34af566
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
16 changes: 9 additions & 7 deletions packages/http/src/http-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function getHttpProperty(
options: GetHttpPropertyOptions = {},
): [HttpProperty, readonly Diagnostic[]] {
const diagnostics: Diagnostic[] = [];

function createResult<T extends Omit<HttpProperty, "path" | "property">>(
opts: T,
): [HttpProperty & T, readonly Diagnostic[]] {
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions packages/http/test/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 34af566

Please sign in to comment.