@readme/oas-to-har 37.0.0 → 37.2.0

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/index.cjs CHANGED
@@ -849,14 +849,24 @@ function formatStyle(value, parameter) {
849
849
  }
850
850
 
851
851
  // src/index.ts
852
+ function getParamValue(values, param, type) {
853
+ const bucket = values[type];
854
+ if (bucket && typeof bucket === "object" && !(param.name in bucket) && type === "header") {
855
+ const matchedKey = Object.keys(bucket).find((key) => key.toLowerCase() === param.name.toLowerCase());
856
+ if (matchedKey !== void 0) {
857
+ return bucket[matchedKey];
858
+ }
859
+ }
860
+ return _optionalChain([bucket, 'optionalAccess', _9 => _9[param.name]]);
861
+ }
852
862
  function formatter(values, param, type, onlyIfExists = false) {
853
863
  if (param.style) {
854
- const value2 = values[type][param.name];
864
+ const value2 = getParamValue(values, param, type);
855
865
  return formatStyle(value2, param);
856
866
  }
857
867
  let value;
858
- if (typeof values[type][param.name] !== "undefined") {
859
- value = values[type][param.name];
868
+ if (typeof getParamValue(values, param, type) !== "undefined") {
869
+ value = getParamValue(values, param, type);
860
870
  } else if (onlyIfExists && !param.required) {
861
871
  value = void 0;
862
872
  } else if (param.required && param.schema && !_types.isRef.call(void 0, param.schema) && param.schema.default) {
@@ -864,7 +874,7 @@ function formatter(values, param, type, onlyIfExists = false) {
864
874
  } else if (param.required && param.content) {
865
875
  const contentType = getParameterContentType(param);
866
876
  const schema = contentType ? getParameterContentSchema(param, contentType) : null;
867
- value = _optionalChain([schema, 'optionalAccess', _9 => _9.default]);
877
+ value = _optionalChain([schema, 'optionalAccess', _10 => _10.default]);
868
878
  } else if (type === "path") {
869
879
  return param.name;
870
880
  }
@@ -885,7 +895,7 @@ function multipartBodyToFormatterParams(payload, oasMediaTypeObject, schema) {
885
895
  const encoding = oasMediaTypeObject.encoding;
886
896
  if (typeof payload === "object" && payload !== null) {
887
897
  return Object.keys(payload).map((key) => {
888
- if (!_optionalChain([schema, 'access', _10 => _10.properties, 'optionalAccess', _11 => _11[key]])) {
898
+ if (!_optionalChain([schema, 'access', _11 => _11.properties, 'optionalAccess', _12 => _12[key]])) {
889
899
  return false;
890
900
  }
891
901
  const paramEncoding = encoding ? encoding[key] : void 0;
@@ -915,7 +925,7 @@ var defaultFormDataTypes = Object.keys(_utils.jsonSchemaTypes).reduce((prev, cur
915
925
  }, {});
916
926
  function getResponseContentType(content) {
917
927
  const types = Object.keys(content) || [];
918
- if (_optionalChain([types, 'optionalAccess', _12 => _12.length])) {
928
+ if (_optionalChain([types, 'optionalAccess', _13 => _13.length])) {
919
929
  const jsonType = types.find((t) => _utils.matchesMimeType.json(t));
920
930
  if (jsonType) {
921
931
  return jsonType;
@@ -982,8 +992,8 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
982
992
  if (!operationSchema || typeof operationSchema.getParameters !== "function") {
983
993
  operation = new (0, _operation.Operation)(
984
994
  oas,
985
- _optionalChain([operationSchema, 'optionalAccess', _13 => _13.path]) || "",
986
- _optionalChain([operationSchema, 'optionalAccess', _14 => _14.method]) || "",
995
+ _optionalChain([operationSchema, 'optionalAccess', _14 => _14.path]) || "",
996
+ _optionalChain([operationSchema, 'optionalAccess', _15 => _15.method]) || "",
987
997
  operationSchema || { path: "", method: "" }
988
998
  );
989
999
  } else {
@@ -1034,15 +1044,15 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
1034
1044
  }
1035
1045
  return formatter(formData, parameter, "path");
1036
1046
  });
1037
- const queryStrings = _optionalChain([parameters, 'optionalAccess', _15 => _15.filter, 'call', _16 => _16((param) => param.in === "query")]);
1038
- if (_optionalChain([queryStrings, 'optionalAccess', _17 => _17.length])) {
1047
+ const queryStrings = _optionalChain([parameters, 'optionalAccess', _16 => _16.filter, 'call', _17 => _17((param) => param.in === "query")]);
1048
+ if (_optionalChain([queryStrings, 'optionalAccess', _18 => _18.length])) {
1039
1049
  queryStrings.forEach((queryString) => {
1040
1050
  const value = formatter(formData, queryString, "query", true);
1041
1051
  appendHarValue(har.queryString, queryString.name, value);
1042
1052
  });
1043
1053
  }
1044
- const cookies = _optionalChain([parameters, 'optionalAccess', _18 => _18.filter, 'call', _19 => _19((param) => param.in === "cookie")]);
1045
- if (_optionalChain([cookies, 'optionalAccess', _20 => _20.length])) {
1054
+ const cookies = _optionalChain([parameters, 'optionalAccess', _19 => _19.filter, 'call', _20 => _20((param) => param.in === "cookie")]);
1055
+ if (_optionalChain([cookies, 'optionalAccess', _21 => _21.length])) {
1046
1056
  cookies.forEach((cookie) => {
1047
1057
  const value = formatter(formData, cookie, "cookie", true);
1048
1058
  appendHarValue(har.cookies, cookie.name, value);
@@ -1064,8 +1074,8 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
1064
1074
  }
1065
1075
  let hasContentType = false;
1066
1076
  let contentType = operation.getContentType();
1067
- const headers = _optionalChain([parameters, 'optionalAccess', _21 => _21.filter, 'call', _22 => _22((param) => param.in === "header")]);
1068
- if (_optionalChain([headers, 'optionalAccess', _23 => _23.length])) {
1077
+ const headers = _optionalChain([parameters, 'optionalAccess', _22 => _22.filter, 'call', _23 => _23((param) => param.in === "header")]);
1078
+ if (_optionalChain([headers, 'optionalAccess', _24 => _24.length])) {
1069
1079
  headers.forEach((header) => {
1070
1080
  const value = formatter(formData, header, "header", true);
1071
1081
  if (typeof value === "undefined") return;
@@ -1120,9 +1130,9 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
1120
1130
  const matchesRequestBodyType = (payload) => {
1121
1131
  return payload.type === (isFormUrlEncoded ? "formData" : "body");
1122
1132
  };
1123
- requestBody = _optionalChain([operation, 'access', _24 => _24.getParametersAsJSONSchema, 'call', _25 => _25({ contentType }), 'optionalAccess', _26 => _26.find, 'call', _27 => _27(matchesRequestBodyType)]);
1133
+ requestBody = _optionalChain([operation, 'access', _25 => _25.getParametersAsJSONSchema, 'call', _26 => _26({ contentType }), 'optionalAccess', _27 => _27.find, 'call', _28 => _28(matchesRequestBodyType)]);
1124
1134
  }
1125
- if (_optionalChain([requestBody, 'optionalAccess', _28 => _28.schema]) && Object.keys(requestBody.schema).length) {
1135
+ if (_optionalChain([requestBody, 'optionalAccess', _29 => _29.schema]) && Object.keys(requestBody.schema).length) {
1126
1136
  const requestBodySchema = requestBody.schema;
1127
1137
  const isFormUrlEncoded = _utils.matchesMimeType.formUrlEncoded(contentType);
1128
1138
  if (isFormUrlEncoded) {
@@ -1157,7 +1167,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
1157
1167
  har.postData = { params: [], mimeType: "multipart/form-data" };
1158
1168
  const safeBodySchema = getSafeRequestBody(requestBodySchema, formData.body, operation.api);
1159
1169
  const binaryTypes = Object.keys(_nullishCoalesce(safeBodySchema.properties, () => ( {}))).filter((key) => {
1160
- if (!_optionalChain([safeBodySchema, 'access', _29 => _29.properties, 'optionalAccess', _30 => _30[key]]) || typeof safeBodySchema.properties[key] !== "object" || safeBodySchema.properties[key] === null) {
1170
+ if (!_optionalChain([safeBodySchema, 'access', _30 => _30.properties, 'optionalAccess', _31 => _31[key]]) || typeof safeBodySchema.properties[key] !== "object" || safeBodySchema.properties[key] === null) {
1161
1171
  return false;
1162
1172
  }
1163
1173
  const propData = safeBodySchema.properties[key];
@@ -1197,7 +1207,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
1197
1207
  }
1198
1208
  }
1199
1209
  }
1200
- appendHarValue(_optionalChain([har, 'access', _31 => _31.postData, 'optionalAccess', _32 => _32.params]) || [], name, val, addtlData);
1210
+ appendHarValue(_optionalChain([har, 'access', _32 => _32.postData, 'optionalAccess', _33 => _33.params]) || [], name, val, addtlData);
1201
1211
  });
1202
1212
  }
1203
1213
  });
@@ -1229,7 +1239,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
1229
1239
  } else {
1230
1240
  try {
1231
1241
  const parsed = parseJSONStringsInBodyWithSchema(cleanBody, requestBodySchema, operation.api);
1232
- if (typeof _optionalChain([parsed, 'optionalAccess', _33 => _33.RAW_BODY]) !== "undefined") {
1242
+ if (typeof _optionalChain([parsed, 'optionalAccess', _34 => _34.RAW_BODY]) !== "undefined") {
1233
1243
  har.postData.text = isPrimitive(parsed.RAW_BODY) ? String(parsed.RAW_BODY) : stringify(parsed.RAW_BODY);
1234
1244
  } else {
1235
1245
  har.postData.text = JSON.stringify(parsed);
@@ -1248,14 +1258,14 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
1248
1258
  }
1249
1259
  }
1250
1260
  }
1251
- if ((_optionalChain([har, 'access', _34 => _34.postData, 'optionalAccess', _35 => _35.text]) || _optionalChain([requestBody, 'optionalAccess', _36 => _36.schema]) && Object.keys(requestBody.schema).length) && !hasContentType) {
1261
+ if ((_optionalChain([har, 'access', _35 => _35.postData, 'optionalAccess', _36 => _36.text]) || _optionalChain([requestBody, 'optionalAccess', _37 => _37.schema]) && Object.keys(requestBody.schema).length) && !hasContentType) {
1252
1262
  har.headers.push({
1253
1263
  name: "content-type",
1254
1264
  value: contentType
1255
1265
  });
1256
1266
  }
1257
1267
  const securityRequirements = operation.getSecurity();
1258
- if (_optionalChain([securityRequirements, 'optionalAccess', _37 => _37.length])) {
1268
+ if (_optionalChain([securityRequirements, 'optionalAccess', _38 => _38.length])) {
1259
1269
  securityRequirements.forEach((schemes) => {
1260
1270
  Object.keys(schemes).forEach((security) => {
1261
1271
  const securityValue = _chunkZYPAVWY2cjs.configureSecurity.call(void 0, apiDefinition, auth, security);