@stoplight/elements-core 9.0.25 → 9.0.26-beta-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.
@@ -4,6 +4,7 @@ export interface ResponseState {
4
4
  bodyText?: string;
5
5
  contentType: string | null;
6
6
  blob?: Blob;
7
+ skipBodyParsing?: boolean;
7
8
  }
8
9
  export interface ErrorState {
9
10
  error: Error;
package/index.esm.js CHANGED
@@ -2,7 +2,7 @@ import { __rest, __awaiter } from 'tslib';
2
2
  import * as React from 'react';
3
3
  import React__default, { useContext, memo, useMemo, useState, useEffect, useRef, useLayoutEffect } from 'react';
4
4
  import { convertToJsonSchema } from '@stoplight/http-spec/oas';
5
- import { resolveInlineRef, hasRef, isPlainObject as isPlainObject$1, safeParse, safeStringify } from '@stoplight/json';
5
+ import { resolveInlineRef, hasRef, isPlainObject as isPlainObject$1, safeStringify, safeParse } from '@stoplight/json';
6
6
  import isArray from 'lodash/isArray.js';
7
7
  import isPlainObject from 'lodash/isPlainObject.js';
8
8
  import { NodeType, HttpParamStyles } from '@stoplight/types';
@@ -16,6 +16,7 @@ export { DefaultSMDComponents } from '@stoplight/markdown-viewer';
16
16
  import cn from 'classnames';
17
17
  import { atomWithStorage, useAtomValue } from 'jotai/utils';
18
18
  import { atom, useAtom, Provider } from 'jotai';
19
+ import * as Sampler from '@stoplight/json-schema-sampler';
19
20
  import URI from 'urijs';
20
21
  import isString from 'lodash/isString.js';
21
22
  import { CodeViewer } from '@stoplight/mosaic-code-viewer';
@@ -38,7 +39,7 @@ import map from 'lodash/map.js';
38
39
  import mapValues from 'lodash/mapValues.js';
39
40
  import pickBy from 'lodash/pickBy.js';
40
41
  import { CodeEditor } from '@stoplight/mosaic-code-editor';
41
- import * as Sampler from '@stoplight/json-schema-sampler';
42
+ import DOMPurify from 'dompurify';
42
43
  import compact from 'lodash/compact.js';
43
44
  import uniq from 'lodash/uniq.js';
44
45
  import orderBy from 'lodash/orderBy.js';
@@ -652,6 +653,242 @@ function useIsCompact(layoutOptions) {
652
653
 
653
654
  const chosenServerAtom = atom(undefined);
654
655
 
656
+ const mergeOneOfAnyOf = (schema) => {
657
+ if (!isPlainObject$1(schema)) {
658
+ return schema;
659
+ }
660
+ let result = Object.assign({}, schema);
661
+ if (result.oneOf && result.oneOf.length > 0) {
662
+ const firstOption = result.oneOf[0];
663
+ const { oneOf } = result, rest = __rest(result, ["oneOf"]);
664
+ result = Object.assign(Object.assign({}, rest), firstOption);
665
+ }
666
+ else if (result.anyOf && result.anyOf.length > 0) {
667
+ const firstOption = result.anyOf[0];
668
+ const { anyOf } = result, rest = __rest(result, ["anyOf"]);
669
+ result = Object.assign(Object.assign({}, rest), firstOption);
670
+ }
671
+ if (result.properties) {
672
+ result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, mergeOneOfAnyOf(value)]));
673
+ }
674
+ if (result.items) {
675
+ result.items = mergeOneOfAnyOf(result.items);
676
+ }
677
+ if (result.allOf) {
678
+ result.allOf = result.allOf.map((item) => mergeOneOfAnyOf(item));
679
+ }
680
+ delete result.oneOf;
681
+ delete result.anyOf;
682
+ return result;
683
+ };
684
+ const OAS_FORMAT_RANGES = {
685
+ int32: { minimum: 0 - Math.pow(2, 31), maximum: Math.pow(2, 31) - 1 },
686
+ int64: { minimum: Number.MIN_SAFE_INTEGER, maximum: Number.MAX_SAFE_INTEGER },
687
+ float: { minimum: 0 - Math.pow(2, 128), maximum: Math.pow(2, 128) - 1 },
688
+ double: { minimum: 0 - Number.MAX_VALUE, maximum: Number.MAX_VALUE },
689
+ };
690
+ const stripInferredNumericBounds = (schema) => {
691
+ var _a;
692
+ if (!isPlainObject$1(schema)) {
693
+ return schema;
694
+ }
695
+ const result = Object.assign({}, schema);
696
+ const explicitProperties = Array.isArray((_a = result === null || result === void 0 ? void 0 : result['x-stoplight']) === null || _a === void 0 ? void 0 : _a.explicitProperties)
697
+ ? result['x-stoplight'].explicitProperties
698
+ : [];
699
+ const isNumericType = result.type === 'integer' || result.type === 'number';
700
+ const formatRange = OAS_FORMAT_RANGES[result.format];
701
+ const hasExplicitMinimum = explicitProperties.includes('minimum') && result.minimum !== (formatRange === null || formatRange === void 0 ? void 0 : formatRange.minimum);
702
+ const hasExplicitMaximum = explicitProperties.includes('maximum') && result.maximum !== (formatRange === null || formatRange === void 0 ? void 0 : formatRange.maximum);
703
+ if (isNumericType && !hasExplicitMinimum) {
704
+ delete result.minimum;
705
+ }
706
+ if (isNumericType && !hasExplicitMaximum) {
707
+ delete result.maximum;
708
+ }
709
+ if (result.properties && isPlainObject$1(result.properties)) {
710
+ result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, stripInferredNumericBounds(value)]));
711
+ }
712
+ if (Array.isArray(result.items)) {
713
+ result.items = result.items.map((item) => stripInferredNumericBounds(item));
714
+ }
715
+ else if (result.items) {
716
+ result.items = stripInferredNumericBounds(result.items);
717
+ }
718
+ if (Array.isArray(result.allOf)) {
719
+ result.allOf = result.allOf.map((item) => stripInferredNumericBounds(item));
720
+ }
721
+ if (Array.isArray(result.oneOf)) {
722
+ result.oneOf = result.oneOf.map((item) => stripInferredNumericBounds(item));
723
+ }
724
+ if (Array.isArray(result.anyOf)) {
725
+ result.anyOf = result.anyOf.map((item) => stripInferredNumericBounds(item));
726
+ }
727
+ return result;
728
+ };
729
+ const FLOAT_ZERO_MARKER = '__FLOAT_ZERO__';
730
+ const markFloatZeros = (value, schema) => {
731
+ if (!isPlainObject$1(schema))
732
+ return value;
733
+ if (Array.isArray(schema.allOf)) {
734
+ return schema.allOf.reduce((currentValue, item) => markFloatZeros(currentValue, item), value);
735
+ }
736
+ if (Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {
737
+ return markFloatZeros(value, schema.oneOf[0]);
738
+ }
739
+ if (Array.isArray(schema.anyOf) && schema.anyOf.length > 0) {
740
+ return markFloatZeros(value, schema.anyOf[0]);
741
+ }
742
+ if (schema.type === 'number' && (schema.format === 'float' || schema.format === 'double') && value === 0) {
743
+ return FLOAT_ZERO_MARKER;
744
+ }
745
+ if (isPlainObject$1(value) && isPlainObject$1(schema.properties)) {
746
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => { var _a; return [k, markFloatZeros(v, (_a = schema.properties[k]) !== null && _a !== void 0 ? _a : {})]; }));
747
+ }
748
+ if (Array.isArray(value) && schema.items && !Array.isArray(schema.items)) {
749
+ return value.map((item) => markFloatZeros(item, schema.items));
750
+ }
751
+ return value;
752
+ };
753
+ const stringifyWithFloatZeros = (value) => {
754
+ var _a;
755
+ if (value === FLOAT_ZERO_MARKER)
756
+ return '0.0';
757
+ return ((_a = safeStringify(value, undefined, 2)) !== null && _a !== void 0 ? _a : '').replace(/"__FLOAT_ZERO__"/g, '0.0');
758
+ };
759
+ const normalizeInferredNumericBounds = (value, schema) => {
760
+ var _a;
761
+ if (!isPlainObject$1(schema))
762
+ return value;
763
+ const schemaObject = schema;
764
+ if (Array.isArray(schemaObject.allOf)) {
765
+ return schemaObject.allOf.reduce((currentValue, item) => normalizeInferredNumericBounds(currentValue, item), value);
766
+ }
767
+ if (Array.isArray(schemaObject.oneOf) && schemaObject.oneOf.length > 0) {
768
+ return normalizeInferredNumericBounds(value, schemaObject.oneOf[0]);
769
+ }
770
+ if (Array.isArray(schemaObject.anyOf) && schemaObject.anyOf.length > 0) {
771
+ return normalizeInferredNumericBounds(value, schemaObject.anyOf[0]);
772
+ }
773
+ const explicitProperties = Array.isArray((_a = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject['x-stoplight']) === null || _a === void 0 ? void 0 : _a.explicitProperties)
774
+ ? schemaObject['x-stoplight'].explicitProperties
775
+ : [];
776
+ const isNumericType = schemaObject.type === 'integer' || schemaObject.type === 'number';
777
+ const formatRange = OAS_FORMAT_RANGES[schemaObject.format];
778
+ const hasExplicitMinimum = explicitProperties.includes('minimum') && schemaObject.minimum !== (formatRange === null || formatRange === void 0 ? void 0 : formatRange.minimum);
779
+ const hasExplicitMaximum = explicitProperties.includes('maximum') && schemaObject.maximum !== (formatRange === null || formatRange === void 0 ? void 0 : formatRange.maximum);
780
+ if (isNumericType &&
781
+ formatRange &&
782
+ ((!hasExplicitMinimum && value === formatRange.minimum) || (!hasExplicitMaximum && value === formatRange.maximum))) {
783
+ return schemaObject.type === 'number' && (schemaObject.format === 'float' || schemaObject.format === 'double')
784
+ ? FLOAT_ZERO_MARKER
785
+ : 0;
786
+ }
787
+ if (isPlainObject$1(value) && isPlainObject$1(schemaObject.properties)) {
788
+ return Object.fromEntries(Object.entries(value).map(([key, nestedValue]) => {
789
+ var _a;
790
+ return [
791
+ key,
792
+ normalizeInferredNumericBounds(nestedValue, (_a = schemaObject.properties[key]) !== null && _a !== void 0 ? _a : {}),
793
+ ];
794
+ }));
795
+ }
796
+ if (Array.isArray(value) && schemaObject.items && !Array.isArray(schemaObject.items)) {
797
+ return value.map((item) => normalizeInferredNumericBounds(item, schemaObject.items));
798
+ }
799
+ if (Array.isArray(value) && Array.isArray(schemaObject.items)) {
800
+ return value.map((item, index) => normalizeInferredNumericBounds(item, schemaObject.items[index]));
801
+ }
802
+ return value;
803
+ };
804
+ const stringifyExampleWithResolvedSchema = (value, schema) => {
805
+ const normalizedValue = normalizeInferredNumericBounds(value, schema);
806
+ return stringifyWithFloatZeros(markFloatZeros(normalizedValue, schema));
807
+ };
808
+ const useGenerateExampleFromMediaTypeContent = (mediaTypeContent, chosenExampleIndex, { skipReadOnly, skipWriteOnly, skipNonRequired, ticks } = {}) => {
809
+ const document = useDocument();
810
+ return React__default.useMemo(() => generateExampleFromMediaTypeContent(mediaTypeContent, document, chosenExampleIndex, {
811
+ skipNonRequired,
812
+ skipWriteOnly,
813
+ skipReadOnly,
814
+ ticks: ticks || 6000,
815
+ }), [mediaTypeContent, document, chosenExampleIndex, skipNonRequired, skipWriteOnly, skipReadOnly, ticks]);
816
+ };
817
+ const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenExampleIndex = 0, options) => {
818
+ var _a;
819
+ const textRequestBodySchema = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.schema;
820
+ const textRequestBodyExamples = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.examples;
821
+ try {
822
+ if (textRequestBodyExamples === null || textRequestBodyExamples === void 0 ? void 0 : textRequestBodyExamples.length) {
823
+ return ((_a = safeStringify(textRequestBodyExamples === null || textRequestBodyExamples === void 0 ? void 0 : textRequestBodyExamples[chosenExampleIndex]['value'], undefined, 2)) !== null && _a !== void 0 ? _a : '');
824
+ }
825
+ else if (textRequestBodySchema) {
826
+ let unwrappedSchema = getResolvedObject(textRequestBodySchema);
827
+ unwrappedSchema = stripInferredNumericBounds(unwrappedSchema);
828
+ unwrappedSchema = mergeOneOfAnyOf(unwrappedSchema);
829
+ const generated = Sampler.sample(unwrappedSchema, options, document);
830
+ if (generated === null)
831
+ return '';
832
+ return stringifyExampleWithResolvedSchema(generated, unwrappedSchema);
833
+ }
834
+ }
835
+ catch (e) {
836
+ console.warn(e);
837
+ return `Example cannot be created for this schema\n${e}`;
838
+ }
839
+ return '';
840
+ };
841
+ const generateExamplesFromJsonSchema = (schema) => {
842
+ var _a;
843
+ const examples = [];
844
+ if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.examples)) {
845
+ schema.examples.forEach((example, index) => {
846
+ var _a;
847
+ examples.push({
848
+ data: (_a = safeStringify(example, undefined, 2)) !== null && _a !== void 0 ? _a : '',
849
+ label: index === 0 ? 'default' : `example-${index}`,
850
+ });
851
+ });
852
+ }
853
+ else if (isPlainObject$1(schema === null || schema === void 0 ? void 0 : schema['x-examples'])) {
854
+ for (const [label, example] of Object.entries(schema['x-examples'])) {
855
+ if (isPlainObject$1(example)) {
856
+ const val = example.hasOwnProperty('value') && Object.keys(example).length === 1 ? example.value : example;
857
+ examples.push({
858
+ label,
859
+ data: (_a = safeStringify(val, undefined, 2)) !== null && _a !== void 0 ? _a : '',
860
+ });
861
+ }
862
+ }
863
+ }
864
+ if (examples.length) {
865
+ return examples;
866
+ }
867
+ try {
868
+ let resolvedSchema = getResolvedObject(schema);
869
+ resolvedSchema = stripInferredNumericBounds(resolvedSchema);
870
+ resolvedSchema = mergeOneOfAnyOf(resolvedSchema);
871
+ const generated = Sampler.sample(resolvedSchema, {
872
+ maxSampleDepth: 4,
873
+ ticks: 6000,
874
+ });
875
+ return generated !== null
876
+ ? [
877
+ {
878
+ label: 'default',
879
+ data: stringifyExampleWithResolvedSchema(generated, resolvedSchema),
880
+ },
881
+ ]
882
+ : [{ label: 'default', data: '' }];
883
+ }
884
+ catch (e) {
885
+ return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
886
+ }
887
+ };
888
+ const exceedsSize = (example, size = 500) => {
889
+ return example.split(/\r\n|\r|\n/).length > size;
890
+ };
891
+
655
892
  function isValidServer(server) {
656
893
  return server.url !== null;
657
894
  }
