@readme/oas-to-har 38.2.0 → 39.0.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/{chunk-567EY73K.js → chunk-6RK2UK6T.js} +9 -4
- package/dist/chunk-6RK2UK6T.js.map +1 -0
- package/dist/{chunk-ZYPAVWY2.cjs → chunk-SGNSCCC3.cjs} +9 -4
- package/dist/chunk-SGNSCCC3.cjs.map +1 -0
- package/dist/index.cjs +45 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -15
- package/dist/index.js.map +1 -1
- package/dist/lib/configure-security.cjs +2 -2
- package/dist/lib/configure-security.js +1 -1
- package/package.json +8 -7
- package/dist/chunk-567EY73K.js.map +0 -1
- package/dist/chunk-ZYPAVWY2.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
configureSecurity
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6RK2UK6T.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { parse as parseDataUrl } from "@readme/data-urls";
|
|
7
7
|
import { HEADERS, PROXY_ENABLED } from "oas/extensions";
|
|
8
8
|
import { Operation } from "oas/operation";
|
|
9
9
|
import { isRef as isRef2 } from "oas/types";
|
|
10
|
-
import { jsonSchemaTypes, matchesMimeType as matchesMimeType2 } from "oas/utils";
|
|
10
|
+
import { dereferenceRef as dereferenceRef2, jsonSchemaTypes, matchesMimeType as matchesMimeType2 } from "oas/utils";
|
|
11
11
|
import removeUndefinedObjects from "remove-undefined-objects";
|
|
12
12
|
|
|
13
13
|
// src/lib/lodash.ts
|
|
@@ -209,13 +209,17 @@ function getParameterContentType(param) {
|
|
|
209
209
|
}
|
|
210
210
|
return getParameterContentTypeUtil(contentKeys) || null;
|
|
211
211
|
}
|
|
212
|
-
function getParameterContentSchema(param, contentType) {
|
|
212
|
+
function getParameterContentSchema(param, contentType, api) {
|
|
213
213
|
if (!("content" in param) || typeof param.content !== "object" || !param.content) {
|
|
214
214
|
return null;
|
|
215
215
|
}
|
|
216
216
|
const mediaTypeObject = param.content[contentType];
|
|
217
217
|
if (typeof mediaTypeObject === "object" && mediaTypeObject && "schema" in mediaTypeObject && mediaTypeObject.schema) {
|
|
218
|
-
|
|
218
|
+
const schema = isRef(mediaTypeObject.schema) ? dereferenceRef(mediaTypeObject.schema, api) : mediaTypeObject.schema;
|
|
219
|
+
if (!schema || isRef(schema)) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return schema;
|
|
219
223
|
}
|
|
220
224
|
return null;
|
|
221
225
|
}
|
|
@@ -859,7 +863,7 @@ function getParamValue(values, param, type) {
|
|
|
859
863
|
}
|
|
860
864
|
return bucket?.[param.name];
|
|
861
865
|
}
|
|
862
|
-
function formatter(values, param, type, onlyIfExists = false) {
|
|
866
|
+
function formatter(values, param, type, onlyIfExists = false, api) {
|
|
863
867
|
if (param.style) {
|
|
864
868
|
const value2 = getParamValue(values, param, type);
|
|
865
869
|
return formatStyle(value2, param);
|
|
@@ -869,13 +873,21 @@ function formatter(values, param, type, onlyIfExists = false) {
|
|
|
869
873
|
value = getParamValue(values, param, type);
|
|
870
874
|
} else if (onlyIfExists && !param.required) {
|
|
871
875
|
value = void 0;
|
|
872
|
-
} else if (param.required && param.schema
|
|
873
|
-
|
|
876
|
+
} else if (param.required && param.schema) {
|
|
877
|
+
const schema = isRef2(param.schema) ? dereferenceRef2(param.schema, api) : param.schema;
|
|
878
|
+
if (schema && !isRef2(schema) && schema.default) {
|
|
879
|
+
value = schema.default;
|
|
880
|
+
} else if (param.content) {
|
|
881
|
+
const contentType = getParameterContentType(param);
|
|
882
|
+
const contentSchema = contentType ? getParameterContentSchema(param, contentType, api) : null;
|
|
883
|
+
value = contentSchema?.default;
|
|
884
|
+
}
|
|
874
885
|
} else if (param.required && param.content) {
|
|
875
886
|
const contentType = getParameterContentType(param);
|
|
876
|
-
const schema = contentType ? getParameterContentSchema(param, contentType) : null;
|
|
887
|
+
const schema = contentType ? getParameterContentSchema(param, contentType, api) : null;
|
|
877
888
|
value = schema?.default;
|
|
878
|
-
}
|
|
889
|
+
}
|
|
890
|
+
if (value === void 0 && type === "path") {
|
|
879
891
|
return param.name;
|
|
880
892
|
}
|
|
881
893
|
if (param.schema && !isRef2(param.schema) && param.schema.type === "array" && param.schema.items && !isRef2(param.schema.items) && param.schema.items.format === "binary") {
|
|
@@ -1040,21 +1052,21 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1040
1052
|
if (!operation || !parameters) return key;
|
|
1041
1053
|
const parameter = parameters.find((param) => param.name === key) || { name: key };
|
|
1042
1054
|
if (!("style" in parameter) || !parameter.style) {
|
|
1043
|
-
return encodeURIComponent(formatter(formData, parameter, "path"));
|
|
1055
|
+
return encodeURIComponent(formatter(formData, parameter, "path", false, oas.api));
|
|
1044
1056
|
}
|
|
1045
|
-
return formatter(formData, parameter, "path");
|
|
1057
|
+
return formatter(formData, parameter, "path", false, oas.api);
|
|
1046
1058
|
});
|
|
1047
1059
|
const queryStrings = parameters?.filter((param) => param.in === "query");
|
|
1048
1060
|
if (queryStrings?.length) {
|
|
1049
1061
|
queryStrings.forEach((queryString) => {
|
|
1050
|
-
const value = formatter(formData, queryString, "query", true);
|
|
1062
|
+
const value = formatter(formData, queryString, "query", true, oas.api);
|
|
1051
1063
|
appendHarValue(har.queryString, queryString.name, value);
|
|
1052
1064
|
});
|
|
1053
1065
|
}
|
|
1054
1066
|
const cookies = parameters?.filter((param) => param.in === "cookie");
|
|
1055
1067
|
if (cookies?.length) {
|
|
1056
1068
|
cookies.forEach((cookie) => {
|
|
1057
|
-
const value = formatter(formData, cookie, "cookie", true);
|
|
1069
|
+
const value = formatter(formData, cookie, "cookie", true, oas.api);
|
|
1058
1070
|
appendHarValue(har.cookies, cookie.name, value);
|
|
1059
1071
|
});
|
|
1060
1072
|
}
|
|
@@ -1077,7 +1089,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1077
1089
|
const headers = parameters?.filter((param) => param.in === "header");
|
|
1078
1090
|
if (headers?.length) {
|
|
1079
1091
|
headers.forEach((header) => {
|
|
1080
|
-
const value = formatter(formData, header, "header", true);
|
|
1092
|
+
const value = formatter(formData, header, "header", true, oas.api);
|
|
1081
1093
|
if (typeof value === "undefined") return;
|
|
1082
1094
|
if (header.name.toLowerCase() === "content-type") {
|
|
1083
1095
|
hasContentType = true;
|
|
@@ -1193,7 +1205,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUr
|
|
|
1193
1205
|
const param = multipartParams.find((multipartParam) => multipartParam.name === name);
|
|
1194
1206
|
if (param) {
|
|
1195
1207
|
const addtlData = {};
|
|
1196
|
-
let value = formatter(formData, param, "body", true);
|
|
1208
|
+
let value = formatter(formData, param, "body", true, oas.api);
|
|
1197
1209
|
if (!Array.isArray(value)) {
|
|
1198
1210
|
value = [value];
|
|
1199
1211
|
}
|