@stoplight/elements-core 7.3.3 → 7.3.7
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/Docs/Article/index.d.ts +2 -1
- package/components/Docs/HttpOperation/HttpOperation.d.ts +2 -1
- package/components/Docs/HttpOperation/Parameters.spec.d.ts +1 -0
- package/components/Docs/HttpService/HttpService.d.ts +2 -1
- package/components/Docs/Model/Model.d.ts +2 -1
- package/components/LoadMore.d.ts +7 -0
- package/components/TryIt/Mocking/mocking-utils.d.ts +1 -1
- package/components/TryIt/Parameters/parameter-utils.d.ts +7 -3
- package/index.esm.js +143 -54
- package/index.js +199 -114
- package/index.mjs +143 -54
- package/package.json +5 -5
- package/styles.min.css +1 -1
- package/utils/{exampleGeneration.d.ts → exampleGeneration/exampleGeneration.d.ts} +1 -0
- package/utils/exampleGeneration/exampleGeneration.spec.d.ts +1 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MDAST } from '@stoplight/markdown';
|
|
2
|
+
import * as React from 'react';
|
|
2
3
|
import { DocsComponentProps } from '..';
|
|
3
4
|
declare type ArticleProps = DocsComponentProps<string | MDAST.Root>;
|
|
4
|
-
export declare const Article:
|
|
5
|
+
export declare const Article: React.FunctionComponent<ArticleProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
|
|
5
6
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IHttpOperation } from '@stoplight/types';
|
|
2
|
+
import * as React from 'react';
|
|
2
3
|
import { DocsComponentProps } from '..';
|
|
3
4
|
export declare type HttpOperationProps = DocsComponentProps<IHttpOperation>;
|
|
4
|
-
export declare const HttpOperation:
|
|
5
|
+
export declare const HttpOperation: React.FunctionComponent<HttpOperationProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IHttpService } from '@stoplight/types';
|
|
2
|
+
import * as React from 'react';
|
|
2
3
|
import { DocsComponentProps } from '..';
|
|
3
4
|
export declare type HttpServiceProps = DocsComponentProps<Partial<IHttpService>>;
|
|
4
|
-
export declare const HttpService:
|
|
5
|
+
export declare const HttpService: React.FunctionComponent<HttpServiceProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import * as React from 'react';
|
|
2
3
|
import { DocsComponentProps } from '..';
|
|
3
4
|
export declare type ModelProps = DocsComponentProps<JSONSchema7>;
|
|
4
|
-
export declare const Model:
|
|
5
|
+
export declare const Model: React.FunctionComponent<ModelProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
|
|
@@ -15,5 +15,5 @@ export declare type MockData = {
|
|
|
15
15
|
header?: Record<'Prefer', string>;
|
|
16
16
|
};
|
|
17
17
|
export declare function getMockData(url: string | undefined, httpOperation: IHttpOperation, { isEnabled, code, dynamic, example }: MockingOptions): MockData | undefined;
|
|
18
|
-
export declare function buildPreferHeader({ code, example, dynamic }: PreferHeaderProps, httpOperation: IHttpOperation): Record<'Prefer', string
|
|
18
|
+
export declare function buildPreferHeader({ code, example, dynamic }: PreferHeaderProps, httpOperation: IHttpOperation): Record<'Prefer', string> | undefined;
|
|
19
19
|
export {};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { IHttpParam } from '@stoplight/types';
|
|
2
2
|
import { JSONSchema7Definition } from 'json-schema';
|
|
3
3
|
export declare type ParameterSpec = Pick<IHttpParam, 'name' | 'examples' | 'schema' | 'required'>;
|
|
4
|
-
export declare function parameterOptions(parameter: ParameterSpec): {
|
|
4
|
+
export declare function parameterOptions(parameter: ParameterSpec): ({
|
|
5
5
|
value: string | number;
|
|
6
|
-
}
|
|
6
|
+
} | {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
})[] | null;
|
|
7
10
|
export declare const selectExampleOption: {
|
|
8
11
|
value: string;
|
|
9
12
|
label: string;
|
|
@@ -17,7 +20,8 @@ export declare function getPlaceholderForParameter(parameter: ParameterSpec): st
|
|
|
17
20
|
export declare const initialParameterValues: (params: readonly ParameterSpec[]) => Record<string, string>;
|
|
18
21
|
export declare function mapSchemaPropertiesToParameters(properties: {
|
|
19
22
|
[key: string]: JSONSchema7Definition;
|
|
20
|
-
}): {
|
|
23
|
+
}, required: string[] | undefined): {
|
|
24
|
+
required?: boolean | undefined;
|
|
21
25
|
name: string;
|
|
22
26
|
schema: import("json-schema").JSONSchema7 | undefined;
|
|
23
27
|
examples: {
|
package/index.esm.js
CHANGED
|
@@ -8,7 +8,7 @@ import { NodeType, HttpParamStyles } from '@stoplight/types';
|
|
|
8
8
|
import { parse as parse$1 } from '@stoplight/yaml';
|
|
9
9
|
import { isArray as isArray$1, Flex, Box, Popover, Button, Panel, CopyButton, Menu, Text, Input, Icon, Select, Image, Link, useThemeIsDark, Tooltip, VStack, InvertTheme, Badge, Tabs, TabList, Tab, TabPanels, TabPanel, Heading as Heading$1, HStack, useClipboard, Provider as Provider$1 } from '@stoplight/mosaic';
|
|
10
10
|
import { withErrorBoundary } from '@stoplight/react-error-boundary';
|
|
11
|
-
import { MarkdownViewer as MarkdownViewer$1, MarkdownViewerProvider } from '@stoplight/markdown-viewer';
|
|
11
|
+
import { MarkdownViewer as MarkdownViewer$1, DefaultSMDComponents, MarkdownViewerProvider } from '@stoplight/markdown-viewer';
|
|
12
12
|
export { DefaultSMDComponents } from '@stoplight/markdown-viewer';
|
|
13
13
|
import { faStream, faCrosshairs, faCloud, faBookOpen, faCube, faDatabase, faQuestionCircle, faExclamationCircle, faExclamationTriangle, faEye, faLock, faBolt, faCopy, faCheck } from '@fortawesome/free-solid-svg-icons';
|
|
14
14
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
@@ -944,12 +944,16 @@ const booleanOptions = [
|
|
|
944
944
|
{ label: 'False', value: 'false' },
|
|
945
945
|
{ label: 'True', value: 'true' },
|
|
946
946
|
];
|
|
947
|
+
function enumOptions(enumValues, required) {
|
|
948
|
+
const options = map(enumValues, v => ({ value: Number.isNaN(Number(v)) ? String(v) : Number(v) }));
|
|
949
|
+
return required ? options : [{ label: 'Not Set', value: '' }, ...options];
|
|
950
|
+
}
|
|
947
951
|
function parameterOptions(parameter) {
|
|
948
952
|
var _a, _b;
|
|
949
953
|
return ((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.type) === 'boolean'
|
|
950
954
|
? booleanOptions
|
|
951
955
|
: ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.enum) !== undefined
|
|
952
|
-
?
|
|
956
|
+
? enumOptions(parameter.schema.enum, parameter.required)
|
|
953
957
|
: null;
|
|
954
958
|
}
|
|
955
959
|
const selectExampleOption = { value: '', label: 'Pick an example' };
|
|
@@ -997,20 +1001,14 @@ const getValueForParameter = (parameter) => {
|
|
|
997
1001
|
return '';
|
|
998
1002
|
};
|
|
999
1003
|
const getInitialValueForParameter = (parameter) => {
|
|
1000
|
-
var _a;
|
|
1001
1004
|
const isRequired = !!parameter.required;
|
|
1002
|
-
|
|
1003
|
-
if (!isEnum && !isRequired)
|
|
1005
|
+
if (!isRequired)
|
|
1004
1006
|
return '';
|
|
1005
1007
|
return getValueForParameter(parameter);
|
|
1006
1008
|
};
|
|
1007
1009
|
const initialParameterValues = pipe(keyBy((param) => param.name), mapValues(getInitialValueForParameter));
|
|
1008
|
-
function mapSchemaPropertiesToParameters(properties) {
|
|
1009
|
-
return Object.entries(properties).map(([name, schema]) => ({
|
|
1010
|
-
name,
|
|
1011
|
-
schema: typeof schema !== 'boolean' ? schema : undefined,
|
|
1012
|
-
examples: typeof schema !== 'boolean' && schema.examples ? [{ key: 'example', value: schema.examples }] : undefined,
|
|
1013
|
-
}));
|
|
1010
|
+
function mapSchemaPropertiesToParameters(properties, required) {
|
|
1011
|
+
return Object.entries(properties).map(([name, schema]) => (Object.assign({ name, schema: typeof schema !== 'boolean' ? schema : undefined, examples: typeof schema !== 'boolean' && schema.examples ? [{ key: 'example', value: schema.examples }] : undefined }, ((required === null || required === void 0 ? void 0 : required.includes(name)) && { required: true }))));
|
|
1014
1012
|
}
|
|
1015
1013
|
|
|
1016
1014
|
const ParameterEditor = ({ parameter, value, onChange, validate }) => {
|
|
@@ -1032,6 +1030,7 @@ const ParameterEditor = ({ parameter, value, onChange, validate }) => {
|
|
|
1032
1030
|
const FormDataBody = ({ specification, values, onChangeValues }) => {
|
|
1033
1031
|
const schema = specification.schema;
|
|
1034
1032
|
const parameters = schema === null || schema === void 0 ? void 0 : schema.properties;
|
|
1033
|
+
const required = schema === null || schema === void 0 ? void 0 : schema.required;
|
|
1035
1034
|
React.useEffect(() => {
|
|
1036
1035
|
if (parameters === undefined) {
|
|
1037
1036
|
console.warn(`Invalid schema in form data spec: ${safeStringify(schema)}`);
|
|
@@ -1042,7 +1041,7 @@ const FormDataBody = ({ specification, values, onChangeValues }) => {
|
|
|
1042
1041
|
}
|
|
1043
1042
|
return (React.createElement(Panel, { defaultIsOpen: true },
|
|
1044
1043
|
React.createElement(Panel.Titlebar, null, "Body"),
|
|
1045
|
-
React.createElement(Panel.Content, { className: "sl-overflow-y-auto ParameterGrid OperationParametersContent" }, mapSchemaPropertiesToParameters(parameters).map(parameter => {
|
|
1044
|
+
React.createElement(Panel.Content, { className: "sl-overflow-y-auto ParameterGrid OperationParametersContent" }, mapSchemaPropertiesToParameters(parameters, required).map(parameter => {
|
|
1046
1045
|
const supportsFileUpload = parameterSupportsFileUpload(parameter);
|
|
1047
1046
|
const value = values[parameter.name];
|
|
1048
1047
|
if (supportsFileUpload) {
|
|
@@ -1114,12 +1113,13 @@ const requestBodyCreators = {
|
|
|
1114
1113
|
const useBodyParameterState = (mediaTypeContent) => {
|
|
1115
1114
|
const isFormDataBody = mediaTypeContent && isFormDataContent(mediaTypeContent);
|
|
1116
1115
|
const initialState = React.useMemo(() => {
|
|
1117
|
-
var _a, _b;
|
|
1116
|
+
var _a, _b, _c;
|
|
1118
1117
|
if (!isFormDataBody) {
|
|
1119
1118
|
return {};
|
|
1120
1119
|
}
|
|
1121
1120
|
const properties = (_b = (_a = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.schema) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {};
|
|
1122
|
-
const
|
|
1121
|
+
const required = (_c = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.schema) === null || _c === void 0 ? void 0 : _c.required;
|
|
1122
|
+
const parameters = mapSchemaPropertiesToParameters(properties, required);
|
|
1123
1123
|
return initialParameterValues(parameters);
|
|
1124
1124
|
}, [isFormDataBody, mediaTypeContent]);
|
|
1125
1125
|
const [bodyParameterValues, setBodyParameterValues] = React.useState(initialState);
|
|
@@ -1187,6 +1187,7 @@ const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenE
|
|
|
1187
1187
|
}
|
|
1188
1188
|
catch (e) {
|
|
1189
1189
|
console.warn(e);
|
|
1190
|
+
return `Example cannot be created for this schema\n${e}`;
|
|
1190
1191
|
}
|
|
1191
1192
|
return '';
|
|
1192
1193
|
};
|
|
@@ -1216,15 +1217,26 @@ const generateExamplesFromJsonSchema = (schema) => {
|
|
|
1216
1217
|
if (examples.length) {
|
|
1217
1218
|
return examples;
|
|
1218
1219
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1220
|
+
try {
|
|
1221
|
+
const generated = Sampler.sample(schema, {
|
|
1222
|
+
maxSampleDepth: 4,
|
|
1223
|
+
});
|
|
1224
|
+
return generated !== null
|
|
1225
|
+
? [
|
|
1226
|
+
{
|
|
1227
|
+
label: 'default',
|
|
1228
|
+
data: (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '',
|
|
1229
|
+
},
|
|
1230
|
+
]
|
|
1231
|
+
: [{ label: 'default', data: '' }];
|
|
1232
|
+
}
|
|
1233
|
+
catch (e) {
|
|
1234
|
+
console.error(e);
|
|
1235
|
+
return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
const exceedsSize = (example, size = 500) => {
|
|
1239
|
+
return example.split(/\r\n|\r|\n/).length > size;
|
|
1228
1240
|
};
|
|
1229
1241
|
|
|
1230
1242
|
const useTextRequestBodyState = (mediaTypeContent) => {
|
|
@@ -1261,7 +1273,9 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
|
|
|
1261
1273
|
const url = new URL(URI(serverUrl).segment(expandedPath).toString());
|
|
1262
1274
|
url.search = new URLSearchParams(queryParamsWithAuth.map(nameAndValueObjectToPair)).toString();
|
|
1263
1275
|
const body = typeof bodyInput === 'object' ? yield createRequestBody(mediaTypeContent, bodyInput) : bodyInput;
|
|
1264
|
-
const headers = Object.assign(Object.assign({
|
|
1276
|
+
const headers = Object.assign(Object.assign(Object.assign({}, ((mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== 'multipart/form-data' && {
|
|
1277
|
+
'Content-Type': (_f = mediaTypeContent === null || mediaTypeContent === void 0 ? void 0 : mediaTypeContent.mediaType) !== null && _f !== void 0 ? _f : 'application/json',
|
|
1278
|
+
})), Object.fromEntries(headersWithAuth.map(nameAndValueObjectToPair))), mockData === null || mockData === void 0 ? void 0 : mockData.header);
|
|
1265
1279
|
return [
|
|
1266
1280
|
url.toString(),
|
|
1267
1281
|
{
|
|
@@ -1395,6 +1409,9 @@ function getMockData(url, httpOperation, { isEnabled, code, dynamic, example })
|
|
|
1395
1409
|
return isEnabled && url ? { url, header: buildPreferHeader({ code, dynamic, example }, httpOperation) } : undefined;
|
|
1396
1410
|
}
|
|
1397
1411
|
function buildPreferHeader({ code, example, dynamic }, httpOperation) {
|
|
1412
|
+
if (!code) {
|
|
1413
|
+
return undefined;
|
|
1414
|
+
}
|
|
1398
1415
|
const isCodeSupported = supportsResponseCode(httpOperation, code);
|
|
1399
1416
|
const isExampleSupported = isCodeSupported && supportsExample(httpOperation, code, example);
|
|
1400
1417
|
const args = compact([
|
|
@@ -1740,6 +1757,12 @@ const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embe
|
|
|
1740
1757
|
response && 'error' in response && React.createElement(ResponseError, { state: response })));
|
|
1741
1758
|
};
|
|
1742
1759
|
|
|
1760
|
+
const LoadMore = ({ loading, onClick }) => {
|
|
1761
|
+
return (React.createElement(Flex, { flexDirection: "col", justifyContent: "center", alignItems: "center", style: { height: '400px' } },
|
|
1762
|
+
React.createElement(Button, { "aria-label": "load-example", onPress: onClick, appearance: "minimal", loading: loading, disabled: loading }, loading ? 'Loading...' : 'Load examples'),
|
|
1763
|
+
React.createElement(Text, { fontSize: "base", textAlign: "center" }, "Large examples are not rendered by default.")));
|
|
1764
|
+
};
|
|
1765
|
+
|
|
1743
1766
|
const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode }) => {
|
|
1744
1767
|
var _a;
|
|
1745
1768
|
const [chosenExampleIndex, setChosenExampleIndex] = React__default.useState(0);
|
|
@@ -1754,7 +1777,10 @@ const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode
|
|
|
1754
1777
|
const responseExample = useGenerateExampleFromMediaTypeContent(responseContents, chosenExampleIndex, {
|
|
1755
1778
|
skipWriteOnly: true,
|
|
1756
1779
|
});
|
|
1757
|
-
const
|
|
1780
|
+
const handleLoadMore = () => {
|
|
1781
|
+
setLoading(true);
|
|
1782
|
+
setTimeout(() => setShow(true), 50);
|
|
1783
|
+
};
|
|
1758
1784
|
if (!userDefinedExamples && responseMediaType !== 'application/json')
|
|
1759
1785
|
return null;
|
|
1760
1786
|
if (!responseExample)
|
|
@@ -1762,12 +1788,7 @@ const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode
|
|
|
1762
1788
|
const examplesSelect = userDefinedExamples && userDefinedExamples.length > 1 && (React__default.createElement(Select, { "aria-label": "Response Example", value: String(chosenExampleIndex), options: userDefinedExamples.map((example, index) => ({ value: index, label: example.key })), onChange: (value) => setChosenExampleIndex(parseInt(String(value), 10)), size: "sm", triggerTextPrefix: "Response Example: " }));
|
|
1763
1789
|
return (React__default.createElement(Panel, { rounded: true, isCollapsible: false },
|
|
1764
1790
|
React__default.createElement(Panel.Titlebar, null, examplesSelect || React__default.createElement(Text, { color: "body" }, "Response Example")),
|
|
1765
|
-
React__default.createElement(Panel.Content, { p: 0 },
|
|
1766
|
-
React__default.createElement(Button, { "aria-label": "load-example", onPress: () => {
|
|
1767
|
-
setLoading(true);
|
|
1768
|
-
setTimeout(() => setShow(true), 50);
|
|
1769
|
-
}, appearance: "minimal", loading: loading, disabled: loading }, loading ? 'Loading...' : 'Load examples'),
|
|
1770
|
-
React__default.createElement(Text, { fontSize: "base", textAlign: "center" }, "Large examples are not rendered by default."))))));
|
|
1791
|
+
React__default.createElement(Panel.Content, { p: 0 }, show || !exceedsSize(responseExample) ? (React__default.createElement(CodeViewer, { "aria-label": responseExample, noCopyButton: true, maxHeight: "400px", language: "json", value: responseExample, showLineNumbers: true })) : (React__default.createElement(LoadMore, { loading: loading, onClick: handleLoadMore })))));
|
|
1771
1792
|
};
|
|
1772
1793
|
|
|
1773
1794
|
const TryItWithRequestSamples = (_a) => {
|
|
@@ -1861,22 +1882,23 @@ const Parameters = ({ parameters, parameterType }) => {
|
|
|
1861
1882
|
};
|
|
1862
1883
|
Parameters.displayName = 'HttpOperation.Parameters';
|
|
1863
1884
|
const Parameter = ({ parameter, parameterType }) => {
|
|
1864
|
-
var _a, _b, _c;
|
|
1885
|
+
var _a, _b, _c, _d, _e;
|
|
1865
1886
|
if (!parameter)
|
|
1866
1887
|
return null;
|
|
1867
1888
|
const description = get(parameter, 'description') || get(parameter, 'schema.description');
|
|
1868
|
-
const
|
|
1869
|
-
const
|
|
1889
|
+
const rootType = get(parameter, 'schema.type', 'unknown');
|
|
1890
|
+
const type = ((_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b['type']) && rootType === 'array' ? `array[${parameter.schema.items['type']}]` : rootType;
|
|
1891
|
+
const format = (_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.format;
|
|
1870
1892
|
const deprecated = get(parameter, 'deprecated') || get(parameter, 'schema.deprecated', false);
|
|
1871
|
-
const parameterExamples = ((
|
|
1893
|
+
const parameterExamples = ((_d = parameter.examples) === null || _d === void 0 ? void 0 : _d.map(example => {
|
|
1872
1894
|
if (isNodeExample(example)) {
|
|
1873
1895
|
return example.value;
|
|
1874
1896
|
}
|
|
1875
1897
|
return example.externalValue;
|
|
1876
1898
|
})) || [];
|
|
1877
|
-
const schemaExamples = (
|
|
1899
|
+
const schemaExamples = (_e = parameter.schema) === null || _e === void 0 ? void 0 : _e.examples;
|
|
1878
1900
|
const schemaExamplesArray = Array.isArray(schemaExamples) ? schemaExamples : [];
|
|
1879
|
-
const validations = omitBy(Object.assign(Object.assign(Object.assign({}, omit(parameter, ['name', 'required', 'deprecated', 'description', 'schema', 'style', 'examples'])), omit(get(parameter, 'schema'), ['description', 'type', 'deprecated'])), { examples: [...parameterExamples, ...schemaExamplesArray] }), value => (typeof value === 'object' && isEmpty(value)) || typeof value === 'undefined');
|
|
1901
|
+
const validations = omitBy(Object.assign(Object.assign(Object.assign(Object.assign({}, omit(parameter, ['name', 'required', 'deprecated', 'description', 'schema', 'style', 'examples'])), omit(get(parameter, 'schema'), ['description', 'type', 'deprecated'])), omit(get(parameter, 'schema.items'), ['description', 'type', 'deprecated'])), { examples: [...parameterExamples, ...schemaExamplesArray] }), value => (typeof value === 'object' && isEmpty(value)) || typeof value === 'undefined');
|
|
1880
1902
|
return (React.createElement("div", { className: "HttpOperation__Parameters" },
|
|
1881
1903
|
React.createElement("div", { className: "sl-flex sl-items-center sl-my-2" },
|
|
1882
1904
|
React.createElement("div", { className: "sl-flex sl-items-baseline sl-text-base sl-flex-1" },
|
|
@@ -2150,10 +2172,16 @@ const HttpService = withErrorBoundary(HttpServiceComponent, { recoverableProps:
|
|
|
2150
2172
|
const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps, }) => {
|
|
2151
2173
|
var _a;
|
|
2152
2174
|
const [chosenExampleIndex, setChosenExampleIndex] = React.useState(0);
|
|
2175
|
+
const [show, setShow] = React.useState(false);
|
|
2176
|
+
const [loading, setLoading] = React.useState(false);
|
|
2153
2177
|
const resolveRef = useInlineRefResolver();
|
|
2154
2178
|
const data = useResolvedObject(unresolvedData);
|
|
2155
2179
|
const title = (_a = data.title) !== null && _a !== void 0 ? _a : nodeTitle;
|
|
2156
2180
|
const isInternal = !!data['x-internal'];
|
|
2181
|
+
const handleLoadMorePress = () => {
|
|
2182
|
+
setLoading(true);
|
|
2183
|
+
setTimeout(() => setShow(true), 50);
|
|
2184
|
+
};
|
|
2157
2185
|
const examples = React.useMemo(() => generateExamplesFromJsonSchema(data), [data]);
|
|
2158
2186
|
const shouldDisplayHeader = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) && (title !== undefined || (exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport)));
|
|
2159
2187
|
const header = (shouldDisplayHeader || isInternal) && (React.createElement(React.Fragment, null,
|
|
@@ -2168,8 +2196,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
|
|
|
2168
2196
|
const examplesSelect = examples.length > 1 && (React.createElement(Select, { "aria-label": "Example", value: String(chosenExampleIndex), options: examples.map(({ label }, index) => ({ value: index, label })), onChange: (value) => setChosenExampleIndex(parseInt(String(value), 10)), size: "sm", triggerTextPrefix: "Example: " }));
|
|
2169
2197
|
const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && (React.createElement(Panel, { rounded: true, isCollapsible: false },
|
|
2170
2198
|
React.createElement(Panel.Titlebar, null, examplesSelect || (React.createElement(Text, { color: "body", role: "heading" }, "Example"))),
|
|
2171
|
-
React.createElement(Panel.Content, { p: 0 },
|
|
2172
|
-
React.createElement(CodeViewer, { "aria-label": examples[chosenExampleIndex].data, noCopyButton: true, maxHeight: "500px", language: "json", value: examples[chosenExampleIndex].data, showLineNumbers: true }))));
|
|
2199
|
+
React.createElement(Panel.Content, { p: 0 }, show || !exceedsSize(examples[chosenExampleIndex].data) ? (React.createElement(CodeViewer, { "aria-label": examples[chosenExampleIndex].data, noCopyButton: true, maxHeight: "500px", language: "json", value: examples[chosenExampleIndex].data, showLineNumbers: true })) : (React.createElement(LoadMore, { loading: loading, onClick: handleLoadMorePress })))));
|
|
2173
2200
|
return (React.createElement(TwoColumnLayout, { className: cn('Model', className), header: header, left: description, right: modelExamples }));
|
|
2174
2201
|
};
|
|
2175
2202
|
const Model = withErrorBoundary(ModelComponent, { recoverableProps: ['data'] });
|
|
@@ -2227,8 +2254,84 @@ const Logo = ({ logo }) => {
|
|
|
2227
2254
|
React.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))) : (React.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))));
|
|
2228
2255
|
};
|
|
2229
2256
|
|
|
2257
|
+
function useParsedValue(value) {
|
|
2258
|
+
return React.useMemo(() => {
|
|
2259
|
+
let parsedValue = value;
|
|
2260
|
+
if (typeof value === 'string') {
|
|
2261
|
+
try {
|
|
2262
|
+
parsedValue = parse$1(value);
|
|
2263
|
+
}
|
|
2264
|
+
catch (error) {
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
return parsedValue;
|
|
2268
|
+
}, [value]);
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
function isPartialHttpRequest(maybeHttpRequest) {
|
|
2272
|
+
return (isObject(maybeHttpRequest) &&
|
|
2273
|
+
'method' in maybeHttpRequest &&
|
|
2274
|
+
typeof maybeHttpRequest['method'] === 'string' &&
|
|
2275
|
+
'url' in maybeHttpRequest &&
|
|
2276
|
+
typeof maybeHttpRequest['url'] === 'string');
|
|
2277
|
+
}
|
|
2278
|
+
const SchemaAndDescription = ({ title: titleProp, schema }) => {
|
|
2279
|
+
const resolveRef = useInlineRefResolver();
|
|
2280
|
+
const title = titleProp !== null && titleProp !== void 0 ? titleProp : schema.title;
|
|
2281
|
+
return (React__default.createElement(Box, { py: 2 },
|
|
2282
|
+
title && (React__default.createElement(Flex, { alignItems: "center", p: 2 },
|
|
2283
|
+
React__default.createElement(FontAwesomeIcon, { icon: NodeTypeIconDefs[NodeType.Model], color: NodeTypeColors[NodeType.Model] }),
|
|
2284
|
+
React__default.createElement(Box, { color: "muted", px: 2 }, title))),
|
|
2285
|
+
React__default.createElement(JsonSchemaViewer, { resolveRef: resolveRef, schema: getOriginalObject(schema) })));
|
|
2286
|
+
};
|
|
2287
|
+
const CodeComponent = props => {
|
|
2288
|
+
const { title, jsonSchema, http, children } = props;
|
|
2289
|
+
const value = String(Array.isArray(children) ? children[0] : children);
|
|
2290
|
+
const parsedValue = useParsedValue(value);
|
|
2291
|
+
if (jsonSchema) {
|
|
2292
|
+
if (!isJSONSchema(parsedValue)) {
|
|
2293
|
+
return null;
|
|
2294
|
+
}
|
|
2295
|
+
return React__default.createElement(SchemaAndDescription, { title: title, schema: parsedValue });
|
|
2296
|
+
}
|
|
2297
|
+
if (http) {
|
|
2298
|
+
if (!isObject(parsedValue) || (!isPartialHttpRequest(parsedValue) && !isHttpOperation(parsedValue))) {
|
|
2299
|
+
return null;
|
|
2300
|
+
}
|
|
2301
|
+
return (React__default.createElement(TryIt, { httpOperation: isHttpOperation(parsedValue) ? parsedValue : parseHttpRequest(parsedValue), embeddedInMd: true }));
|
|
2302
|
+
}
|
|
2303
|
+
const DefaultCode = DefaultSMDComponents.code;
|
|
2304
|
+
return React__default.createElement(DefaultCode, Object.assign({}, props));
|
|
2305
|
+
};
|
|
2306
|
+
function parseHttpRequest(data) {
|
|
2307
|
+
const uri = URI(data.url);
|
|
2308
|
+
const pathParam = data.url.match(/[^{\}]+(?=})/g);
|
|
2309
|
+
return {
|
|
2310
|
+
id: '?http-operation-id?',
|
|
2311
|
+
method: data.method,
|
|
2312
|
+
path: uri.is('absolute') ? uri.path() : data.url,
|
|
2313
|
+
servers: [{ url: uri.is('absolute') ? uri.origin() : data.baseUrl || '' }],
|
|
2314
|
+
request: Object.assign({ query: Object.entries(data.query || {}).map(([key, value]) => ({
|
|
2315
|
+
name: key,
|
|
2316
|
+
style: HttpParamStyles.Form,
|
|
2317
|
+
schema: { default: Array.isArray(value) && value.length > 0 ? value[0] : value },
|
|
2318
|
+
})), headers: Object.entries(data.headers || {}).map(([key, value]) => ({
|
|
2319
|
+
name: key,
|
|
2320
|
+
style: HttpParamStyles.Simple,
|
|
2321
|
+
schema: { default: value },
|
|
2322
|
+
})), path: pathParam === null || pathParam === void 0 ? void 0 : pathParam.map(name => ({
|
|
2323
|
+
name,
|
|
2324
|
+
style: HttpParamStyles.Simple,
|
|
2325
|
+
required: true,
|
|
2326
|
+
})) }, (data.body
|
|
2327
|
+
? { body: { contents: [{ mediaType: 'application/json', schema: { default: data.body } }] } }
|
|
2328
|
+
: null)),
|
|
2329
|
+
responses: [],
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2230
2333
|
const MarkdownComponentsProvider = ({ value, children }) => {
|
|
2231
|
-
return React.createElement(MarkdownViewerProvider, { components: value }, children);
|
|
2334
|
+
return React.createElement(MarkdownViewerProvider, { components: Object.assign({ code: CodeComponent }, value) }, children);
|
|
2232
2335
|
};
|
|
2233
2336
|
|
|
2234
2337
|
const NODE_TYPE_TITLE_ICON = {
|
|
@@ -2523,20 +2626,6 @@ const doBundle = (data, baseUrl) => {
|
|
|
2523
2626
|
}
|
|
2524
2627
|
};
|
|
2525
2628
|
|
|
2526
|
-
function useParsedValue(value) {
|
|
2527
|
-
return React.useMemo(() => {
|
|
2528
|
-
let parsedValue = value;
|
|
2529
|
-
if (typeof value === 'string') {
|
|
2530
|
-
try {
|
|
2531
|
-
parsedValue = parse$1(value);
|
|
2532
|
-
}
|
|
2533
|
-
catch (error) {
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
return parsedValue;
|
|
2537
|
-
}, [value]);
|
|
2538
|
-
}
|
|
2539
|
-
|
|
2540
2629
|
const scopeClassName = 'sl-elements';
|
|
2541
2630
|
class Styled extends React.Component {
|
|
2542
2631
|
getChildContext() {
|