@@ -1818,114 +2055,6 @@ function ExampleMenu({ examples, requestBody, onChange }) {
1818
2055
  return (React.createElement(Menu, { "aria-label": "Examples", items: menuItems, renderTrigger: ({ isOpen }) => (React.createElement(Button, { appearance: "minimal", size: "sm", iconRight: ['fas', 'sort'], active: isOpen }, "Examples")) }));
1819
2056
  }
1820
2057
 
1821
- const mergeOneOfAnyOf = (schema) => {
1822
- if (!isPlainObject$1(schema)) {
1823
- return schema;
1824
- }
1825
- let result = Object.assign({}, schema);
1826
- if (result.oneOf && result.oneOf.length > 0) {
1827
- const firstOption = result.oneOf[0];
1828
- const { oneOf } = result, rest = __rest(result, ["oneOf"]);
1829
- result = Object.assign(Object.assign({}, rest), firstOption);
1830
- }
1831
- else if (result.anyOf && result.anyOf.length > 0) {
1832
- const firstOption = result.anyOf[0];
1833
- const { anyOf } = result, rest = __rest(result, ["anyOf"]);
1834
- result = Object.assign(Object.assign({}, rest), firstOption);
1835
- }
1836
- if (result.properties) {
1837
- result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, mergeOneOfAnyOf(value)]));
1838
- }
1839
- if (result.items) {
1840
- result.items = mergeOneOfAnyOf(result.items);
1841
- }
1842
- if (result.allOf) {
1843
- result.allOf = result.allOf.map((item) => mergeOneOfAnyOf(item));
1844
- }
1845
- delete result.oneOf;
1846
- delete result.anyOf;
1847
- return result;
1848
- };
1849
- const useGenerateExampleFromMediaTypeContent = (mediaTypeContent, chosenExampleIndex, { skipReadOnly, skipWriteOnly, skipNonRequired, ticks } = {}) => {
1850
- const document = useDocument();
1851
- return React__default.useMemo(() => generateExampleFromMediaTypeContent(mediaTypeContent, document, chosenExampleIndex, {
1852
- skipNonRequired,
1853
- skipWriteOnly,
1854
- skipReadOnly,
1855
- ticks: ticks || 6000,
1856
- }), [mediaTypeContent, document, chosenExampleIndex, skipNonRequired, skipWriteOnly, skipReadOnly, ticks]);
1857
- };
1858
- const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenExampleIndex = 0, options) => {
1859
- var _a, _b;
1860
- const textRequestBodySchema = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.schema;
1861
- const textRequestBodyExamples = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.examples;
1862
- try {
1863
- if (textRequestBodyExamples === null || textRequestBodyExamples === void 0 ? void 0 : textRequestBodyExamples.length) {
1864
- return ((_a = safeStringify(textRequestBodyExamples === null || textRequestBodyExamples === void 0 ? void 0 : textRequestBodyExamples[chosenExampleIndex]['value'], undefined, 2)) !== null && _a !== void 0 ? _a : '');
1865
- }
1866
- else if (textRequestBodySchema) {
1867
- let unwrappedSchema = getResolvedObject(textRequestBodySchema);
1868
- unwrappedSchema = mergeOneOfAnyOf(unwrappedSchema);
1869
- const generated = Sampler.sample(unwrappedSchema, options, document);
1870
- return generated !== null ? (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '' : '';
1871
- }
1872
- }
1873
- catch (e) {
1874
- console.warn(e);
1875
- return `Example cannot be created for this schema\n${e}`;
1876
- }
1877
- return '';
1878
- };
1879
- const generateExamplesFromJsonSchema = (schema) => {
1880
- var _a, _b;
1881
- const examples = [];
1882
- if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.examples)) {
1883
- schema.examples.forEach((example, index) => {
1884
- var _a;
1885
- examples.push({
1886
- data: (_a = safeStringify(example, undefined, 2)) !== null && _a !== void 0 ? _a : '',
1887
- label: index === 0 ? 'default' : `example-${index}`,
1888
- });
1889
- });
1890
- }
1891
- else if (isPlainObject$1(schema === null || schema === void 0 ? void 0 : schema['x-examples'])) {
1892
- for (const [label, example] of Object.entries(schema['x-examples'])) {
1893
- if (isPlainObject$1(example)) {
1894
- const val = example.hasOwnProperty('value') && Object.keys(example).length === 1 ? example.value : example;
1895
- examples.push({
1896
- label,
1897
- data: (_a = safeStringify(val, undefined, 2)) !== null && _a !== void 0 ? _a : '',
1898
- });
1899
- }
1900
- }
1901
- }
1902
- if (examples.length) {
1903
- return examples;
1904
- }
1905
- try {
1906
- let resolvedSchema = getResolvedObject(schema);
1907
- resolvedSchema = mergeOneOfAnyOf(resolvedSchema);
1908
- const generated = Sampler.sample(resolvedSchema, {
1909
- maxSampleDepth: 4,
1910
- ticks: 6000,
1911
- });
1912
- return generated !== null
1913
- ? [
1914
- {
1915
- label: 'default',
1916
- data: (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '',
1917
- },
1918
- ]
1919
- : [{ label: 'default', data: '' }];
1920
- }
1921
- catch (e) {
1922
- return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
1923
- }
1924
- };
1925
- const exceedsSize = (example, size = 500) => {
1926
- return example.split(/\r\n|\r|\n/).length > size;
1927
- };
1928
-
1929
2058
  const useTextRequestBodyState = (mediaTypeContent, skipReadOnly) => {
1930
2059
  const initialRequestBody = useGenerateExampleFromMediaTypeContent(mediaTypeContent, undefined, {
1931
2060
  skipReadOnly,
@@ -2033,14 +2162,15 @@ const getQueryParams = ({ httpOperation, parameterValues, }) => {
2033
2162
  function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, parameterValues, serverVariableValues, mockData, auth, chosenServer, credentials = 'omit', corsProxy, }) {
2034
2163
  var _a, _b, _c;
2035
2164
  return __awaiter(this, void 0, void 0, function* () {
2165
+ const sanitizedParameterValues = Object.fromEntries(Object.entries(parameterValues).map(([key, value]) => [key, DOMPurify.sanitize(value)]));
2036
2166
  const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy, serverVariableValues });
2037
2167
  const shouldIncludeBody = ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined;
2038
- const queryParams = getQueryParams({ httpOperation, parameterValues });
2168
+ const queryParams = getQueryParams({ httpOperation, parameterValues: sanitizedParameterValues });
2039
2169
  const rawHeaders = filterOutAuthorizationParams((_b = (_a = httpOperation.request) === null || _a === void 0 ? void 0 : _a.headers) !== null && _b !== void 0 ? _b : [], httpOperation.security)
2040
- .map(header => { var _a; return ({ name: header.name, value: (_a = parameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })
2170
+ .map(header => { var _a; return ({ name: header.name, value: (_a = sanitizedParameterValues[header.name]) !== null && _a !== void 0 ? _a : '' }); })
2041
2171
  .filter(({ value }) => value.length > 0);
2042
2172
  const [queryParamsWithAuth, headersWithAuth] = runAuthRequestEhancements(auth, queryParams, rawHeaders);
2043
- const expandedPath = uriExpand(httpOperation.path, parameterValues);
2173
+ const expandedPath = uriExpand(httpOperation.path, sanitizedParameterValues);
2044
2174
  const urlObject = new URL(serverUrl + expandedPath);
2045
2175
  urlObject.search = new URLSearchParams(queryParamsWithAuth.map(nameAndValueObjectToPair)).toString();
2046
2176
  const body = typeof bodyInput === 'object' && !(bodyInput instanceof File)
@@ -2410,7 +2540,7 @@ const TryItResponse = ({ response }) => {
2410
2540
  React.createElement(Panel.Content, null,
2411
2541
  React.createElement("div", null,
2412
2542
  React.createElement("div", { className: `sl-mb-3 sl-text-${getHttpCodeColor(response.status)}` }, `${response.status} ${(_a = HttpCodeDescriptions[response.status]) !== null && _a !== void 0 ? _a : ''}`),
2413
- response.bodyText && responseType && ['json', 'xml', 'text'].includes(responseType) ? (React.createElement(ResponseCodeViewer, { language: "json", value: responseType && bodyFormat === 'preview'
2543
+ response.bodyText && responseType && ['json', 'xml', 'text'].includes(responseType) ? (React.createElement(ResponseCodeViewer, { language: "json", value: responseType && bodyFormat === 'preview' && !response.skipBodyParsing
2414
2544
  ? parseBody(response.bodyText, responseType)
2415
2545
  : response.bodyText })) : response.blob && responseType === 'image' ? (React.createElement(Flex, { justifyContent: "center" },
2416
2546
  React.createElement(Image, { src: URL.createObjectURL(response.blob), alt: "response image" }))) : !response.bodyText ? null : (React.createElement("p", null,
@@ -2513,6 +2643,12 @@ const ServerVariables = ({ variables, values, onChangeValue }) => {
2513
2643
  };
2514
2644
 
2515
2645
  const defaultServers = [];
2646
+ const findResponseForStatus = (httpOperation, status) => {
2647
+ var _a, _b;
2648
+ const statusCode = String(status);
2649
+ const statusRange = `${Math.floor(status / 100)}XX`;
2650
+ return ((_b = (_a = httpOperation.responses.find(({ code }) => code === statusCode)) !== null && _a !== void 0 ? _a : httpOperation.responses.find(({ code }) => code.toUpperCase() === statusRange)) !== null && _b !== void 0 ? _b : httpOperation.responses.find(({ code }) => code === 'default'));
2651
+ };
2516
2652
  const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embeddedInMd = false, hideTryItPanel = false, tryItCredentialsPolicy, corsProxy, }) => {
2517
2653
  var _a, _b, _c, _d, _e, _f;
2518
2654
  TryIt.displayName = 'TryIt';
@@ -2592,6 +2728,7 @@ const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embe
2592
2728
  embeddedInMd,
2593
2729
  ]);
2594
2730
  const handleSendRequest = () => __awaiter(void 0, void 0, void 0, function* () {
2731
+ var _g, _h, _j;
2595
2732
  setValidateParameters(true);
2596
2733
  if (hasRequiredButEmptyParameters || !isHttpOperation(httpOperation))
2597
2734
  return;
@@ -2624,14 +2761,28 @@ const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embe
2624
2761
  if (response) {
2625
2762
  const contentType = response.headers.get('Content-Type');
2626
2763
  const type = contentType ? getResponseType(contentType) : undefined;
2627
- const bodyText = type !== 'image' ? yield response.text() : undefined;
2764
+ let bodyText = type !== 'image' ? yield response.text() : undefined;
2628
2765
  const blob = type === 'image' ? yield response.blob() : undefined;
2766
+ let skipBodyParsing = false;
2767
+ if (mockData && type === 'json' && bodyText) {
2768
+ const responseMediaType = contentType === null || contentType === void 0 ? void 0 : contentType.split(';')[0];
2769
+ const responseSchema = (_j = (_h = (_g = findResponseForStatus(httpOperation, response.status)) === null || _g === void 0 ? void 0 : _g.contents) === null || _h === void 0 ? void 0 : _h.find(({ mediaType }) => mediaType === responseMediaType)) === null || _j === void 0 ? void 0 : _j.schema;
2770
+ if (responseSchema) {
2771
+ try {
2772
+ bodyText = stringifyExampleWithResolvedSchema(JSON.parse(bodyText), responseSchema);
2773
+ skipBodyParsing = true;
2774
+ }
2775
+ catch (_k) {
2776
+ }
2777
+ }
2778
+ }
2629
2779
  setResponse(undefined);
2630
2780
  setResponse({
2631
2781
  status: response.status,
2632
2782
  bodyText,
2633
2783
  blob,
2634
2784
  contentType,
2785
+ skipBodyParsing,
2635
2786
  });
2636
2787
  }
2637
2788
  }