@stoplight/elements-core 7.7.15 → 7.7.17

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.
@@ -0,0 +1,3 @@
1
+ import { IHttpOperation } from '@stoplight/types';
2
+ export declare const httpOperation: IHttpOperation;
3
+ export default httpOperation;
@@ -0,0 +1,3 @@
1
+ import { IHttpOperation } from '@stoplight/types';
2
+ export declare const httpOperation: IHttpOperation;
3
+ export default httpOperation;
@@ -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
@@ -905,11 +905,17 @@ const OAuth2Auth = ({ value, onChange }) => {
905
905
  React.createElement(AuthTokenInput, { type: "oauth2", name: "Token", value: value, onChange: onChange })));
906
906
  };
907
907
 
908
- const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value }) => {
908
+ function getSupportedSecurityScheme(value, supportedSecuritySchemes) {
909
909
  var _a;
910
+ if (value && supportedSecuritySchemes.some(s => value.scheme.id === s.id)) {
911
+ return [value.scheme, (_a = value.authValue) !== null && _a !== void 0 ? _a : ''];
912
+ }
913
+ return [supportedSecuritySchemes[0], ''];
914
+ }
915
+ const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value }) => {
910
916
  const operationSecurityArray = flatten(operationAuth);
911
917
  const filteredSecurityItems = operationSecurityArray.filter(scheme => securitySchemeKeys.includes(scheme === null || scheme === void 0 ? void 0 : scheme.type));
912
- const securityScheme = value ? value.scheme : filteredSecurityItems[0];
918
+ const [securityScheme, authValue] = getSupportedSecurityScheme(value, filteredSecurityItems);
913
919
  const menuName = securityScheme ? getReadableSecurityName(securityScheme) : 'Security Scheme';
914
920
  const handleChange = (authValue) => {
915
921
  onChange(securityScheme && { scheme: securityScheme, authValue: authValue });
@@ -938,7 +944,7 @@ const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value })
938
944
  return null;
939
945
  return (React.createElement(Panel, { defaultIsOpen: true },
940
946
  React.createElement(Panel.Titlebar, { rightComponent: filteredSecurityItems.length > 1 && (React.createElement(Menu, { "aria-label": "security-schemes", items: menuItems, closeOnPress: true, renderTrigger: ({ isOpen }) => (React.createElement(Button, { appearance: "minimal", size: "sm", iconRight: ['fas', 'sort'], active: isOpen }, menuName)) })) }, "Auth"),
941
- React.createElement(SecuritySchemeComponent, { scheme: value ? value.scheme : filteredSecurityItems[0], onChange: handleChange, value: (_a = (value && value.authValue)) !== null && _a !== void 0 ? _a : '' })));
947
+ React.createElement(SecuritySchemeComponent, { scheme: securityScheme, onChange: handleChange, value: authValue })));
942
948
  };
