diff --git a/plugins/importer-postman/src/index.ts b/plugins/importer-postman/src/index.ts index a36142b6..c0cc5bb7 100644 --- a/plugins/importer-postman/src/index.ts +++ b/plugins/importer-postman/src/index.ts @@ -180,8 +180,12 @@ function convertUrl(rawUrl: unknown): Pick v += `:${url.port}`; } - if ("path" in url && Array.isArray(url.path) && url.path.length > 0) { - v += `/${Array.isArray(url.path) ? url.path.join("/") : url.path}`; + if ("path" in url) { + if (Array.isArray(url.path) && url.path.length > 0) { + v += `/${url.path.join("/")}`; + } else if (typeof url.path === "string" && url.path.length > 0) { + v += `/${url.path.replace(/^\//, "")}`; + } } const params: HttpUrlParameter[] = []; diff --git a/plugins/importer-postman/tests/index.test.ts b/plugins/importer-postman/tests/index.test.ts index 399605d4..2fea86c2 100644 --- a/plugins/importer-postman/tests/index.test.ts +++ b/plugins/importer-postman/tests/index.test.ts @@ -57,4 +57,34 @@ describe("importer-postman", () => { }), ]); }); + + test("Imports url.path when it is a string instead of an array", () => { + const result = convertPostman( + JSON.stringify({ + info: { + name: "String Path Test", + schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + }, + item: [ + { + name: "String Path", + request: { + method: "GET", + url: { + host: ["example", "com"], + path: "foo/bar", + }, + }, + }, + ], + }), + ); + + expect(result?.resources.httpRequests).toEqual([ + expect.objectContaining({ + name: "String Path", + url: "example.com/foo/bar", + }), + ]); + }); });