@readme/oas-to-har 23.2.1 → 23.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-EOITCV6F.js → chunk-B6VBOO2O.js} +2 -2
- package/dist/chunk-B6VBOO2O.js.map +1 -0
- package/dist/{chunk-V2WHK4KJ.cjs → chunk-QPHB6RUE.cjs} +3 -3
- package/dist/{chunk-V2WHK4KJ.cjs.map → chunk-QPHB6RUE.cjs.map} +1 -1
- package/dist/index.cjs +54 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -44
- package/dist/index.js.map +1 -1
- package/dist/lib/configure-security.cjs +4 -3
- package/dist/lib/configure-security.d.cts +1 -1
- package/dist/lib/configure-security.d.ts +1 -1
- package/dist/lib/configure-security.js +1 -1
- package/dist/lib/types.d.cts +2 -2
- package/dist/lib/types.d.ts +2 -2
- package/package.json +14 -16
- package/dist/chunk-EOITCV6F.js.map +0 -1
|
@@ -10,7 +10,7 @@ function configureSecurity(apiDefinition, values, scheme) {
|
|
|
10
10
|
return void 0;
|
|
11
11
|
if (Object.keys(values || {}).length === 0)
|
|
12
12
|
return void 0;
|
|
13
|
-
if (!apiDefinition.components
|
|
13
|
+
if (!apiDefinition.components?.securitySchemes?.[scheme])
|
|
14
14
|
return void 0;
|
|
15
15
|
const security = apiDefinition.components.securitySchemes[scheme];
|
|
16
16
|
if (isRef(security)) {
|
|
@@ -80,4 +80,4 @@ function configureSecurity(apiDefinition, values, scheme) {
|
|
|
80
80
|
export {
|
|
81
81
|
configureSecurity
|
|
82
82
|
};
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-B6VBOO2O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/configure-security.ts"],"sourcesContent":["import type { AuthForHAR } from './types.js';\nimport type { OASDocument, SecuritySchemeObject } from 'oas/types';\n\nimport { isRef } from 'oas/types';\n\nfunction harValue(type: 'cookies' | 'headers' | 'queryString', value: { name: string; value: string }) {\n if (!value.value) return undefined;\n return { type, value };\n}\n\nexport default function configureSecurity(apiDefinition: OASDocument, values: AuthForHAR, scheme: string) {\n if (!scheme) return undefined;\n\n if (Object.keys(values || {}).length === 0) return undefined;\n\n if (!apiDefinition.components?.securitySchemes?.[scheme]) return undefined;\n const security = apiDefinition.components.securitySchemes[scheme] as SecuritySchemeObject & {\n 'x-bearer-format'?: string;\n };\n\n if (isRef(security)) {\n return undefined;\n } else if (!values[scheme]) {\n // If we don't have any data for this auth scheme then we shouldn't add it.\n return false;\n }\n\n if (security.type === 'http') {\n if (security.scheme === 'basic') {\n const auth = values[scheme];\n if (typeof auth !== 'object') return false;\n if (!auth.user && !auth.pass) return false;\n\n let user = auth.user ?? null;\n if (user === null || user.length === 0) {\n user = '';\n }\n\n let pass = auth.pass ?? null;\n if (pass === null || pass.length === 0) {\n pass = '';\n }\n\n return harValue('headers', {\n name: 'authorization',\n value: `Basic ${Buffer.from(`${user}:${pass}`).toString('base64')}`,\n });\n } else if (security.scheme === 'bearer') {\n return harValue('headers', {\n name: 'authorization',\n value: `Bearer ${values[scheme]}`,\n });\n }\n }\n\n if (security.type === 'apiKey') {\n if (security.in === 'query') {\n return harValue('queryString', {\n name: security.name,\n value: String(values[scheme]),\n });\n } else if (security.in === 'header') {\n const header = {\n name: security.name,\n value: String(values[scheme]),\n };\n\n if (security['x-bearer-format']) {\n // Uppercase: token -> Token\n const bearerFormat = security['x-bearer-format'].charAt(0).toUpperCase() + security['x-bearer-format'].slice(1);\n header.name = security.name;\n header.value = `${bearerFormat} ${header.value}`;\n }\n\n return harValue('headers', header);\n } else if (security.in === 'cookie') {\n return harValue('cookies', {\n name: security.name,\n value: String(values[scheme]),\n });\n }\n }\n\n if (security.type === 'oauth2') {\n return harValue('headers', {\n name: 'authorization',\n value: `Bearer ${values[scheme]}`,\n });\n }\n\n return undefined;\n}\n"],"mappings":";AAGA,SAAS,aAAa;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e;AAAA,QAC7B,MAAM,SAAS;AAAA,QACf,OAAO,OAAO,OAAO,MAAM,CAAC;AAAA,MAC9B,CAAC;AAAA,IACH,WAAW,SAAS,OAAO,UAAU;AACnC,YAAM,SAAS;AAAA,QACb,MAAM,SAAS;AAAA,QACf,OAAO,OAAO,OAAO,MAAM,CAAC;AAAA,MAC9B;AAEA,UAAI,SAAS,iBAAiB,GAAG;AAE/B,cAAM,eAAe,SAAS,iBAAiB,EAAE,OAAO,CAAC,EAAE,YAAY,IAAI,SAAS,iBAAiB,EAAE,MAAM,CAAC;AAC9G,eAAO,OAAO,SAAS;AACvB,eAAO,QAAQ,GAAG,YAAY,IAAI,OAAO,KAAK;AAAA,MAChD;AAEA,aAAO,SAAS,WAAW,MAAM;AAAA,IACnC,WAAW,SAAS,OAAO,UAAU;AACnC,aAAO,SAAS,WAAW;AAAA,QACzB,MAAM,SAAS;AAAA,QACf,OAAO,OAAO,OAAO,MAAM,CAAC;AAAA,MAC9B,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,SAAS,SAAS,UAAU;AAC9B,WAAO,SAAS,WAAW;AAAA,MACzB,MAAM;AAAA,MACN,OAAO,UAAU,OAAO,MAAM,CAAC;AAAA,IACjC,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/lib/configure-security.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/lib/configure-security.ts
|
|
2
2
|
var _types = require('oas/types');
|
|
3
3
|
function harValue(type, value) {
|
|
4
4
|
if (!value.value)
|
|
@@ -10,7 +10,7 @@ function configureSecurity(apiDefinition, values, scheme) {
|
|
|
10
10
|
return void 0;
|
|
11
11
|
if (Object.keys(values || {}).length === 0)
|
|
12
12
|
return void 0;
|
|
13
|
-
if (!apiDefinition.components.securitySchemes[scheme])
|
|
13
|
+
if (!_optionalChain([apiDefinition, 'access', _ => _.components, 'optionalAccess', _2 => _2.securitySchemes, 'optionalAccess', _3 => _3[scheme]]))
|
|
14
14
|
return void 0;
|
|
15
15
|
const security = apiDefinition.components.securitySchemes[scheme];
|
|
16
16
|
if (_types.isRef.call(void 0, security)) {
|
|
@@ -80,4 +80,4 @@ function configureSecurity(apiDefinition, values, scheme) {
|
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
exports.configureSecurity = configureSecurity;
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-QPHB6RUE.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/configure-security.ts"],"names":[],"mappings":";AAGA,SAAS,aAAa;AAEtB,SAAS,SAAS,MAA6C,OAAwC;AACrG,MAAI,CAAC,MAAM;AAAO,WAAO;AACzB,SAAO,EAAE,MAAM,MAAM;AACvB;AAEe,SAAR,kBAAmC,eAA4B,QAAoB,QAAgB;AACxG,MAAI,CAAC;AAAQ,WAAO;AAEpB,MAAI,OAAO,KAAK,UAAU,CAAC,CAAC,EAAE,WAAW;AAAG,WAAO;AAEnD,MAAI,CAAC,cAAc,
|
|
1
|
+
{"version":3,"sources":["../src/lib/configure-security.ts"],"names":[],"mappings":";AAGA,SAAS,aAAa;AAEtB,SAAS,SAAS,MAA6C,OAAwC;AACrG,MAAI,C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AO,OAAO,MAAM,CAAC;AAAA,MAC9B,CAAC;AAAA,IACH,WAAW,SAAS,OAAO,UAAU;AACnC,YAAM,SAAS;AAAA,QACb,MAAM,SAAS;AAAA,QACf,OAAO,OAAO,OAAO,MAAM,CAAC;AAAA,MAC9B;AAEA,UAAI,SAAS,iBAAiB,GAAG;AAE/B,cAAM,eAAe,SAAS,iBAAiB,EAAE,OAAO,CAAC,EAAE,YAAY,IAAI,SAAS,iBAAiB,EAAE,MAAM,CAAC;AAC9G,eAAO,OAAO,SAAS;AACvB,eAAO,QAAQ,GAAG,YAAY,IAAI,OAAO,KAAK;AAAA,MAChD;AAEA,aAAO,SAAS,WAAW,MAAM;AAAA,IACnC,WAAW,SAAS,OAAO,UAAU;AACnC,aAAO,SAAS,WAAW;AAAA,QACzB,MAAM,SAAS;AAAA,QACf,OAAO,OAAO,OAAO,MAAM,CAAC;AAAA,MAC9B,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,SAAS,SAAS,UAAU;AAC9B,WAAO,SAAS,WAAW;AAAA,MACzB,MAAM;AAAA,MACN,OAAO,UAAU,OAAO,MAAM,CAAC;AAAA,IACjC,CAAC;AAAA,EACH;AAEA,SAAO;AACT","sourcesContent":["import type { AuthForHAR } from './types.js';\nimport type { OASDocument, SecuritySchemeObject } from 'oas/types';\n\nimport { isRef } from 'oas/types';\n\nfunction harValue(type: 'cookies' | 'headers' | 'queryString', value: { name: string; value: string }) {\n if (!value.value) return undefined;\n return { type, value };\n}\n\nexport default function configureSecurity(apiDefinition: OASDocument, values: AuthForHAR, scheme: string) {\n if (!scheme) return undefined;\n\n if (Object.keys(values || {}).length === 0) return undefined;\n\n if (!apiDefinition.components?.securitySchemes?.[scheme]) return undefined;\n const security = apiDefinition.components.securitySchemes[scheme] as SecuritySchemeObject & {\n 'x-bearer-format'?: string;\n };\n\n if (isRef(security)) {\n return undefined;\n } else if (!values[scheme]) {\n // If we don't have any data for this auth scheme then we shouldn't add it.\n return false;\n }\n\n if (security.type === 'http') {\n if (security.scheme === 'basic') {\n const auth = values[scheme];\n if (typeof auth !== 'object') return false;\n if (!auth.user && !auth.pass) return false;\n\n let user = auth.user ?? null;\n if (user === null || user.length === 0) {\n user = '';\n }\n\n let pass = auth.pass ?? null;\n if (pass === null || pass.length === 0) {\n pass = '';\n }\n\n return harValue('headers', {\n name: 'authorization',\n value: `Basic ${Buffer.from(`${user}:${pass}`).toString('base64')}`,\n });\n } else if (security.scheme === 'bearer') {\n return harValue('headers', {\n name: 'authorization',\n value: `Bearer ${values[scheme]}`,\n });\n }\n }\n\n if (security.type === 'apiKey') {\n if (security.in === 'query') {\n return harValue('queryString', {\n name: security.name,\n value: String(values[scheme]),\n });\n } else if (security.in === 'header') {\n const header = {\n name: security.name,\n value: String(values[scheme]),\n };\n\n if (security['x-bearer-format']) {\n // Uppercase: token -> Token\n const bearerFormat = security['x-bearer-format'].charAt(0).toUpperCase() + security['x-bearer-format'].slice(1);\n header.name = security.name;\n header.value = `${bearerFormat} ${header.value}`;\n }\n\n return harValue('headers', header);\n } else if (security.in === 'cookie') {\n return harValue('cookies', {\n name: security.name,\n value: String(values[scheme]),\n });\n }\n }\n\n if (security.type === 'oauth2') {\n return harValue('headers', {\n name: 'authorization',\n value: `Bearer ${values[scheme]}`,\n });\n }\n\n return undefined;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkQPHB6RUEcjs = require('./chunk-QPHB6RUE.cjs');
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
var _dataurls = require('@readme/data-urls');
|
|
7
|
-
var
|
|
8
|
-
var _lodashset = require('lodash.set'); var _lodashset2 = _interopRequireDefault(_lodashset);
|
|
7
|
+
var _lodashes = require('lodash-es');
|
|
9
8
|
var _extensions = require('oas/extensions');
|
|
10
9
|
var _operation = require('oas/operation');
|
|
11
10
|
var _types = require('oas/types');
|
|
@@ -198,7 +197,7 @@ function encodePrimitive({ location, key, value, style, escape, isAllowedReserve
|
|
|
198
197
|
|
|
199
198
|
// src/lib/style-formatting/index.ts
|
|
200
199
|
function shouldNotStyleEmptyValues(parameter) {
|
|
201
|
-
return ["simple", "spaceDelimited", "pipeDelimited", "deepObject"].includes(parameter.style);
|
|
200
|
+
return ["simple", "spaceDelimited", "pipeDelimited", "deepObject"].includes(parameter.style || "");
|
|
202
201
|
}
|
|
203
202
|
function shouldNotStyleReservedHeader(parameter) {
|
|
204
203
|
return ["accept", "authorization", "content-type"].includes(parameter.name.toLowerCase());
|
|
@@ -350,7 +349,7 @@ function getSafeRequestBody(obj) {
|
|
|
350
349
|
function getSubschemas(schema, opts) {
|
|
351
350
|
let subSchemaDataSize = 0;
|
|
352
351
|
if (opts.parentIsArray) {
|
|
353
|
-
const parentData =
|
|
352
|
+
const parentData = _lodashes.get.call(void 0, opts.payload, opts.parentKey || "");
|
|
354
353
|
if (parentData === void 0 || !Array.isArray(parentData)) {
|
|
355
354
|
return false;
|
|
356
355
|
}
|
|
@@ -378,17 +377,17 @@ function getTypedFormatsInSchema(format, schema, opts) {
|
|
|
378
377
|
try {
|
|
379
378
|
if (_optionalChain([schema, 'optionalAccess', _3 => _3.format]) === format) {
|
|
380
379
|
if (opts.parentIsArray) {
|
|
381
|
-
const parentData =
|
|
380
|
+
const parentData = _lodashes.get.call(void 0, opts.payload, opts.parentKey || "");
|
|
382
381
|
if (parentData !== void 0 && Array.isArray(parentData)) {
|
|
383
382
|
return Object.keys(parentData).map((pdk) => {
|
|
384
383
|
const currentKey = [opts.parentKey, pdk].join(".");
|
|
385
|
-
if (
|
|
384
|
+
if (_lodashes.get.call(void 0, opts.payload, currentKey) !== void 0) {
|
|
386
385
|
return currentKey;
|
|
387
386
|
}
|
|
388
387
|
return false;
|
|
389
388
|
}).filter(Boolean);
|
|
390
389
|
}
|
|
391
|
-
} else if (opts.parentKey &&
|
|
390
|
+
} else if (opts.parentKey && _lodashes.get.call(void 0, opts.payload, opts.parentKey) !== void 0) {
|
|
392
391
|
return opts.parentKey;
|
|
393
392
|
} else if (opts.payload !== void 0) {
|
|
394
393
|
return true;
|
|
@@ -457,7 +456,7 @@ function multipartBodyToFormatterParams(payload, oasMediaTypeObject, schema) {
|
|
|
457
456
|
const encoding = oasMediaTypeObject.encoding;
|
|
458
457
|
if (typeof payload === "object" && payload !== null) {
|
|
459
458
|
return Object.keys(payload).map((key) => {
|
|
460
|
-
if (!schema.properties[key]) {
|
|
459
|
+
if (!_optionalChain([schema, 'access', _6 => _6.properties, 'optionalAccess', _7 => _7[key]])) {
|
|
461
460
|
return false;
|
|
462
461
|
}
|
|
463
462
|
const paramEncoding = encoding ? encoding[key] : void 0;
|
|
@@ -542,8 +541,8 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
542
541
|
if (!operationSchema || typeof operationSchema.getParameters !== "function") {
|
|
543
542
|
operation = new (0, _operation.Operation)(
|
|
544
543
|
oas,
|
|
545
|
-
_optionalChain([operationSchema, 'optionalAccess',
|
|
546
|
-
_optionalChain([operationSchema, 'optionalAccess',
|
|
544
|
+
_optionalChain([operationSchema, 'optionalAccess', _8 => _8.path]) || "",
|
|
545
|
+
_optionalChain([operationSchema, 'optionalAccess', _9 => _9.method]) || "",
|
|
547
546
|
operationSchema || { path: "", method: "" }
|
|
548
547
|
);
|
|
549
548
|
} else {
|
|
@@ -552,12 +551,14 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
552
551
|
const apiDefinition = oas.getDefinition();
|
|
553
552
|
const formData = {
|
|
554
553
|
...defaultFormDataTypes,
|
|
555
|
-
server: {
|
|
556
|
-
selected: 0,
|
|
557
|
-
variables: oas.defaultVariables(0)
|
|
558
|
-
},
|
|
559
554
|
...values
|
|
560
555
|
};
|
|
556
|
+
if (!formData.server) {
|
|
557
|
+
formData.server = {
|
|
558
|
+
selected: 0,
|
|
559
|
+
variables: oas.defaultVariables(0)
|
|
560
|
+
};
|
|
561
|
+
}
|
|
561
562
|
formData.server.variables = {
|
|
562
563
|
...oas.defaultVariables(formData.server.selected),
|
|
563
564
|
...formData.server.variables ? formData.server.variables : {}
|
|
@@ -571,7 +572,10 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
571
572
|
postData: {},
|
|
572
573
|
bodySize: 0,
|
|
573
574
|
method: operation.method.toUpperCase(),
|
|
574
|
-
url: `${oas.url(formData.server.selected, formData.server.variables)}${operation.path}`.replace(
|
|
575
|
+
url: `${oas.url(formData.server.selected, formData.server.variables)}${operation.path}`.replace(
|
|
576
|
+
/\s/g,
|
|
577
|
+
"%20"
|
|
578
|
+
),
|
|
575
579
|
httpVersion: "HTTP/1.1"
|
|
576
580
|
};
|
|
577
581
|
if (opts.proxyUrl) {
|
|
@@ -605,12 +609,12 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
605
609
|
}
|
|
606
610
|
if (operation.schema.responses) {
|
|
607
611
|
Object.keys(operation.schema.responses).some((response) => {
|
|
608
|
-
if (_types.isRef.call(void 0, operation.schema.responses[response]))
|
|
612
|
+
if (_types.isRef.call(void 0, _optionalChain([operation, 'access', _10 => _10.schema, 'access', _11 => _11.responses, 'optionalAccess', _12 => _12[response]])))
|
|
609
613
|
return false;
|
|
610
|
-
const content = operation.schema.responses[response].content;
|
|
614
|
+
const content = (_optionalChain([operation, 'access', _13 => _13.schema, 'access', _14 => _14.responses, 'optionalAccess', _15 => _15[response]])).content;
|
|
611
615
|
if (!content)
|
|
612
616
|
return false;
|
|
613
|
-
if (Object.keys(formData.header).find((h) => h.toLowerCase() === "accept"))
|
|
617
|
+
if (Object.keys(formData.header || {}).find((h) => h.toLowerCase() === "accept"))
|
|
614
618
|
return true;
|
|
615
619
|
har.headers.push({
|
|
616
620
|
name: "accept",
|
|
@@ -672,17 +676,17 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
672
676
|
if (requestBody && requestBody.schema && Object.keys(requestBody.schema).length) {
|
|
673
677
|
const requestBodySchema = requestBody.schema;
|
|
674
678
|
if (operation.isFormUrlEncoded()) {
|
|
675
|
-
if (Object.keys(formData.formData).length) {
|
|
679
|
+
if (Object.keys(formData.formData || {}).length) {
|
|
676
680
|
const cleanFormData = _removeundefinedobjects2.default.call(void 0, JSON.parse(JSON.stringify(formData.formData)));
|
|
677
681
|
if (cleanFormData !== void 0) {
|
|
678
|
-
|
|
679
|
-
har.postData.mimeType = "application/x-www-form-urlencoded";
|
|
682
|
+
const postData = { params: [], mimeType: "application/x-www-form-urlencoded" };
|
|
680
683
|
Object.keys(cleanFormData).forEach((name) => {
|
|
681
|
-
|
|
684
|
+
postData.params.push({
|
|
682
685
|
name,
|
|
683
686
|
value: stringifyParameter(cleanFormData[name])
|
|
684
687
|
});
|
|
685
688
|
});
|
|
689
|
+
har.postData = postData;
|
|
686
690
|
}
|
|
687
691
|
}
|
|
688
692
|
} else if ("body" in formData && formData.body !== void 0 && (isPrimitive(formData.body) || Object.keys(formData.body).length)) {
|
|
@@ -692,8 +696,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
692
696
|
try {
|
|
693
697
|
let cleanBody = _removeundefinedobjects2.default.call(void 0, JSON.parse(JSON.stringify(formData.body)));
|
|
694
698
|
if (isMultipart) {
|
|
695
|
-
har.postData
|
|
696
|
-
har.postData.params = [];
|
|
699
|
+
har.postData = { params: [], mimeType: "multipart/form-data" };
|
|
697
700
|
const safeBodySchema = getSafeRequestBody(requestBodySchema);
|
|
698
701
|
const binaryTypes = Object.keys(safeBodySchema.properties).filter((key) => {
|
|
699
702
|
const propData = safeBodySchema.properties[key];
|
|
@@ -713,28 +716,30 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
713
716
|
if (multipartParams.length) {
|
|
714
717
|
Object.keys(cleanBody).forEach((name) => {
|
|
715
718
|
const param = multipartParams.find((multipartParam) => multipartParam.name === name);
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
value
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
719
|
+
if (param) {
|
|
720
|
+
const addtlData = {};
|
|
721
|
+
let value = formatter(formData, param, "body", true);
|
|
722
|
+
if (!Array.isArray(value)) {
|
|
723
|
+
value = [value];
|
|
724
|
+
}
|
|
725
|
+
value.forEach((val) => {
|
|
726
|
+
if (binaryTypes.includes(name)) {
|
|
727
|
+
const parsed = _dataurls.parse.call(void 0, val);
|
|
728
|
+
if (parsed) {
|
|
729
|
+
addtlData.fileName = "name" in parsed ? parsed.name : "unknown";
|
|
730
|
+
if ("contentType" in parsed) {
|
|
731
|
+
addtlData.contentType = parsed.contentType;
|
|
732
|
+
}
|
|
728
733
|
}
|
|
729
734
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
735
|
+
appendHarValue(_optionalChain([har, 'access', _16 => _16.postData, 'optionalAccess', _17 => _17.params]) || [], name, val, addtlData);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
733
738
|
});
|
|
734
739
|
}
|
|
735
740
|
}
|
|
736
741
|
} else {
|
|
737
|
-
har.postData
|
|
742
|
+
har.postData = { mimeType: contentType, text: "" };
|
|
738
743
|
if (hasSchemaType(requestBody.schema, "string") || hasSchemaType(requestBody.schema, "integer") || hasSchemaType(requestBody.schema, "number") || hasSchemaType(requestBody.schema, "boolean")) {
|
|
739
744
|
har.postData.text = JSON.stringify(JSON.parse(cleanBody));
|
|
740
745
|
} else {
|
|
@@ -743,7 +748,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
743
748
|
try {
|
|
744
749
|
jsonTypes.forEach((prop) => {
|
|
745
750
|
try {
|
|
746
|
-
|
|
751
|
+
_lodashes.set.call(void 0, cleanBody, String(prop), JSON.parse(_lodashes.get.call(void 0, cleanBody, String(prop))));
|
|
747
752
|
} catch (e) {
|
|
748
753
|
}
|
|
749
754
|
});
|
|
@@ -760,15 +765,14 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
760
765
|
}
|
|
761
766
|
}
|
|
762
767
|
} catch (e) {
|
|
763
|
-
har.postData
|
|
768
|
+
har.postData = { mimeType: contentType, text: stringify(formData.body) };
|
|
764
769
|
}
|
|
765
770
|
} else {
|
|
766
|
-
har.postData
|
|
767
|
-
har.postData.text = encodeBodyForHAR(formData.body);
|
|
771
|
+
har.postData = { mimeType: contentType, text: encodeBodyForHAR(formData.body) };
|
|
768
772
|
}
|
|
769
773
|
}
|
|
770
774
|
}
|
|
771
|
-
if ((har.postData.text || requestBody && requestBody.schema && Object.keys(requestBody.schema).length) && !hasContentType) {
|
|
775
|
+
if ((_optionalChain([har, 'access', _18 => _18.postData, 'optionalAccess', _19 => _19.text]) || requestBody && requestBody.schema && Object.keys(requestBody.schema).length) && !hasContentType) {
|
|
772
776
|
har.headers.push({
|
|
773
777
|
name: "content-type",
|
|
774
778
|
value: contentType
|
|
@@ -778,7 +782,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
778
782
|
if (securityRequirements && securityRequirements.length) {
|
|
779
783
|
securityRequirements.forEach((schemes) => {
|
|
780
784
|
Object.keys(schemes).forEach((security) => {
|
|
781
|
-
const securityValue =
|
|
785
|
+
const securityValue = _chunkQPHB6RUEcjs.configureSecurity.call(void 0, apiDefinition, auth, security);
|
|
782
786
|
if (!securityValue) {
|
|
783
787
|
return;
|
|
784
788
|
}
|
|
@@ -796,7 +800,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
796
800
|
});
|
|
797
801
|
});
|
|
798
802
|
}
|
|
799
|
-
if (Object.keys(har.postData).length === 0) {
|
|
803
|
+
if (Object.keys(har.postData || {}).length === 0) {
|
|
800
804
|
delete har.postData;
|
|
801
805
|
}
|
|
802
806
|
return {
|
|
@@ -820,4 +824,5 @@ exports.default = oasToHar;
|
|
|
820
824
|
* @link https://github.com/swagger-api/swagger-js/blob/master/src/execute/oas3/style-serializer.js
|
|
821
825
|
*/
|
|
822
826
|
|
|
823
|
-
module.exports = exports.default
|
|
827
|
+
module.exports = exports.default;
|
|
828
|
+
//# sourceMappingURL=index.cjs.map
|