@readme/oas-to-har 23.2.27 → 24.0.1
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-QPHB6RUE.cjs → chunk-E4ELBEQK.cjs} +7 -13
- package/dist/chunk-E4ELBEQK.cjs.map +1 -0
- package/dist/{chunk-B6VBOO2O.js → chunk-IYAKHQZB.js} +7 -13
- package/dist/{chunk-B6VBOO2O.js.map → chunk-IYAKHQZB.js.map} +1 -1
- package/dist/index.cjs +101 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +100 -21
- package/dist/index.js.map +1 -1
- package/dist/lib/configure-security.cjs +2 -2
- package/dist/lib/configure-security.cjs.map +1 -1
- package/dist/lib/configure-security.js +1 -1
- package/dist/lib/types.cjs.map +1 -1
- package/dist/lib/types.d.cts +7 -1
- package/dist/lib/types.d.ts +7 -1
- package/dist/lib/types.js.map +1 -1
- package/package.json +5 -6
- package/dist/chunk-QPHB6RUE.cjs.map +0 -1
|
@@ -1,17 +1,13 @@
|
|
|
1
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
|
-
if (!value.value)
|
|
5
|
-
return void 0;
|
|
4
|
+
if (!value.value) return void 0;
|
|
6
5
|
return { type, value };
|
|
7
6
|
}
|
|
8
7
|
function configureSecurity(apiDefinition, values, scheme) {
|
|
9
|
-
if (!scheme)
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
return void 0;
|
|
13
|
-
if (!_optionalChain([apiDefinition, 'access', _ => _.components, 'optionalAccess', _2 => _2.securitySchemes, 'optionalAccess', _3 => _3[scheme]]))
|
|
14
|
-
return void 0;
|
|
8
|
+
if (!scheme) return void 0;
|
|
9
|
+
if (Object.keys(values || {}).length === 0) return void 0;
|
|
10
|
+
if (!_optionalChain([apiDefinition, 'access', _ => _.components, 'optionalAccess', _2 => _2.securitySchemes, 'optionalAccess', _3 => _3[scheme]])) return void 0;
|
|
15
11
|
const security = apiDefinition.components.securitySchemes[scheme];
|
|
16
12
|
if (_types.isRef.call(void 0, security)) {
|
|
17
13
|
return void 0;
|
|
@@ -21,10 +17,8 @@ function configureSecurity(apiDefinition, values, scheme) {
|
|
|
21
17
|
if (security.type === "http") {
|
|
22
18
|
if (security.scheme === "basic") {
|
|
23
19
|
const auth = values[scheme];
|
|
24
|
-
if (typeof auth !== "object")
|
|
25
|
-
|
|
26
|
-
if (!auth.user && !auth.pass)
|
|
27
|
-
return false;
|
|
20
|
+
if (typeof auth !== "object") return false;
|
|
21
|
+
if (!auth.user && !auth.pass) return false;
|
|
28
22
|
let user = _nullishCoalesce(auth.user, () => ( null));
|
|
29
23
|
if (user === null || user.length === 0) {
|
|
30
24
|
user = "";
|
|
@@ -80,4 +74,4 @@ function configureSecurity(apiDefinition, values, scheme) {
|
|
|
80
74
|
|
|
81
75
|
|
|
82
76
|
exports.configureSecurity = configureSecurity;
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
77
|
+
//# sourceMappingURL=chunk-E4ELBEQK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kanadg/Code/readmeio/oas/packages/oas-to-har/dist/chunk-E4ELBEQK.cjs","../src/lib/configure-security.ts"],"names":[],"mappings":"AAAA;ACGA,kCAAsB;AAEtB,SAAS,QAAA,CAAS,IAAA,EA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AQ,IAAA,CAAK,OAAA,IAAW,CAAA,EAAG;AACtC,QAAA,KAAA,EAAO,EAAA;AAAA,MACT;AAEA,MAAA,IAAI,KAAA,mBAAO,IAAA,CAAK,IAAA,UAAQ,MAAA;AACxB,MAAA,GAAA,CAAI,KAAA,IAAS,KAAA,GAAQ,IAAA,CAAK,OAAA,IAAW,CAAA,EAAG;AACtC,QAAA,KAAA,EAAO,EAAA;AAAA,MACT;AAEA,MAAA,OAAO,QAAA,CAAS,SAAA,EAAW;AAAA,QACzB,IAAA,EAAM,eAAA;AAAA,QACN,KAAA,EAAO,CAAA,MAAA,EAAS,MAAA,CAAO,IAAA,CAAK,CAAA,EAAA;AAC7B,MAAA;AAC4B,IAAA;AACF,MAAA;AACnB,QAAA;AACkB,QAAA;AACzB,MAAA;AACH,IAAA;AACF,EAAA;AAEgC,EAAA;AACD,IAAA;AACI,MAAA;AACd,QAAA;AACa,QAAA;AAC7B,MAAA;AACwB,IAAA;AACV,MAAA;AACE,QAAA;AACa,QAAA;AAC9B,MAAA;AAE8B,MAAA;AAEP,QAAA;AACE,QAAA;AACL,QAAA;AACpB,MAAA;AAE2B,MAAA;AACF,IAAA;AACE,MAAA;AACV,QAAA;AACa,QAAA;AAC7B,MAAA;AACH,IAAA;AACF,EAAA;AAEgC,EAAA;AACH,IAAA;AACnB,MAAA;AACyB,MAAA;AAChC,IAAA;AACH,EAAA;AAEO,EAAA;AACT;ADnBqC;AACA;AACA;AACA","file":"/Users/kanadg/Code/readmeio/oas/packages/oas-to-har/dist/chunk-E4ELBEQK.cjs","sourcesContent":[null,"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"]}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
// src/lib/configure-security.ts
|
|
2
2
|
import { isRef } from "oas/types";
|
|
3
3
|
function harValue(type, value) {
|
|
4
|
-
if (!value.value)
|
|
5
|
-
return void 0;
|
|
4
|
+
if (!value.value) return void 0;
|
|
6
5
|
return { type, value };
|
|
7
6
|
}
|
|
8
7
|
function configureSecurity(apiDefinition, values, scheme) {
|
|
9
|
-
if (!scheme)
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
return void 0;
|
|
13
|
-
if (!apiDefinition.components?.securitySchemes?.[scheme])
|
|
14
|
-
return void 0;
|
|
8
|
+
if (!scheme) return void 0;
|
|
9
|
+
if (Object.keys(values || {}).length === 0) return void 0;
|
|
10
|
+
if (!apiDefinition.components?.securitySchemes?.[scheme]) return void 0;
|
|
15
11
|
const security = apiDefinition.components.securitySchemes[scheme];
|
|
16
12
|
if (isRef(security)) {
|
|
17
13
|
return void 0;
|
|
@@ -21,10 +17,8 @@ function configureSecurity(apiDefinition, values, scheme) {
|
|
|
21
17
|
if (security.type === "http") {
|
|
22
18
|
if (security.scheme === "basic") {
|
|
23
19
|
const auth = values[scheme];
|
|
24
|
-
if (typeof auth !== "object")
|
|
25
|
-
|
|
26
|
-
if (!auth.user && !auth.pass)
|
|
27
|
-
return false;
|
|
20
|
+
if (typeof auth !== "object") return false;
|
|
21
|
+
if (!auth.user && !auth.pass) return false;
|
|
28
22
|
let user = auth.user ?? null;
|
|
29
23
|
if (user === null || user.length === 0) {
|
|
30
24
|
user = "";
|
|
@@ -80,4 +74,4 @@ function configureSecurity(apiDefinition, values, scheme) {
|
|
|
80
74
|
export {
|
|
81
75
|
configureSecurity
|
|
82
76
|
};
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
77
|
+
//# sourceMappingURL=chunk-IYAKHQZB.js.map
|
|
@@ -1 +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;AAEtB,SAAS,SAAS,MAA6C,OAAwC;AACrG,MAAI,CAAC,MAAM
|
|
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: `Bear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SAAS,UAAU;AAC9B,QAAI,SAAS,OAAO,SAAS;AAC3B,aAAO,SAAS,eAAe;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":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 _chunkE4ELBEQKcjs = require('./chunk-E4ELBEQK.cjs');
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
var _dataurls = require('@readme/data-urls');
|
|
@@ -12,8 +12,7 @@ var _removeundefinedobjects = require('remove-undefined-objects'); var _removeun
|
|
|
12
12
|
|
|
13
13
|
// src/lib/lodash.ts
|
|
14
14
|
function get(object, path) {
|
|
15
|
-
if (!path)
|
|
16
|
-
return void 0;
|
|
15
|
+
if (!path) return void 0;
|
|
17
16
|
const pathArray = String(path).match(/([^[.\]])+/g);
|
|
18
17
|
const result = _optionalChain([pathArray, 'optionalAccess', _ => _.reduce, 'call', _2 => _2((prevObj, key) => prevObj && prevObj[key], object)]);
|
|
19
18
|
return result;
|
|
@@ -106,10 +105,25 @@ function encodeArray({
|
|
|
106
105
|
isAllowedReserved
|
|
107
106
|
});
|
|
108
107
|
switch (style) {
|
|
108
|
+
/**
|
|
109
|
+
* @example <caption>`style: simple`</caption>
|
|
110
|
+
* `["blue","black","brown"]` → `blue,black,brown`
|
|
111
|
+
*/
|
|
109
112
|
case "simple":
|
|
110
113
|
return value.map((val) => valueEncoder(val)).join(",");
|
|
114
|
+
/**
|
|
115
|
+
* @example <caption>`style: label`</caption>
|
|
116
|
+
* `["blue","black","brown"]` → `.blue.black.brown`
|
|
117
|
+
*/
|
|
111
118
|
case "label":
|
|
112
119
|
return `.${value.map((val) => valueEncoder(val)).join(".")}`;
|
|
120
|
+
/**
|
|
121
|
+
* @example <caption>`style: matrix` + `explode: true`</caption>
|
|
122
|
+
* `["blue","black","brown"]` → `;color=blue;color=black;color=brown`
|
|
123
|
+
*
|
|
124
|
+
* @example <caption>`style: matrix` + `explode: false` (the default behavior)</caption>
|
|
125
|
+
* `["blue","black","brown"]` → `;color=blue,black,brown `
|
|
126
|
+
*/
|
|
113
127
|
case "matrix":
|
|
114
128
|
return value.map((val) => valueEncoder(val)).reduce((prev, curr) => {
|
|
115
129
|
if (!prev || explode) {
|
|
@@ -117,10 +131,25 @@ function encodeArray({
|
|
|
117
131
|
}
|
|
118
132
|
return `${prev},${curr}`;
|
|
119
133
|
}, "");
|
|
134
|
+
/**
|
|
135
|
+
* @example <caption>`style: form` + `explode: true`</caption>
|
|
136
|
+
* `["blue","black","brown"]` → `color=blue&color=black&color=brown`
|
|
137
|
+
*
|
|
138
|
+
* @example <caption>`style: form` + `explode: false` (the default behavior)</caption>
|
|
139
|
+
* `["blue","black","brown"]` → `color=blue,black,brown`
|
|
140
|
+
*/
|
|
120
141
|
case "form":
|
|
121
142
|
return value.map((val) => valueEncoder(val)).join(explode ? `&${key}=` : ",");
|
|
143
|
+
/**
|
|
144
|
+
* @example <caption>`style: spaceDelimited`</caption>
|
|
145
|
+
* `["blue","black","brown"]` → `blue%20black%20brown`
|
|
146
|
+
*/
|
|
122
147
|
case "spaceDelimited":
|
|
123
148
|
return value.map((val) => valueEncoder(val)).join(` ${explode ? `${key}=` : ""}`);
|
|
149
|
+
/**
|
|
150
|
+
* @example <caption>`style: pipeDelimited`</caption>
|
|
151
|
+
* `["blue","black","brown"]` → `blue|black|brown`
|
|
152
|
+
*/
|
|
124
153
|
case "pipeDelimited":
|
|
125
154
|
return value.map((val) => valueEncoder(val)).join(`|${explode ? `${key}=` : ""}`);
|
|
126
155
|
default:
|
|
@@ -135,6 +164,13 @@ function encodeObject({ location, key, value, style, explode, escape, isAllowedR
|
|
|
135
164
|
});
|
|
136
165
|
const valueKeys = Object.keys(value);
|
|
137
166
|
switch (style) {
|
|
167
|
+
/**
|
|
168
|
+
* @example <caption>`style: simple` + `explode: true`</caption>
|
|
169
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `R=100,G=200,B=150`
|
|
170
|
+
*
|
|
171
|
+
* @example <caption>`style: simple` + `explode: false` (the default behavior)</caption>
|
|
172
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `R,100,G,200,B,150`
|
|
173
|
+
*/
|
|
138
174
|
case "simple":
|
|
139
175
|
return valueKeys.reduce((prev, curr) => {
|
|
140
176
|
const val = valueEncoder(value[curr]);
|
|
@@ -142,6 +178,13 @@ function encodeObject({ location, key, value, style, explode, escape, isAllowedR
|
|
|
142
178
|
const prefix = prev ? `${prev},` : "";
|
|
143
179
|
return `${prefix}${curr}${middleChar}${val}`;
|
|
144
180
|
}, "");
|
|
181
|
+
/**
|
|
182
|
+
* @example <caption>`style: label` + `explode: true`</caption>
|
|
183
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `.R=100.G=200.B=150`
|
|
184
|
+
*
|
|
185
|
+
* @example <caption>`style: label` + `explode: false` (the default behavior)</caption>
|
|
186
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `.R.100.G.200.B.150`
|
|
187
|
+
*/
|
|
145
188
|
case "label":
|
|
146
189
|
return valueKeys.reduce((prev, curr) => {
|
|
147
190
|
const val = valueEncoder(value[curr]);
|
|
@@ -149,6 +192,13 @@ function encodeObject({ location, key, value, style, explode, escape, isAllowedR
|
|
|
149
192
|
const prefix = prev ? `${prev}.` : ".";
|
|
150
193
|
return `${prefix}${curr}${middleChar}${val}`;
|
|
151
194
|
}, "");
|
|
195
|
+
/**
|
|
196
|
+
* @example <caption>`style: matrix` + `explode: true`</caption>
|
|
197
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `;R=100;G=200;B=150`
|
|
198
|
+
*
|
|
199
|
+
* @example <caption>`style: matrix` + `explode: false` (the default behavior)</caption>
|
|
200
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `;color=R,100,G,200,B,150`
|
|
201
|
+
*/
|
|
152
202
|
case "matrix":
|
|
153
203
|
if (explode) {
|
|
154
204
|
return valueKeys.reduce((prev, curr) => {
|
|
@@ -162,6 +212,13 @@ function encodeObject({ location, key, value, style, explode, escape, isAllowedR
|
|
|
162
212
|
const prefix = prev ? `${prev},` : `;${key}=`;
|
|
163
213
|
return `${prefix}${curr},${val}`;
|
|
164
214
|
}, "");
|
|
215
|
+
/**
|
|
216
|
+
* @example <caption>`style: form` + `explode: true`</caption>
|
|
217
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `R=100&G=200&B=150`
|
|
218
|
+
*
|
|
219
|
+
* @example <caption>`style: form` + `explode: false` (the default behavior)</caption>
|
|
220
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `color=R,100,G,200,B,150`
|
|
221
|
+
*/
|
|
165
222
|
case "form":
|
|
166
223
|
return valueKeys.reduce((prev, curr) => {
|
|
167
224
|
const val = valueEncoder(value[curr]);
|
|
@@ -169,18 +226,30 @@ function encodeObject({ location, key, value, style, explode, escape, isAllowedR
|
|
|
169
226
|
const separator = explode ? "=" : ",";
|
|
170
227
|
return `${prefix}${curr}${separator}${val}`;
|
|
171
228
|
}, "");
|
|
229
|
+
/**
|
|
230
|
+
* @example <caption>`style: spaceDelimited`</caption>
|
|
231
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `R%20100%20G%20200%20B%20150`
|
|
232
|
+
*/
|
|
172
233
|
case "spaceDelimited":
|
|
173
234
|
return valueKeys.reduce((prev, curr) => {
|
|
174
235
|
const val = valueEncoder(value[curr]);
|
|
175
236
|
const prefix = prev ? `${prev} ` : "";
|
|
176
237
|
return `${prefix}${curr} ${val}`;
|
|
177
238
|
}, "");
|
|
239
|
+
/**
|
|
240
|
+
* @example <caption>`style: pipeDelimited`</caption>
|
|
241
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `R|100|G|200|B|150`
|
|
242
|
+
*/
|
|
178
243
|
case "pipeDelimited":
|
|
179
244
|
return valueKeys.reduce((prev, curr) => {
|
|
180
245
|
const val = valueEncoder(value[curr]);
|
|
181
246
|
const prefix = prev ? `${prev}|` : "";
|
|
182
247
|
return `${prefix}${curr}|${val}`;
|
|
183
248
|
}, "");
|
|
249
|
+
/**
|
|
250
|
+
* @example <caption>`style: deepObject`</caption>
|
|
251
|
+
* `{ "R": 100, "G": 200, "B": 150 }` → `color[R]=100&color[G]=200&color[B]=150`
|
|
252
|
+
*/
|
|
184
253
|
case "deepObject":
|
|
185
254
|
return valueKeys.reduce((curr) => {
|
|
186
255
|
const val = valueEncoder(value[curr]);
|
|
@@ -197,17 +266,37 @@ function encodePrimitive({ location, key, value, style, escape, isAllowedReserve
|
|
|
197
266
|
isAllowedReserved
|
|
198
267
|
});
|
|
199
268
|
switch (style) {
|
|
269
|
+
/**
|
|
270
|
+
* @example <caption>`style: simple`</caption>
|
|
271
|
+
* `blue` → `blue`
|
|
272
|
+
*/
|
|
200
273
|
case "simple":
|
|
201
274
|
return valueEncoder(value);
|
|
275
|
+
/**
|
|
276
|
+
* @example <caption>`style: label`</caption>
|
|
277
|
+
* `blue` → `.blue`
|
|
278
|
+
*/
|
|
202
279
|
case "label":
|
|
203
280
|
return `.${valueEncoder(value)}`;
|
|
281
|
+
/**
|
|
282
|
+
* @example <caption>`style: matrix`</caption>
|
|
283
|
+
* `blue` → `;color=blue`
|
|
284
|
+
*/
|
|
204
285
|
case "matrix":
|
|
205
286
|
if (value === "") {
|
|
206
287
|
return `;${key}`;
|
|
207
288
|
}
|
|
208
289
|
return `;${key}=${valueEncoder(value)}`;
|
|
290
|
+
/**
|
|
291
|
+
* @example <caption>`style: form`</caption>
|
|
292
|
+
* `blue` → `color=blue`
|
|
293
|
+
*/
|
|
209
294
|
case "form":
|
|
210
295
|
return valueEncoder(value);
|
|
296
|
+
/**
|
|
297
|
+
* @example <caption>`style: deepObject`</caption>
|
|
298
|
+
* `blue` → n/a
|
|
299
|
+
*/
|
|
211
300
|
case "deepObject":
|
|
212
301
|
return valueEncoder(value);
|
|
213
302
|
default:
|
|
@@ -522,8 +611,7 @@ function stringifyParameter(param) {
|
|
|
522
611
|
return JSON.stringify(param);
|
|
523
612
|
}
|
|
524
613
|
function appendHarValue(harParam, name, value, addtlData = {}) {
|
|
525
|
-
if (typeof value === "undefined")
|
|
526
|
-
return;
|
|
614
|
+
if (typeof value === "undefined") return;
|
|
527
615
|
if (Array.isArray(value)) {
|
|
528
616
|
value.forEach((singleValue) => {
|
|
529
617
|
appendHarValue(harParam, name, singleValue);
|
|
@@ -551,11 +639,7 @@ function encodeBodyForHAR(body) {
|
|
|
551
639
|
}
|
|
552
640
|
return stringify(body);
|
|
553
641
|
}
|
|
554
|
-
function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
555
|
-
// If true, the operation URL will be rewritten and prefixed with https://try.readme.io/ in
|
|
556
|
-
// order to funnel requests through our CORS-friendly proxy.
|
|
557
|
-
proxyUrl: false
|
|
558
|
-
}) {
|
|
642
|
+
function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = { proxyUrl: "" }) {
|
|
559
643
|
let operation;
|
|
560
644
|
if (!operationSchema || typeof operationSchema.getParameters !== "function") {
|
|
561
645
|
operation = new (0, _operation.Operation)(
|
|
@@ -599,13 +683,12 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
599
683
|
};
|
|
600
684
|
if (opts.proxyUrl) {
|
|
601
685
|
if (oas.getExtension(_extensions.PROXY_ENABLED, operation)) {
|
|
602
|
-
har.url =
|
|
686
|
+
har.url = `${opts.proxyUrl}/${har.url}`;
|
|
603
687
|
}
|
|
604
688
|
}
|
|
605
689
|
const parameters = operation.getParameters();
|
|
606
690
|
har.url = har.url.replace(/{([-_a-zA-Z0-9[\]]+)}/g, (full, key) => {
|
|
607
|
-
if (!operation || !parameters)
|
|
608
|
-
return key;
|
|
691
|
+
if (!operation || !parameters) return key;
|
|
609
692
|
const parameter = parameters.find((param) => param.name === key) || { name: key };
|
|
610
693
|
if (!("style" in parameter) || !parameter.style) {
|
|
611
694
|
return encodeURIComponent(formatter(formData, parameter, "path"));
|
|
@@ -628,13 +711,10 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
628
711
|
}
|
|
629
712
|
if (operation.schema.responses) {
|
|
630
713
|
Object.keys(operation.schema.responses).some((response) => {
|
|
631
|
-
if (_types.isRef.call(void 0, _optionalChain([operation, 'access', _14 => _14.schema, 'access', _15 => _15.responses, 'optionalAccess', _16 => _16[response]])))
|
|
632
|
-
return false;
|
|
714
|
+
if (_types.isRef.call(void 0, _optionalChain([operation, 'access', _14 => _14.schema, 'access', _15 => _15.responses, 'optionalAccess', _16 => _16[response]]))) return false;
|
|
633
715
|
const content = (_optionalChain([operation, 'access', _17 => _17.schema, 'access', _18 => _18.responses, 'optionalAccess', _19 => _19[response]])).content;
|
|
634
|
-
if (!content)
|
|
635
|
-
|
|
636
|
-
if (Object.keys(formData.header || {}).find((h) => h.toLowerCase() === "accept"))
|
|
637
|
-
return true;
|
|
716
|
+
if (!content) return false;
|
|
717
|
+
if (Object.keys(formData.header || {}).find((h) => h.toLowerCase() === "accept")) return true;
|
|
638
718
|
har.headers.push({
|
|
639
719
|
name: "accept",
|
|
640
720
|
value: getResponseContentType(content)
|
|
@@ -648,8 +728,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
648
728
|
if (headers && headers.length) {
|
|
649
729
|
headers.forEach((header) => {
|
|
650
730
|
const value = formatter(formData, header, "header", true);
|
|
651
|
-
if (typeof value === "undefined")
|
|
652
|
-
return;
|
|
731
|
+
if (typeof value === "undefined") return;
|
|
653
732
|
if (header.name.toLowerCase() === "content-type") {
|
|
654
733
|
hasContentType = true;
|
|
655
734
|
contentType = String(value);
|
|
@@ -801,7 +880,7 @@ function oasToHar(oas, operationSchema, values = {}, auth = {}, opts = {
|
|
|
801
880
|
if (securityRequirements && securityRequirements.length) {
|
|
802
881
|
securityRequirements.forEach((schemes) => {
|
|
803
882
|
Object.keys(schemes).forEach((security) => {
|
|
804
|
-
const securityValue =
|
|
883
|
+
const securityValue = _chunkE4ELBEQKcjs.configureSecurity.call(void 0, apiDefinition, auth, security);
|
|
805
884
|
if (!securityValue) {
|
|
806
885
|
return;
|
|
807
886
|
}
|