@readme/oas-to-har 36.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 +35 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,6 @@ var _chunkZYPAVWY2cjs = require('./chunk-ZYPAVWY2.cjs');
|
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
var _dataurls = require('@readme/data-urls');
|
|
7
|
-
var _oas = require('oas'); var _oas2 = _interopRequireDefault(_oas);
|
|
8
7
|
var _extensions = require('oas/extensions');
|
|
9
8
|
var _operation = require('oas/operation');
|
|
10
9
|
var _types = require('oas/types');
|
|
@@ -850,14 +849,24 @@ function formatStyle(value, parameter) {
|
|
|
850
849
|
}
|
|
851
850
|
|
|
852
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
|
+
}
|
|
853
862
|
function formatter(values, param, type, onlyIfExists = false) {
|
|
854
863
|
if (param.style) {
|
|
855
|
-
const value2 = values
|
|
864
|
+
const value2 = getParamValue(values, param, type);
|
|
856
865
|
return formatStyle(value2, param);
|
|
857
866
|
}
|
|
858
867
|
let value;
|
|
859
|
-
if (typeof values
|
|
860
|
-
value = values
|
|
868
|
+
if (typeof getParamValue(values, param, type) !== "undefined") {
|
|
869
|
+
value = getParamValue(values, param, type);
|
|
861
870
|
} else if (onlyIfExists && !param.required) {
|
|
862
871
|
value = void 0;
|
|
863
872
|
} else if (param.required && param.schema && !_types.isRef.call(void 0, param.schema) && param.schema.default) {
|
|
@@ -865,7 +874,7 @@ function formatter(values, param, type, onlyIfExists = false) {
|
|
|
865
874
|
} else if (param.required && param.content) {
|
|
866
875
|
const contentType = getParameterContentType(param);
|
|
867
876
|
const schema = contentType ? getParameterContentSchema(param, contentType) : null;
|
|
868
|
-
value = _optionalChain([schema, 'optionalAccess',
|
|
877
|
+
value = _optionalChain([schema, 'optionalAccess', _10 => _10.default]);
|
|
869
878
|
} else if (type === "path") {
|
|
870
879
|
return param.name;
|
|
871
880
|
}
|
|
@@ -886,7 +895,7 @@ function multipartBodyToFormatterParams(payload, oasMediaTypeObject, schema) {
|
|
|
886
895
|
const encoding = oasMediaTypeObject.encoding;
|
|
887
896
|
if (typeof payload === "object" && payload !== null) {
|
|
888
897
|
return Object.keys(payload).map((key) => {
|
|
889
|
-
if (!_optionalChain([schema, 'access',
|
|
898
|
+
if (!_optionalChain([schema, 'access', _11 => _11.properties, 'optionalAccess', _12 => _12[key]])) {
|
|
890
899
|
return false;
|
|
891
900
|
}
|
|
892
901
|
const paramEncoding = encoding ? encoding[key] : void 0;
|
|
@@ -916,7 +925,7 @@ var defaultFormDataTypes = Object.keys(_utils.jsonSchemaTypes).reduce((prev, cur
|
|
|
916
925
|
}, {});
|
|
917
926
|
function getResponseContentType(content) {
|
|
918
927
|
const types = Object.keys(content) || [];
|
|
919
|
-
if (_optionalChain([types, 'optionalAccess',
|
|
928
|
+
if (_optionalChain([types, 'optionalAccess', _13 => _13.length])) {
|
|
920
929
|
const jsonType = types.find((t) => _utils.matchesMimeType.json(t));
|
|
921
930
|
if (jsonType) {
|
|
922
931
|
return jsonType;
|
|
@@ -981,11 +990,10 @@ function encodeBodyForHAR(body) {
|
|
|
981
990
|
function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUrl: "" }) {
|
|
982
991
|
let operation;
|
|
983
992
|
if (!operationSchema || typeof operationSchema.getParameters !== "function") {
|
|
984
|
-
const currentOas = _oas2.default.init(oas);
|
|
985
993
|
operation = new (0, _operation.Operation)(
|
|
986
|
-
|
|
987
|
-
_optionalChain([operationSchema, 'optionalAccess',
|
|
988
|
-
_optionalChain([operationSchema, 'optionalAccess',
|
|
994
|
+
oas,
|
|
995
|
+
_optionalChain([operationSchema, 'optionalAccess', _14 => _14.path]) || "",
|
|
996
|
+
_optionalChain([operationSchema, 'optionalAccess', _15 => _15.method]) || "",
|
|
989
997
|
operationSchema || { path: "", method: "" }
|
|
990
998
|
);
|
|
991
999
|
} else {
|
|
@@ -1000,11 +1008,11 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1000
1008
|
if (!formData.server) {
|
|
1001
1009
|
formData.server = {
|
|
1002
1010
|
selected: 0,
|
|
1003
|
-
variables:
|
|
1011
|
+
variables: operation.defaultVariables(0)
|
|
1004
1012
|
};
|
|
1005
1013
|
}
|
|
1006
1014
|
formData.server.variables = {
|
|
1007
|
-
...
|
|
1015
|
+
...operation.defaultVariables(formData.server.selected),
|
|
1008
1016
|
...formData.server.variables ? formData.server.variables : {}
|
|
1009
1017
|
};
|
|
1010
1018
|
const har = {
|
|
@@ -1016,7 +1024,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1016
1024
|
postData: {},
|
|
1017
1025
|
bodySize: 0,
|
|
1018
1026
|
method: operation.method.toUpperCase(),
|
|
1019
|
-
url: `${
|
|
1027
|
+
url: `${operation.url(formData.server.selected, formData.server.variables)}${operation.path}`.replace(
|
|
1020
1028
|
/\s/g,
|
|
1021
1029
|
"%20"
|
|
1022
1030
|
),
|
|
@@ -1036,15 +1044,15 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1036
1044
|
}
|
|
1037
1045
|
return formatter(formData, parameter, "path");
|
|
1038
1046
|
});
|
|
1039
|
-
const queryStrings = _optionalChain([parameters, 'optionalAccess',
|
|
1040
|
-
if (_optionalChain([queryStrings, 'optionalAccess',
|
|
1047
|
+
const queryStrings = _optionalChain([parameters, 'optionalAccess', _16 => _16.filter, 'call', _17 => _17((param) => param.in === "query")]);
|
|
1048
|
+
if (_optionalChain([queryStrings, 'optionalAccess', _18 => _18.length])) {
|
|
1041
1049
|
queryStrings.forEach((queryString) => {
|
|
1042
1050
|
const value = formatter(formData, queryString, "query", true);
|
|
1043
1051
|
appendHarValue(har.queryString, queryString.name, value);
|
|
1044
1052
|
});
|
|
1045
1053
|
}
|
|
1046
|
-
const cookies = _optionalChain([parameters, 'optionalAccess',
|
|
1047
|
-
if (_optionalChain([cookies, 'optionalAccess',
|
|
1054
|
+
const cookies = _optionalChain([parameters, 'optionalAccess', _19 => _19.filter, 'call', _20 => _20((param) => param.in === "cookie")]);
|
|
1055
|
+
if (_optionalChain([cookies, 'optionalAccess', _21 => _21.length])) {
|
|
1048
1056
|
cookies.forEach((cookie) => {
|
|
1049
1057
|
const value = formatter(formData, cookie, "cookie", true);
|
|
1050
1058
|
appendHarValue(har.cookies, cookie.name, value);
|
|
@@ -1066,8 +1074,8 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1066
1074
|
}
|
|
1067
1075
|
let hasContentType = false;
|
|
1068
1076
|
let contentType = operation.getContentType();
|
|
1069
|
-
const headers = _optionalChain([parameters, 'optionalAccess',
|
|
1070
|
-
if (_optionalChain([headers, 'optionalAccess',
|
|
1077
|
+
const headers = _optionalChain([parameters, 'optionalAccess', _22 => _22.filter, 'call', _23 => _23((param) => param.in === "header")]);
|
|
1078
|
+
if (_optionalChain([headers, 'optionalAccess', _24 => _24.length])) {
|
|
1071
1079
|
headers.forEach((header) => {
|
|
1072
1080
|
const value = formatter(formData, header, "header", true);
|
|
1073
1081
|
if (typeof value === "undefined") return;
|
|
@@ -1122,9 +1130,9 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1122
1130
|
const matchesRequestBodyType = (payload) => {
|
|
1123
1131
|
return payload.type === (isFormUrlEncoded ? "formData" : "body");
|
|
1124
1132
|
};
|
|
1125
|
-
requestBody = _optionalChain([operation, 'access',
|
|
1133
|
+
requestBody = _optionalChain([operation, 'access', _25 => _25.getParametersAsJSONSchema, 'call', _26 => _26({ contentType }), 'optionalAccess', _27 => _27.find, 'call', _28 => _28(matchesRequestBodyType)]);
|
|
1126
1134
|
}
|
|
1127
|
-
if (_optionalChain([requestBody, 'optionalAccess',
|
|
1135
|
+
if (_optionalChain([requestBody, 'optionalAccess', _29 => _29.schema]) && Object.keys(requestBody.schema).length) {
|
|
1128
1136
|
const requestBodySchema = requestBody.schema;
|
|
1129
1137
|
const isFormUrlEncoded = _utils.matchesMimeType.formUrlEncoded(contentType);
|
|
1130
1138
|
if (isFormUrlEncoded) {
|
|
@@ -1159,7 +1167,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1159
1167
|
har.postData = { params: [], mimeType: "multipart/form-data" };
|
|
1160
1168
|
const safeBodySchema = getSafeRequestBody(requestBodySchema, formData.body, operation.api);
|
|
1161
1169
|
const binaryTypes = Object.keys(_nullishCoalesce(safeBodySchema.properties, () => ( {}))).filter((key) => {
|
|
1162
|
-
if (!_optionalChain([safeBodySchema, 'access',
|
|
1170
|
+
if (!_optionalChain([safeBodySchema, 'access', _30 => _30.properties, 'optionalAccess', _31 => _31[key]]) || typeof safeBodySchema.properties[key] !== "object" || safeBodySchema.properties[key] === null) {
|
|
1163
1171
|
return false;
|
|
1164
1172
|
}
|
|
1165
1173
|
const propData = safeBodySchema.properties[key];
|
|
@@ -1199,7 +1207,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1199
1207
|
}
|
|
1200
1208
|
}
|
|
1201
1209
|
}
|
|
1202
|
-
appendHarValue(_optionalChain([har, 'access',
|
|
1210
|
+
appendHarValue(_optionalChain([har, 'access', _32 => _32.postData, 'optionalAccess', _33 => _33.params]) || [], name, val, addtlData);
|
|
1203
1211
|
});
|
|
1204
1212
|
}
|
|
1205
1213
|
});
|
|
@@ -1231,7 +1239,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1231
1239
|
} else {
|
|
1232
1240
|
try {
|
|
1233
1241
|
const parsed = parseJSONStringsInBodyWithSchema(cleanBody, requestBodySchema, operation.api);
|
|
1234
|
-
if (typeof _optionalChain([parsed, 'optionalAccess',
|
|
1242
|
+
if (typeof _optionalChain([parsed, 'optionalAccess', _34 => _34.RAW_BODY]) !== "undefined") {
|
|
1235
1243
|
har.postData.text = isPrimitive(parsed.RAW_BODY) ? String(parsed.RAW_BODY) : stringify(parsed.RAW_BODY);
|
|
1236
1244
|
} else {
|
|
1237
1245
|
har.postData.text = JSON.stringify(parsed);
|
|
@@ -1250,14 +1258,14 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1250
1258
|
}
|
|
1251
1259
|
}
|
|
1252
1260
|
}
|
|
1253
|
-
if ((_optionalChain([har, 'access',
|
|
1261
|
+
if ((_optionalChain([har, 'access', _35 => _35.postData, 'optionalAccess', _36 => _36.text]) || _optionalChain([requestBody, 'optionalAccess', _37 => _37.schema]) && Object.keys(requestBody.schema).length) && !hasContentType) {
|
|
1254
1262
|
har.headers.push({
|
|
1255
1263
|
name: "content-type",
|
|
1256
1264
|
value: contentType
|
|
1257
1265
|
});
|
|
1258
1266
|
}
|
|
1259
1267
|
const securityRequirements = operation.getSecurity();
|
|
1260
|
-
if (_optionalChain([securityRequirements, 'optionalAccess',
|
|
1268
|
+
if (_optionalChain([securityRequirements, 'optionalAccess', _38 => _38.length])) {
|
|
1261
1269
|
securityRequirements.forEach((schemes) => {
|
|
1262
1270
|
Object.keys(schemes).forEach((security) => {
|
|
1263
1271
|
const securityValue = _chunkZYPAVWY2cjs.configureSecurity.call(void 0, apiDefinition, auth, security);
|