swagger-api / swagger-api/swagger-client

OAS3 seems not to support multiple cookies

Open
#4,155 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.7k
Forks
765
Avg merge
1d 1h
Merged PRs (30d)
6

Description

Q&A (please complete the following information)
  • OS: [e.g. macOS] macOS
  • Environment: [e.g. Chrome 59, Node.js v10.0.0] Node v22.22.0
  • Method of installation: [e.g. npm, unpkg] pnpm
  • Swagger-Client version: [e.g. 3.8.0] 3.35.5
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0] OAS3
Content & configuration

Swagger/OpenAPI definition:

n/a

Swagger-Client usage:

import SwaggerClient from "swagger-client";

const operationId = "cookieTest";

const req = SwaggerClient.buildRequest({
  spec: {
    openapi: "3.1.0",
    paths: {
      "/": {
        get: {
          operationId,
          parameters: [
            {
              name: "c1",
              in: "cookie",
            },
            {
              name: "c2",
              in: "cookie",
            },
          ],
        },
      },
    },
  },
  operationId,
  parameters: {
    c1: "v1",
    c2: "v2",
  },
});

console.log(req.headers.Cookie);
if (req.headers.Cookie === "c2=v2") {
  console.log("Seems like should be both cookies");
}

Describe the bug you're encountering
To reproduce...

Steps to reproduce the behavior:

  1. Set more than one cookie parameter
  2. Observe that only last cookie is set
Expected behavior

Expect when there are multiple cookies set, they will all be set. However, only last is set.

Additional context or thoughts

In https://github.com/swagger-api/swagger-js/blob/7baca902b84d757ff7490cd66d0cb5ead6ad5834/src/execute/oas3/parameter-builders.js#L118 Cookie is always overwritten in both cases. OAS2 was not examined

    req.headers.Cookie = serializeCookie({ [cookieName]: cookieValue });

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/execute/oas3/parameter-builders.js at the referenced cookie-building code around line 118. Run the provided SwaggerClient.buildRequest reproduction with c1 and c2, then verify that the resulting Cookie header preserves both values rather than only the last one.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.