Skip to content

Commit

Permalink
chore(deps): replace cookie with @swaggerexpect/cookie (#3761)
Browse files Browse the repository at this point in the history
This should be a fully backward compatible
replacement with benefit of new library
being compatible with Node.js 12.20.x.

Closes #3714
  • Loading branch information
char0n authored Jan 6, 2025
1 parent 02b40a6 commit 03c0bba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
23 changes: 13 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@swagger-api/apidom-json-pointer": ">=1.0.0-beta.6 <1.0.0-rc.0",
"@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-beta.6 <1.0.0-rc.0",
"@swagger-api/apidom-reference": ">=1.0.0-beta.6 <1.0.0-rc.0",
"cookie": "~0.7.2",
"@swaggerexpert/cookie": "^1.4.1",
"deepmerge": "~4.3.0",
"fast-json-patch": "^3.0.0-1",
"js-yaml": "^4.1.0",
Expand Down
17 changes: 15 additions & 2 deletions src/execute/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import cookie from 'cookie';
import { identity } from 'ramda';
import { isPlainObject } from 'ramda-adjunct';
import {
test as testServerURLTemplate,
substitute as substituteServerURLTemplate,
} from 'openapi-server-url-templating';
import {
serializeCookie,
cookieValueLenientEncoder,
cookieNameLenientValidator,
cookieValueLenientValidator,
} from '@swaggerexpert/cookie';
import { ApiDOMStructuredError } from '@swagger-api/apidom-error';
import { url } from '@swagger-api/apidom-reference/configuration/empty';

Expand Down Expand Up @@ -297,7 +302,15 @@ export function buildRequest(options) {
const cookieString = Object.keys(req.cookies).reduce((prev, cookieName) => {
const cookieValue = req.cookies[cookieName];
const prefix = prev ? '&' : '';
const stringified = cookie.serialize(cookieName, cookieValue);
const stringified = serializeCookie([[cookieName, cookieValue]], {
encoders: {
value: cookieValueLenientEncoder,
},
validators: {
name: cookieNameLenientValidator,
value: cookieValueLenientValidator,
},
});
return prev + prefix + stringified;
}, '');
req.headers.Cookie = cookieString;
Expand Down

0 comments on commit 03c0bba

Please # to comment.