@stoplight/elements-core 7.7.15 → 7.7.16
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/components/TryIt/build-request.d.ts +1 -0
- package/index.esm.js +18 -4
- package/index.js +18 -4
- package/index.mjs +18 -4
- package/package.json +1 -1
|
@@ -20,4 +20,5 @@ export declare const getQueryParams: ({ httpOperation, parameterValues, }: Pick<
|
|
|
20
20
|
}[];
|
|
21
21
|
export declare function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, parameterValues, mockData, auth, chosenServer, credentials, corsProxy, }: BuildRequestInput): Promise<Parameters<typeof fetch>>;
|
|
22
22
|
export declare function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeContent, auth, mockData, chosenServer, corsProxy, }: BuildRequestInput): Promise<HarRequest>;
|
|
23
|
+
export declare function getAcceptedMimeTypes(httpOperation: IHttpOperation): string[];
|
|
23
24
|
export {};
|
package/index.esm.js
CHANGED
|
@@ -1480,7 +1480,7 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
|
|
|
1480
1480
|
var _a, _b, _c;
|
|
1481
1481
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1482
1482
|
const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
|
|
1483
|
-
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
|
|
1483
|
+
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
|
|
1484
1484
|
const queryParams = getQueryParams({ httpOperation, parameterValues });
|
|
1485
1485
|
const rawHeaders = filterOutAuthorizationParams((_b = (_a = httpOperation.request) === null || _a === void 0 ? void 0 : _a.headers) !== null && _b !== void 0 ? _b : [], httpOperation.security)
|
|
1486
1486
|
.map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })
|
|
@@ -1490,7 +1490,9 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
|
|
|
1490
1490
|
const urlObject = new URL(serverUrl + expandedPath);
|
|
1491
1491
|
urlObject.search = new URLSearchParams(queryParamsWithAuth.map(nameAndValueObjectToPair)).toString();
|
|
1492
1492
|
const body = typeof bodyInput === 'object' ? yield createRequestBody(mediaTypeContent, bodyInput) : bodyInput;
|
|
1493
|
-
const
|
|
1493
|
+
const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
|
|
1494
|
+
const headers = Object.assign(Object.assign(Object.assign(Object.assign({}, (acceptedMimeTypes.length > 0 && { Accept: acceptedMimeTypes.join(', ') })), ((mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== 'multipart/form-data' &&
|
|
1495
|
+
shouldIncludeBody && {
|
|
1494
1496
|
'Content-Type': (_c = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _c !== void 0 ? _c : 'application/json',
|
|
1495
1497
|
})), Object.fromEntries(headersWithAuth.map(nameAndValueObjectToPair))), mockData === null || mockData === void 0 ? void 0 : mockData.header);
|
|
1496
1498
|
return [
|
|
@@ -1555,12 +1557,19 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
|
|
|
1555
1557
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1556
1558
|
const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
|
|
1557
1559
|
const mimeType = (_a = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _a !== void 0 ? _a : 'application/json';
|
|
1558
|
-
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
|
|
1560
|
+
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
|
|
1559
1561
|
const queryParams = getQueryParams({ httpOperation, parameterValues });
|
|
1560
1562
|
const headerParams = (_d = (_c = (_b = httpOperation.request) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })) !== null && _d !== void 0 ? _d : [];
|
|
1561
1563
|
if (mockData === null || mockData === void 0 ? void 0 : mockData.header) {
|
|
1562
1564
|
headerParams.push({ name: 'Prefer', value: mockData.header.Prefer });
|
|
1563
1565
|
}
|
|
1566
|
+
if (shouldIncludeBody) {
|
|
1567
|
+
headerParams.push({ name: 'Content-Type', value: mimeType });
|
|
1568
|
+
}
|
|
1569
|
+
const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
|
|
1570
|
+
if (acceptedMimeTypes.length > 0) {
|
|
1571
|
+
headerParams.push({ name: 'Accept', value: acceptedMimeTypes.join(', ') });
|
|
1572
|
+
}
|
|
1564
1573
|
const [queryParamsWithAuth, headerParamsWithAuth] = runAuthRequestEhancements(auth, queryParams, headerParams);
|
|
1565
1574
|
const expandedPath = uriExpand(httpOperation.path, parameterValues);
|
|
1566
1575
|
const urlObject = new URL(serverUrl + expandedPath);
|
|
@@ -1591,7 +1600,7 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
|
|
|
1591
1600
|
url: urlObject.href,
|
|
1592
1601
|
httpVersion: 'HTTP/1.1',
|
|
1593
1602
|
cookies: [],
|
|
1594
|
-
headers:
|
|
1603
|
+
headers: headerParamsWithAuth,
|
|
1595
1604
|
queryString: queryParamsWithAuth,
|
|
1596
1605
|
postData: postData,
|
|
1597
1606
|
headersSize: -1,
|
|
@@ -1606,6 +1615,11 @@ function uriExpand(uri, data) {
|
|
|
1606
1615
|
return uri.replace(/{([^#?]+?)}/g, (match, value) => {
|
|
1607
1616
|
return data[value] || value;
|
|
1608
1617
|
});
|
|
1618
|
+
}
|
|
1619
|
+
function getAcceptedMimeTypes(httpOperation) {
|
|
1620
|
+
return Array.from(new Set(httpOperation.responses.flatMap(response => response === undefined || response.contents === undefined
|
|
1621
|
+
? []
|
|
1622
|
+
: response.contents.map(contentType => contentType.mediaType))));
|
|
1609
1623
|
}
|
|
1610
1624
|
|
|
1611
1625
|
const formatMultiValueHeader = (...keyValuePairs) => {
|
package/index.js
CHANGED
|
@@ -1533,7 +1533,7 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
|
|
|
1533
1533
|
var _a, _b, _c;
|
|
1534
1534
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1535
1535
|
const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
|
|
1536
|
-
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
|
|
1536
|
+
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
|
|
1537
1537
|
const queryParams = getQueryParams({ httpOperation, parameterValues });
|
|
1538
1538
|
const rawHeaders = filterOutAuthorizationParams((_b = (_a = httpOperation.request) === null || _a === void 0 ? void 0 : _a.headers) !== null && _b !== void 0 ? _b : [], httpOperation.security)
|
|
1539
1539
|
.map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })
|
|
@@ -1543,7 +1543,9 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
|
|
|
1543
1543
|
const urlObject = new URL(serverUrl + expandedPath);
|
|
1544
1544
|
urlObject.search = new URLSearchParams(queryParamsWithAuth.map(nameAndValueObjectToPair)).toString();
|
|
1545
1545
|
const body = typeof bodyInput === 'object' ? yield createRequestBody(mediaTypeContent, bodyInput) : bodyInput;
|
|
1546
|
-
const
|
|
1546
|
+
const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
|
|
1547
|
+
const headers = Object.assign(Object.assign(Object.assign(Object.assign({}, (acceptedMimeTypes.length > 0 && { Accept: acceptedMimeTypes.join(', ') })), ((mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== 'multipart/form-data' &&
|
|
1548
|
+
shouldIncludeBody && {
|
|
1547
1549
|
'Content-Type': (_c = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _c !== void 0 ? _c : 'application/json',
|
|
1548
1550
|
})), Object.fromEntries(headersWithAuth.map(nameAndValueObjectToPair))), mockData === null || mockData === void 0 ? void 0 : mockData.header);
|
|
1549
1551
|
return [
|
|
@@ -1608,12 +1610,19 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
|
|
|
1608
1610
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1609
1611
|
const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
|
|
1610
1612
|
const mimeType = (_a = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _a !== void 0 ? _a : 'application/json';
|
|
1611
|
-
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
|
|
1613
|
+
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
|
|
1612
1614
|
const queryParams = getQueryParams({ httpOperation, parameterValues });
|
|
1613
1615
|
const headerParams = (_d = (_c = (_b = httpOperation.request) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })) !== null && _d !== void 0 ? _d : [];
|
|
1614
1616
|
if (mockData === null || mockData === void 0 ? void 0 : mockData.header) {
|
|
1615
1617
|
headerParams.push({ name: 'Prefer', value: mockData.header.Prefer });
|
|
1616
1618
|
}
|
|
1619
|
+
if (shouldIncludeBody) {
|
|
1620
|
+
headerParams.push({ name: 'Content-Type', value: mimeType });
|
|
1621
|
+
}
|
|
1622
|
+
const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
|
|
1623
|
+
if (acceptedMimeTypes.length > 0) {
|
|
1624
|
+
headerParams.push({ name: 'Accept', value: acceptedMimeTypes.join(', ') });
|
|
1625
|
+
}
|
|
1617
1626
|
const [queryParamsWithAuth, headerParamsWithAuth] = runAuthRequestEhancements(auth, queryParams, headerParams);
|
|
1618
1627
|
const expandedPath = uriExpand(httpOperation.path, parameterValues);
|
|
1619
1628
|
const urlObject = new URL(serverUrl + expandedPath);
|
|
@@ -1644,7 +1653,7 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
|
|
|
1644
1653
|
url: urlObject.href,
|
|
1645
1654
|
httpVersion: 'HTTP/1.1',
|
|
1646
1655
|
cookies: [],
|
|
1647
|
-
headers:
|
|
1656
|
+
headers: headerParamsWithAuth,
|
|
1648
1657
|
queryString: queryParamsWithAuth,
|
|
1649
1658
|
postData: postData,
|
|
1650
1659
|
headersSize: -1,
|
|
@@ -1659,6 +1668,11 @@ function uriExpand(uri, data) {
|
|
|
1659
1668
|
return uri.replace(/{([^#?]+?)}/g, (match, value) => {
|
|
1660
1669
|
return data[value] || value;
|
|
1661
1670
|
});
|
|
1671
|
+
}
|
|
1672
|
+
function getAcceptedMimeTypes(httpOperation) {
|
|
1673
|
+
return Array.from(new Set(httpOperation.responses.flatMap(response => response === undefined || response.contents === undefined
|
|
1674
|
+
? []
|
|
1675
|
+
: response.contents.map(contentType => contentType.mediaType))));
|
|
1662
1676
|
}
|
|
1663
1677
|
|
|
1664
1678
|
const formatMultiValueHeader = (...keyValuePairs) => {
|
package/index.mjs
CHANGED
|
@@ -1480,7 +1480,7 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
|
|
|
1480
1480
|
var _a, _b, _c;
|
|
1481
1481
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1482
1482
|
const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
|
|
1483
|
-
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
|
|
1483
|
+
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
|
|
1484
1484
|
const queryParams = getQueryParams({ httpOperation, parameterValues });
|
|
1485
1485
|
const rawHeaders = filterOutAuthorizationParams((_b = (_a = httpOperation.request) === null || _a === void 0 ? void 0 : _a.headers) !== null && _b !== void 0 ? _b : [], httpOperation.security)
|
|
1486
1486
|
.map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })
|
|
@@ -1490,7 +1490,9 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
|
|
|
1490
1490
|
const urlObject = new URL(serverUrl + expandedPath);
|
|
1491
1491
|
urlObject.search = new URLSearchParams(queryParamsWithAuth.map(nameAndValueObjectToPair)).toString();
|
|
1492
1492
|
const body = typeof bodyInput === 'object' ? yield createRequestBody(mediaTypeContent, bodyInput) : bodyInput;
|
|
1493
|
-
const
|
|
1493
|
+
const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
|
|
1494
|
+
const headers = Object.assign(Object.assign(Object.assign(Object.assign({}, (acceptedMimeTypes.length > 0 && { Accept: acceptedMimeTypes.join(', ') })), ((mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== 'multipart/form-data' &&
|
|
1495
|
+
shouldIncludeBody && {
|
|
1494
1496
|
'Content-Type': (_c = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _c !== void 0 ? _c : 'application/json',
|
|
1495
1497
|
})), Object.fromEntries(headersWithAuth.map(nameAndValueObjectToPair))), mockData === null || mockData === void 0 ? void 0 : mockData.header);
|
|
1496
1498
|
return [
|
|
@@ -1555,12 +1557,19 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
|
|
|
1555
1557
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1556
1558
|
const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
|
|
1557
1559
|
const mimeType = (_a = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _a !== void 0 ? _a : 'application/json';
|
|
1558
|
-
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
|
|
1560
|
+
const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
|
|
1559
1561
|
const queryParams = getQueryParams({ httpOperation, parameterValues });
|
|
1560
1562
|
const headerParams = (_d = (_c = (_b = httpOperation.request) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })) !== null && _d !== void 0 ? _d : [];
|
|
1561
1563
|
if (mockData === null || mockData === void 0 ? void 0 : mockData.header) {
|
|
1562
1564
|
headerParams.push({ name: 'Prefer', value: mockData.header.Prefer });
|
|
1563
1565
|
}
|
|
1566
|
+
if (shouldIncludeBody) {
|
|
1567
|
+
headerParams.push({ name: 'Content-Type', value: mimeType });
|
|
1568
|
+
}
|
|
1569
|
+
const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
|
|
1570
|
+
if (acceptedMimeTypes.length > 0) {
|
|
1571
|
+
headerParams.push({ name: 'Accept', value: acceptedMimeTypes.join(', ') });
|
|
1572
|
+
}
|
|
1564
1573
|
const [queryParamsWithAuth, headerParamsWithAuth] = runAuthRequestEhancements(auth, queryParams, headerParams);
|
|
1565
1574
|
const expandedPath = uriExpand(httpOperation.path, parameterValues);
|
|
1566
1575
|
const urlObject = new URL(serverUrl + expandedPath);
|
|
@@ -1591,7 +1600,7 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
|
|
|
1591
1600
|
url: urlObject.href,
|
|
1592
1601
|
httpVersion: 'HTTP/1.1',
|
|
1593
1602
|
cookies: [],
|
|
1594
|
-
headers:
|
|
1603
|
+
headers: headerParamsWithAuth,
|
|
1595
1604
|
queryString: queryParamsWithAuth,
|
|
1596
1605
|
postData: postData,
|
|
1597
1606
|
headersSize: -1,
|
|
@@ -1606,6 +1615,11 @@ function uriExpand(uri, data) {
|
|
|
1606
1615
|
return uri.replace(/{([^#?]+?)}/g, (match, value) => {
|
|
1607
1616
|
return data[value] || value;
|
|
1608
1617
|
});
|
|
1618
|
+
}
|
|
1619
|
+
function getAcceptedMimeTypes(httpOperation) {
|
|
1620
|
+
return Array.from(new Set(httpOperation.responses.flatMap(response => response === undefined || response.contents === undefined
|
|
1621
|
+
? []
|
|
1622
|
+
: response.contents.map(contentType => contentType.mediaType))));
|
|
1609
1623
|
}
|
|
1610
1624
|
|
|
1611
1625
|
const formatMultiValueHeader = (...keyValuePairs) => {
|