diff --git a/plugins/importer-openapi/src/index.ts b/plugins/importer-openapi/src/index.ts index 5ac84b84..9b5f8170 100644 --- a/plugins/importer-openapi/src/index.ts +++ b/plugins/importer-openapi/src/index.ts @@ -1604,7 +1604,8 @@ function mergeHeaders(...headerGroups: HttpRequestHeader[][]): HttpRequestHeader for (const group of headerGroups) { const namesFromEarlierGroups = new Set(headers.map((header) => header.name.toLowerCase())); for (const header of group) { - if (!namesFromEarlierGroups.has(header.name.toLowerCase())) { + const name = header.name.toLowerCase(); + if (name === "cookie" || !namesFromEarlierGroups.has(name)) { headers.push(header); } } diff --git a/plugins/importer-openapi/tests/index.test.ts b/plugins/importer-openapi/tests/index.test.ts index d48ae3a2..048260b2 100644 --- a/plugins/importer-openapi/tests/index.test.ts +++ b/plugins/importer-openapi/tests/index.test.ts @@ -807,6 +807,53 @@ describe("importer-openapi", () => { ]); }); + test("Preserves parameter cookies alongside cookie API-key authentication", async () => { + const imported = await convertOpenApi( + JSON.stringify({ + openapi: "3.0.4", + info: { title: "Authenticated Cookie Test", version: "1.0.0" }, + paths: { + "/items": { + get: { + security: [{ basicAuth: [], cookieKey: [] }], + parameters: [ + { + name: "session", + in: "cookie", + required: true, + schema: { type: "string", example: "abc" }, + }, + { + name: "debug", + in: "cookie", + schema: { type: "string", example: "verbose" }, + }, + ], + responses: {}, + }, + }, + }, + components: { + securitySchemes: { + basicAuth: { type: "http", scheme: "basic" }, + cookieKey: { type: "apiKey", in: "cookie", name: "api_key" }, + }, + }, + }), + ); + + expect(imported?.resources.httpRequests[0]).toEqual( + expect.objectContaining({ + authenticationType: "basic", + headers: [ + { enabled: true, name: "Cookie", value: "api_key=${[auth_cookie_key_key]}" }, + { enabled: true, name: "Cookie", value: "session=abc" }, + { enabled: false, name: "Cookie", value: "debug=verbose" }, + ], + }), + ); + }); + test("Serializes structured query parameters according to style and explode", async () => { const imported = await convertOpenApi( JSON.stringify({