943
949
  const GenericMessageContainer = ({ scheme }) => {
944
950
  return React.createElement(Panel.Content, null,
@@ -1480,7 +1486,7 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
1480
1486
  var _a, _b, _c;
1481
1487
  return __awaiter(this, void 0, void 0, function* () {
1482
1488
  const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
1483
- const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
1489
+ const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
1484
1490
  const queryParams = getQueryParams({ httpOperation, parameterValues });
1485
1491
  const rawHeaders = filterOutAuthorizationParams((_b = (_a = httpOperation.request) === null || _a === void 0 ? void 0 : _a.headers) !== null && _b !== void 0 ? _b : [], httpOperation.security)
1486
1492
  .map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })
@@ -1490,7 +1496,9 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
1490
1496
  const urlObject = new URL(serverUrl + expandedPath);
1491
1497
  urlObject.search = new URLSearchParams(queryParamsWithAuth.map(nameAndValueObjectToPair)).toString();
1492
1498
  const body = typeof bodyInput === 'object' ? yield createRequestBody(mediaTypeContent, bodyInput) : bodyInput;
1493
- const headers = Object.assign(Object.assign(Object.assign({}, ((mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== 'multipart/form-data' && {
1499
+ const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
1500
+ 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' &&
1501
+ shouldIncludeBody && {
1494
1502
  'Content-Type': (_c = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _c !== void 0 ? _c : 'application/json',
1495
1503
  })), Object.fromEntries(headersWithAuth.map(nameAndValueObjectToPair))), mockData === null || mockData === void 0 ? void 0 : mockData.header);
1496
1504
  return [
@@ -1555,12 +1563,19 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
1555
1563
  return __awaiter(this, void 0, void 0, function* () {
1556
1564
  const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
1557
1565
  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());
1566
+ const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
1559
1567
  const queryParams = getQueryParams({ httpOperation, parameterValues });
1560
1568
  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
1569
  if (mockData === null || mockData === void 0 ? void 0 : mockData.header) {
1562
1570
  headerParams.push({ name: 'Prefer', value: mockData.header.Prefer });
1563
1571
  }
1572
+ if (shouldIncludeBody) {
1573
+ headerParams.push({ name: 'Content-Type', value: mimeType });
1574
+ }
1575
+ const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
1576
+ if (acceptedMimeTypes.length > 0) {
1577
+ headerParams.push({ name: 'Accept', value: acceptedMimeTypes.join(', ') });
1578
+ }
1564
1579
  const [queryParamsWithAuth, headerParamsWithAuth] = runAuthRequestEhancements(auth, queryParams, headerParams);
1565
1580
  const expandedPath = uriExpand(httpOperation.path, parameterValues);
1566
1581
  const urlObject = new URL(serverUrl + expandedPath);
@@ -1591,7 +1606,7 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
1591
1606
  url: urlObject.href,
1592
1607
  httpVersion: 'HTTP/1.1',
1593
1608
  cookies: [],
1594
- headers: [{ name: 'Content-Type', value: mimeType }, ...headerParamsWithAuth],
1609
+ headers: headerParamsWithAuth,
1595
1610
  queryString: queryParamsWithAuth,
1596
1611
  postData: postData,
1597
1612
  headersSize: -1,
@@ -1606,6 +1621,11 @@ function uriExpand(uri, data) {
1606
1621
  return uri.replace(/{([^#?]+?)}/g, (match, value) => {
1607
1622
  return data[value] || value;
1608
1623
  });
1624
+ }
1625
+ function getAcceptedMimeTypes(httpOperation) {
1626
+ return Array.from(new Set(httpOperation.responses.flatMap(response => response === undefined || response.contents === undefined
1627
+ ? []
1628
+ : response.contents.map(contentType => contentType.mediaType))));
1609
1629
  }
1610
1630
 
1611
1631
  const formatMultiValueHeader = (...keyValuePairs) => {
package/index.js CHANGED
@@ -958,11 +958,17 @@ const OAuth2Auth = ({ value, onChange }) => {
958
958
  React__namespace.createElement(AuthTokenInput, { type: "oauth2", name: "Token", value: value, onChange: onChange })));
959
959
  };
960
960
 
961
- const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value }) => {
961
+ function getSupportedSecurityScheme(value, supportedSecuritySchemes) {
962
962
  var _a;
963
+ if (value && supportedSecuritySchemes.some(s => value.scheme.id === s.id)) {
964
+ return [value.scheme, (_a = value.authValue) !== null && _a !== void 0 ? _a : ''];
965
+ }
966
+ return [supportedSecuritySchemes[0], ''];
967
+ }
968
+ const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value }) => {
963
969
  const operationSecurityArray = flatten__default["default"](operationAuth);
964
970
  const filteredSecurityItems = operationSecurityArray.filter(scheme => securitySchemeKeys.includes(scheme === null || scheme === void 0 ? void 0 : scheme.type));
965
- const securityScheme = value ? value.scheme : filteredSecurityItems[0];
971
+ const [securityScheme, authValue] = getSupportedSecurityScheme(value, filteredSecurityItems);
966
972
  const menuName = securityScheme ? getReadableSecurityName(securityScheme) : 'Security Scheme';
967
973
  const handleChange = (authValue) => {
968
974
  onChange(securityScheme && { scheme: securityScheme, authValue: authValue });
@@ -991,7 +997,7 @@ const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value })
991
997
  return null;
992
998
  return (React__namespace.createElement(mosaic.Panel, { defaultIsOpen: true },
993
999
  React__namespace.createElement(mosaic.Panel.Titlebar, { rightComponent: filteredSecurityItems.length > 1 && (React__namespace.createElement(mosaic.Menu, { "aria-label": "security-schemes", items: menuItems, closeOnPress: true, renderTrigger: ({ isOpen }) => (React__namespace.createElement(mosaic.Button, { appearance: "minimal", size: "sm", iconRight: ['fas', 'sort'], active: isOpen }, menuName)) })) }, "Auth"),
994
- React__namespace.createElement(SecuritySchemeComponent, { scheme: value ? value.scheme : filteredSecurityItems[0], onChange: handleChange, value: (_a = (value && value.authValue)) !== null && _a !== void 0 ? _a : '' })));
1000
+ React__namespace.createElement(SecuritySchemeComponent, { scheme: securityScheme, onChange: handleChange, value: authValue })));
995
1001
  };
996
1002
  const GenericMessageContainer = ({ scheme }) => {
997
1003
  return React__namespace.createElement(mosaic.Panel.Content, null,
@@ -1533,7 +1539,7 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
1533
1539
  var _a, _b, _c;
1534
1540
  return tslib.__awaiter(this, void 0, void 0, function* () {
1535
1541
  const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
1536
- const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
1542
+ const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
1537
1543
  const queryParams = getQueryParams({ httpOperation, parameterValues });
1538
1544
  const rawHeaders = filterOutAuthorizationParams((_b = (_a = httpOperation.request) === null || _a === void 0 ? void 0 : _a.headers) !== null && _b !== void 0 ? _b : [], httpOperation.security)
1539
1545
  .map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })
@@ -1543,7 +1549,9 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
1543
1549
  const urlObject = new URL(serverUrl + expandedPath);
1544
1550
  urlObject.search = new URLSearchParams(queryParamsWithAuth.map(nameAndValueObjectToPair)).toString();
1545
1551
  const body = typeof bodyInput === 'object' ? yield createRequestBody(mediaTypeContent, bodyInput) : bodyInput;
1546
- const headers = Object.assign(Object.assign(Object.assign({}, ((mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== 'multipart/form-data' && {
1552
+ const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
1553
+ 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' &&
1554
+ shouldIncludeBody && {
1547
1555
  'Content-Type': (_c = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _c !== void 0 ? _c : 'application/json',
1548
1556
  })), Object.fromEntries(headersWithAuth.map(nameAndValueObjectToPair))), mockData === null || mockData === void 0 ? void 0 : mockData.header);
1549
1557
  return [
@@ -1608,12 +1616,19 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
1608
1616
  return tslib.__awaiter(this, void 0, void 0, function* () {
1609
1617
  const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
1610
1618
  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());
1619
+ const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
1612
1620
  const queryParams = getQueryParams({ httpOperation, parameterValues });
1613
1621
  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
1622
  if (mockData === null || mockData === void 0 ? void 0 : mockData.header) {
1615
1623
  headerParams.push({ name: 'Prefer', value: mockData.header.Prefer });
1616
1624
  }
1625
+ if (shouldIncludeBody) {
1626
+ headerParams.push({ name: 'Content-Type', value: mimeType });
1627
+ }
1628
+ const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
1629
+ if (acceptedMimeTypes.length > 0) {
1630
+ headerParams.push({ name: 'Accept', value: acceptedMimeTypes.join(', ') });
1631
+ }
1617
1632
  const [queryParamsWithAuth, headerParamsWithAuth] = runAuthRequestEhancements(auth, queryParams, headerParams);
1618
1633
  const expandedPath = uriExpand(httpOperation.path, parameterValues);
1619
1634
  const urlObject = new URL(serverUrl + expandedPath);
@@ -1644,7 +1659,7 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
1644
1659
  url: urlObject.href,
1645
1660
  httpVersion: 'HTTP/1.1',
1646
1661
  cookies: [],
1647
- headers: [{ name: 'Content-Type', value: mimeType }, ...headerParamsWithAuth],
1662
+ headers: headerParamsWithAuth,
1648
1663
  queryString: queryParamsWithAuth,
1649
1664
  postData: postData,
1650
1665
  headersSize: -1,
@@ -1659,6 +1674,11 @@ function uriExpand(uri, data) {
1659
1674
  return uri.replace(/{([^#?]+?)}/g, (match, value) => {
1660
1675
  return data[value] || value;
1661
1676
  });
1677
+ }
1678
+ function getAcceptedMimeTypes(httpOperation) {
1679
+ return Array.from(new Set(httpOperation.responses.flatMap(response => response === undefined || response.contents === undefined
1680
+ ? []
1681
+ : response.contents.map(contentType => contentType.mediaType))));
1662
1682
  }
1663
1683
 
1664
1684
  const formatMultiValueHeader = (...keyValuePairs) => {
package/index.mjs CHANGED
@@ -905,11 +905,17 @@ const OAuth2Auth = ({ value, onChange }) => {
905
905
  React.createElement(AuthTokenInput, { type: "oauth2", name: "Token", value: value, onChange: onChange })));
906
906
  };
907
907
 
908
- const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value }) => {
908
+ function getSupportedSecurityScheme(value, supportedSecuritySchemes) {
909
909
  var _a;
910
+ if (value && supportedSecuritySchemes.some(s => value.scheme.id === s.id)) {
911
+ return [value.scheme, (_a = value.authValue) !== null && _a !== void 0 ? _a : ''];
912
+ }
913
+ return [supportedSecuritySchemes[0], ''];
914
+ }
915
+ const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value }) => {
910
916
  const operationSecurityArray = flatten(operationAuth);
911
917
  const filteredSecurityItems = operationSecurityArray.filter(scheme => securitySchemeKeys.includes(scheme === null || scheme === void 0 ? void 0 : scheme.type));
912
- const securityScheme = value ? value.scheme : filteredSecurityItems[0];
918
+ const [securityScheme, authValue] = getSupportedSecurityScheme(value, filteredSecurityItems);
913
919
  const menuName = securityScheme ? getReadableSecurityName(securityScheme) : 'Security Scheme';
914
920
  const handleChange = (authValue) => {
915
921
  onChange(securityScheme && { scheme: securityScheme, authValue: authValue });
@@ -938,7 +944,7 @@ const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value })
938
944
  return null;
939
945
  return (React.createElement(Panel, { defaultIsOpen: true },
940
946
  React.createElement(Panel.Titlebar, { rightComponent: filteredSecurityItems.length > 1 && (React.createElement(Menu, { "aria-label": "security-schemes", items: menuItems, closeOnPress: true, renderTrigger: ({ isOpen }) => (React.createElement(Button, { appearance: "minimal", size: "sm", iconRight: ['fas', 'sort'], active: isOpen }, menuName)) })) }, "Auth"),
941
- React.createElement(SecuritySchemeComponent, { scheme: value ? value.scheme : filteredSecurityItems[0], onChange: handleChange, value: (_a = (value && value.authValue)) !== null && _a !== void 0 ? _a : '' })));
947
+ React.createElement(SecuritySchemeComponent, { scheme: securityScheme, onChange: handleChange, value: authValue })));
942
948
  };
943
949
  const GenericMessageContainer = ({ scheme }) => {
944
950
  return React.createElement(Panel.Content, null,
@@ -1480,7 +1486,7 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
1480
1486
  var _a, _b, _c;
1481
1487
  return __awaiter(this, void 0, void 0, function* () {
1482
1488
  const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
1483
- const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase());
1489
+ const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
1484
1490
  const queryParams = getQueryParams({ httpOperation, parameterValues });
1485
1491
  const rawHeaders = filterOutAuthorizationParams((_b = (_a = httpOperation.request) === null || _a === void 0 ? void 0 : _a.headers) !== null && _b !== void 0 ? _b : [], httpOperation.security)
1486
1492
  .map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })
@@ -1490,7 +1496,9 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
1490
1496
  const urlObject = new URL(serverUrl + expandedPath);
1491
1497
  urlObject.search = new URLSearchParams(queryParamsWithAuth.map(nameAndValueObjectToPair)).toString();
1492
1498
  const body = typeof bodyInput === 'object' ? yield createRequestBody(mediaTypeContent, bodyInput) : bodyInput;
1493
- const headers = Object.assign(Object.assign(Object.assign({}, ((mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== 'multipart/form-data' && {
1499
+ const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
1500
+ 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' &&
1501
+ shouldIncludeBody && {
1494
1502
  'Content-Type': (_c = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _c !== void 0 ? _c : 'application/json',
1495
1503
  })), Object.fromEntries(headersWithAuth.map(nameAndValueObjectToPair))), mockData === null || mockData === void 0 ? void 0 : mockData.header);
1496
1504
  return [
@@ -1555,12 +1563,19 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
1555
1563
  return __awaiter(this, void 0, void 0, function* () {
1556
1564
  const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy });
1557
1565
  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());
1566
+ const shouldIncludeBody = ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
1559
1567
  const queryParams = getQueryParams({ httpOperation, parameterValues });
1560
1568
  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
1569
  if (mockData === null || mockData === void 0 ? void 0 : mockData.header) {
1562
1570
  headerParams.push({ name: 'Prefer', value: mockData.header.Prefer });
1563
1571
  }
1572
+ if (shouldIncludeBody) {
1573
+ headerParams.push({ name: 'Content-Type', value: mimeType });
1574
+ }
1575
+ const acceptedMimeTypes = getAcceptedMimeTypes(httpOperation);
1576
+ if (acceptedMimeTypes.length > 0) {
1577
+ headerParams.push({ name: 'Accept', value: acceptedMimeTypes.join(', ') });
1578
+ }
1564
1579
  const [queryParamsWithAuth, headerParamsWithAuth] = runAuthRequestEhancements(auth, queryParams, headerParams);
1565
1580
  const expandedPath = uriExpand(httpOperation.path, parameterValues);
1566
1581
  const urlObject = new URL(serverUrl + expandedPath);
@@ -1591,7 +1606,7 @@ function buildHarRequest({ httpOperation, bodyInput, parameterValues, mediaTypeC
1591
1606
  url: urlObject.href,
1592
1607
  httpVersion: 'HTTP/1.1',
1593
1608
  cookies: [],
1594
- headers: [{ name: 'Content-Type', value: mimeType }, ...headerParamsWithAuth],
1609
+ headers: headerParamsWithAuth,
1595
1610
  queryString: queryParamsWithAuth,
1596
1611
  postData: postData,
1597
1612
  headersSize: -1,
@@ -1606,6 +1621,11 @@ function uriExpand(uri, data) {
1606
1621
  return uri.replace(/{([^#?]+?)}/g, (match, value) => {
1607
1622
  return data[value] || value;
1608
1623
  });
1624
+ }
1625
+ function getAcceptedMimeTypes(httpOperation) {
1626
+ return Array.from(new Set(httpOperation.responses.flatMap(response => response === undefined || response.contents === undefined
1627
+ ? []
1628
+ : response.contents.map(contentType => contentType.mediaType))));
1609
1629
  }
1610
1630
 
1611
1631
  const formatMultiValueHeader = (...keyValuePairs) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "7.7.15",
3
+ "version": "7.7.17",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",