Skip to content

Commit

Permalink
Merge pull request #1364 from tobiaswatzek/1357-path-parameters
Browse files Browse the repository at this point in the history
Allow falsy values as path parameters in URL
  • Loading branch information
baywet authored Sep 10, 2024
2 parents d45aec9 + 086486e commit 4137905
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/abstractions/src/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class RequestInformation implements RequestInformationSetContent {
}
}
for (const key in this.pathParameters) {
if (this.pathParameters[key]) {
if (this.pathParameters[key] !== null && this.pathParameters[key] !== undefined) {
data[key] = this.normalizeValue(this.pathParameters[key]);
}
}
Expand Down
24 changes: 24 additions & 0 deletions packages/abstractions/test/common/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,30 @@ describe("RequestInformation", () => {
assert.equal(requestInformation.URL, "http://localhost/me?datasets=1,2");
});

it.each([
{ someNumber: -1, expected: "http://localhost/-1" },
{ someNumber: 0, expected: "http://localhost/0" },
{ someNumber: 1, expected: "http://localhost/1" },
{ someNumber: NaN, expected: "http://localhost/NaN" },
])("Sets number $someNumber in path parameters", () => {
const requestInformation = new RequestInformation();
requestInformation.pathParameters["baseurl"] = baseUrl;
requestInformation.pathParameters["someNumber"] = 0;
requestInformation.urlTemplate = "http://localhost/{someNumber}";
assert.equal(requestInformation.URL, "http://localhost/0");
});

it.each([
{ someBoolean: true, expected: "http://localhost/true" },
{ someBoolean: false, expected: "http://localhost/false" },
])("Sets false in path parameters", () => {
const requestInformation = new RequestInformation();
requestInformation.pathParameters["baseurl"] = baseUrl;
requestInformation.pathParameters["someBoolean"] = false;
requestInformation.urlTemplate = "http://localhost/{someBoolean}";
assert.equal(requestInformation.URL, "http://localhost/false");
});

it("Sets enum value in path parameters", () => {
const requestInformation = new RequestInformation();
requestInformation.pathParameters["baseurl"] = baseUrl;
Expand Down

0 comments on commit 4137905

Please sign in to comment.