@stoplight/elements-core 7.7.11 → 7.7.13
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/HttpOperation/Body.d.ts +1 -1
- package/components/Docs/story-helper.d.ts +1 -1
- package/components/RequestSamples/convertRequestToSample.d.ts +1 -1
- package/components/TryIt/Body/request-body-utils.d.ts +1 -1
- package/hooks/useRouter.d.ts +1 -1
- package/index.esm.js +52 -22
- package/index.js +52 -23
- package/index.mjs +52 -22
- package/package.json +3 -3
- package/utils/exampleGeneration/exampleGeneration.d.ts +2 -2
- package/utils/http-spec/IServer.d.ts +1 -1
|
@@ -3,7 +3,7 @@ export interface BodyProps {
|
|
|
3
3
|
body: IHttpOperationRequestBody;
|
|
4
4
|
onChange: (requestBodyIndex: number) => void;
|
|
5
5
|
}
|
|
6
|
-
export declare const isBodyEmpty: (body?:
|
|
6
|
+
export declare const isBodyEmpty: (body?: BodyProps['body']) => boolean;
|
|
7
7
|
export declare const Body: {
|
|
8
8
|
({ body, onChange }: BodyProps): JSX.Element | null;
|
|
9
9
|
displayName: string;
|
|
@@ -9,5 +9,5 @@ interface HelperReturn<P extends Partial<DocsProps>> {
|
|
|
9
9
|
createStory(name: string, input: Partial<P>): Story<P>;
|
|
10
10
|
createHoistedStory(input: Partial<P>): Story<P>;
|
|
11
11
|
}
|
|
12
|
-
export declare const createStoriesForDocsComponent: <P extends Partial<DocsProps> = DocsProps>(Component: React.ComponentType<P>, title?: string
|
|
12
|
+
export declare const createStoriesForDocsComponent: <P extends Partial<DocsProps> = DocsProps>(Component: React.ComponentType<P>, title?: string) => HelperReturn<P>;
|
|
13
13
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Request as HarFormatRequest } from 'har-format';
|
|
2
|
-
export declare const convertRequestToSample: (language: string, library: string | undefined, request: HarFormatRequest) => string | null
|
|
2
|
+
export declare const convertRequestToSample: (language: string, library: string | undefined, request: HarFormatRequest) => Promise<string | null>;
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
export declare type BodyParameterValues = Record<string, string | File>;
|
|
4
4
|
export declare type ParameterOptional = Record<string, boolean>;
|
|
5
5
|
export declare const isFormDataContent: (content: IMediaTypeContent) => boolean;
|
|
6
|
-
export declare function createRequestBody(mediaTypeContent: IMediaTypeContent | undefined, bodyParameterValues: BodyParameterValues | undefined): Promise<string | Blob | ArrayBuffer |
|
|
6
|
+
export declare function createRequestBody(mediaTypeContent: IMediaTypeContent | undefined, bodyParameterValues: BodyParameterValues | undefined): Promise<string | Blob | ArrayBuffer | ReadableStream<any> | ArrayBufferView | FormData | undefined>;
|
|
7
7
|
export declare const useBodyParameterState: (mediaTypeContent: IMediaTypeContent | undefined) => readonly [BodyParameterValues, React.Dispatch<React.SetStateAction<BodyParameterValues>>, ParameterOptional, React.Dispatch<React.SetStateAction<ParameterOptional>>, {
|
|
8
8
|
readonly isFormDataBody: true;
|
|
9
9
|
readonly bodySpecification: IMediaTypeContent<false>;
|
package/hooks/useRouter.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ interface RouterProps {
|
|
|
4
4
|
basename?: string;
|
|
5
5
|
location?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare const useRouter: (router: RouterType, basePath: string, staticRouterPath?: string
|
|
7
|
+
export declare const useRouter: (router: RouterType, basePath: string, staticRouterPath?: string) => {
|
|
8
8
|
Router: React.ComponentType<{}>;
|
|
9
9
|
routerProps: RouterProps;
|
|
10
10
|
};
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __awaiter, __rest } from 'tslib';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default, { useContext, useMemo } from 'react';
|
|
4
4
|
import { convertToJsonSchema } from '@stoplight/http-spec/oas';
|
|
@@ -10,6 +10,7 @@ import { parse } from '@stoplight/yaml';
|
|
|
10
10
|
import { isArray as isArray$1, Box, Panel, CopyButton, Menu, Button, Text, Flex, Input, Icon, Select, FieldButton, Image, Link, useThemeIsDark, HStack, VStack, InvertTheme, Tooltip, Badge, LinkHeading as LinkHeading$1, NodeAnnotation, Tabs, TabList, Tab, TabPanels, TabPanel, Heading, useClipboard, useBreakpoints, useMosaicContext, Provider as Provider$1 } from '@stoplight/mosaic';
|
|
11
11
|
import isObject from 'lodash/isObject.js';
|
|
12
12
|
import { withErrorBoundary } from '@stoplight/react-error-boundary';
|
|
13
|
+
import { useLocation, BrowserRouter, MemoryRouter, HashRouter, StaticRouter, Route } from 'react-router-dom';
|
|
13
14
|
import { MarkdownViewer as MarkdownViewer$1, DefaultSMDComponents, MarkdownViewerProvider } from '@stoplight/markdown-viewer';
|
|
14
15
|
export { DefaultSMDComponents } from '@stoplight/markdown-viewer';
|
|
15
16
|
import cn from 'classnames';
|
|
@@ -17,7 +18,7 @@ import { atomWithStorage, useAtomValue } from 'jotai/utils';
|
|
|
17
18
|
import { atom, useAtom, Provider } from 'jotai';
|
|
18
19
|
import URI from 'urijs';
|
|
19
20
|
import { CodeViewer } from '@stoplight/mosaic-code-viewer';
|
|
20
|
-
import HTTPSnippet from 'httpsnippet';
|
|
21
|
+
import { isValidTargetId, HTTPSnippet } from 'httpsnippet-lite';
|
|
21
22
|
import flatten from 'lodash/flatten.js';
|
|
22
23
|
import capitalize from 'lodash/capitalize.js';
|
|
23
24
|
import filter from 'lodash/filter.js';
|
|
@@ -38,7 +39,6 @@ import uniqBy from 'lodash/uniqBy.js';
|
|
|
38
39
|
import formatXml from 'xml-formatter';
|
|
39
40
|
import entries from 'lodash/entries.js';
|
|
40
41
|
import keys from 'lodash/keys.js';
|
|
41
|
-
import { useLocation, BrowserRouter, MemoryRouter, HashRouter, StaticRouter, Route } from 'react-router-dom';
|
|
42
42
|
import { JsonSchemaViewer } from '@stoplight/json-schema-viewer';
|
|
43
43
|
import sortBy from 'lodash/sortBy.js';
|
|
44
44
|
import { HashLink } from 'react-router-hash-link';
|
|
@@ -85,7 +85,7 @@ const recursivelyCreateResolvedObject = (currentObject, rootCurrentObject, prope
|
|
|
85
85
|
resolvedValue = mergedOptions.resolver({ pointer: value.$ref, source: null }, newPropertyPath, rootCurrentObject);
|
|
86
86
|
}
|
|
87
87
|
catch (e) {
|
|
88
|
-
resolvedValue = Object.assign(Object.assign({}, value), { $error: e.message });
|
|
88
|
+
resolvedValue = Object.assign(Object.assign({}, value), { $error: e instanceof Error ? e.message : String(e) });
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
@@ -246,14 +246,22 @@ function parseUnknown() {
|
|
|
246
246
|
return undefined;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
const RouterTypeContext = React.createContext(null);
|
|
250
|
+
const useRouterType = () => {
|
|
251
|
+
return React.useContext(RouterTypeContext);
|
|
252
|
+
};
|
|
253
|
+
|
|
249
254
|
const MarkdownViewer = (props) => {
|
|
250
255
|
return React.createElement(MarkdownViewer$1, Object.assign({}, props));
|
|
251
256
|
};
|
|
252
257
|
MarkdownViewer.displayName = 'MarkdownViewer';
|
|
253
258
|
|
|
254
259
|
const ArticleComponent = React.memo(({ data }) => {
|
|
260
|
+
const { pathname } = useLocation();
|
|
261
|
+
const routerKind = React.useContext(RouterTypeContext);
|
|
262
|
+
const basePath = routerKind === 'hash' ? `#${pathname.split('#')[0]}` : '';
|
|
255
263
|
return (React.createElement(Box, { className: "sl-elements-article" },
|
|
256
|
-
React.createElement(MarkdownViewer, { className: "sl-elements-article-content", markdown: data, includeToc: true })));
|
|
264
|
+
React.createElement(MarkdownViewer, { className: "sl-elements-article-content", markdown: data, includeToc: true, tocBasePath: basePath })));
|
|
257
265
|
});
|
|
258
266
|
const Article = withErrorBoundary(ArticleComponent, { recoverableProps: ['data'] });
|
|
259
267
|
|
|
@@ -529,16 +537,22 @@ const persistAtom = (key, atomInstance) => {
|
|
|
529
537
|
});
|
|
530
538
|
};
|
|
531
539
|
|
|
532
|
-
const convertRequestToSample = (language, library, request) => {
|
|
540
|
+
const convertRequestToSample = (language, library, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
541
|
+
if (!isValidTargetId(language))
|
|
542
|
+
return null;
|
|
533
543
|
try {
|
|
534
544
|
const snippet = new HTTPSnippet(request);
|
|
535
|
-
|
|
545
|
+
const converted = yield snippet.convert(language, library);
|
|
546
|
+
if (Array.isArray(converted)) {
|
|
547
|
+
return converted[0];
|
|
548
|
+
}
|
|
549
|
+
return converted || null;
|
|
536
550
|
}
|
|
537
551
|
catch (err) {
|
|
538
552
|
console.error(err);
|
|
539
553
|
return null;
|
|
540
554
|
}
|
|
541
|
-
};
|
|
555
|
+
});
|
|
542
556
|
|
|
543
557
|
const requestSampleConfigs = {
|
|
544
558
|
Shell: {
|
|
@@ -564,7 +578,7 @@ const requestSampleConfigs = {
|
|
|
564
578
|
httpSnippetLibrary: 'fetch',
|
|
565
579
|
},
|
|
566
580
|
XMLHttpRequest: {
|
|
567
|
-
httpSnippetLibrary: '
|
|
581
|
+
httpSnippetLibrary: 'xhr',
|
|
568
582
|
},
|
|
569
583
|
jQuery: {
|
|
570
584
|
httpSnippetLibrary: 'jquery',
|
|
@@ -656,6 +670,11 @@ const requestSampleConfigs = {
|
|
|
656
670
|
Http: {
|
|
657
671
|
mosaicCodeViewerLanguage: 'http',
|
|
658
672
|
httpSnippetLanguage: 'http',
|
|
673
|
+
libraries: {
|
|
674
|
+
'Http1.1': {
|
|
675
|
+
httpSnippetLibrary: 'http1.1',
|
|
676
|
+
},
|
|
677
|
+
},
|
|
659
678
|
},
|
|
660
679
|
Clojure: {
|
|
661
680
|
mosaicCodeViewerLanguage: 'clojure',
|
|
@@ -716,7 +735,24 @@ const RequestSamples = React__default.memo(({ request, embeddedInMd = false }) =
|
|
|
716
735
|
const [selectedLanguage, setSelectedLanguage] = useAtom(selectedLanguageAtom);
|
|
717
736
|
const [selectedLibrary, setSelectedLibrary] = useAtom(selectedLibraryAtom);
|
|
718
737
|
const { httpSnippetLanguage, httpSnippetLibrary, mosaicCodeViewerLanguage } = getConfigFor(selectedLanguage, selectedLibrary);
|
|
719
|
-
const requestSample =
|
|
738
|
+
const [requestSample, setRequestSample] = React__default.useState(null);
|
|
739
|
+
React__default.useEffect(() => {
|
|
740
|
+
let isStale = false;
|
|
741
|
+
convertRequestToSample(httpSnippetLanguage, httpSnippetLibrary, request)
|
|
742
|
+
.then(example => {
|
|
743
|
+
if (!isStale) {
|
|
744
|
+
setRequestSample(example);
|
|
745
|
+
}
|
|
746
|
+
})
|
|
747
|
+
.catch(() => {
|
|
748
|
+
if (!isStale) {
|
|
749
|
+
setRequestSample(fallbackText);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
return () => {
|
|
753
|
+
isStale = true;
|
|
754
|
+
};
|
|
755
|
+
}, [request, httpSnippetLanguage, httpSnippetLibrary]);
|
|
720
756
|
const menuItems = useMemo(() => {
|
|
721
757
|
const items = Object.entries(requestSampleConfigs).map(([language, config]) => {
|
|
722
758
|
const hasLibraries = config.libraries && Object.keys(config.libraries).length > 0;
|
|
@@ -753,13 +789,12 @@ const RequestSamples = React__default.memo(({ request, embeddedInMd = false }) =
|
|
|
753
789
|
selectedLanguage,
|
|
754
790
|
" ",
|
|
755
791
|
selectedLibrary ? ` / ${selectedLibrary}` : '')) }))),
|
|
756
|
-
React__default.createElement(Panel.Content, { p: 0 },
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
} }))));
|
|
792
|
+
React__default.createElement(Panel.Content, { p: 0 }, requestSample !== null && (React__default.createElement(CodeViewer, { "aria-label": requestSample, noCopyButton: true, maxHeight: "400px", language: mosaicCodeViewerLanguage, value: requestSample, style: embeddedInMd
|
|
793
|
+
? undefined
|
|
794
|
+
:
|
|
795
|
+
{
|
|
796
|
+
'--fs-code': 12,
|
|
797
|
+
} })))));
|
|
763
798
|
});
|
|
764
799
|
|
|
765
800
|
function getReadableSecurityName(securityScheme, includeKey = false) {
|
|
@@ -2122,11 +2157,6 @@ ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
|
|
|
2122
2157
|
return description;
|
|
2123
2158
|
}
|
|
2124
2159
|
|
|
2125
|
-
const RouterTypeContext = React.createContext(null);
|
|
2126
|
-
const useRouterType = () => {
|
|
2127
|
-
return React.useContext(RouterTypeContext);
|
|
2128
|
-
};
|
|
2129
|
-
|
|
2130
2160
|
const LinkHeading = React.memo(function LinkHeading(props) {
|
|
2131
2161
|
const isUsingRouter = !!useRouterType();
|
|
2132
2162
|
const Comp = isUsingRouter ? CustomLinkHeading : LinkHeading$1;
|
package/index.js
CHANGED
|
@@ -13,13 +13,14 @@ var yaml = require('@stoplight/yaml');
|
|
|
13
13
|
var mosaic = require('@stoplight/mosaic');
|
|
14
14
|
var isObject = require('lodash/isObject.js');
|
|
15
15
|
var reactErrorBoundary = require('@stoplight/react-error-boundary');
|
|
16
|
+
var reactRouterDom = require('react-router-dom');
|
|
16
17
|
var markdownViewer = require('@stoplight/markdown-viewer');
|
|
17
18
|
var cn = require('classnames');
|
|
18
19
|
var utils = require('jotai/utils');
|
|
19
20
|
var jotai = require('jotai');
|
|
20
21
|
var URI = require('urijs');
|
|
21
22
|
var mosaicCodeViewer = require('@stoplight/mosaic-code-viewer');
|
|
22
|
-
var
|
|
23
|
+
var httpsnippetLite = require('httpsnippet-lite');
|
|
23
24
|
var flatten = require('lodash/flatten.js');
|
|
24
25
|
var capitalize = require('lodash/capitalize.js');
|
|
25
26
|
var filter = require('lodash/filter.js');
|
|
@@ -40,7 +41,6 @@ var uniqBy = require('lodash/uniqBy.js');
|
|
|
40
41
|
var formatXml = require('xml-formatter');
|
|
41
42
|
var entries = require('lodash/entries.js');
|
|
42
43
|
var keys = require('lodash/keys.js');
|
|
43
|
-
var reactRouterDom = require('react-router-dom');
|
|
44
44
|
var jsonSchemaViewer = require('@stoplight/json-schema-viewer');
|
|
45
45
|
var sortBy = require('lodash/sortBy.js');
|
|
46
46
|
var reactRouterHashLink = require('react-router-hash-link');
|
|
@@ -77,7 +77,6 @@ var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
|
|
|
77
77
|
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
78
78
|
var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
|
|
79
79
|
var URI__default = /*#__PURE__*/_interopDefaultLegacy(URI);
|
|
80
|
-
var HTTPSnippet__default = /*#__PURE__*/_interopDefaultLegacy(HTTPSnippet);
|
|
81
80
|
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
82
81
|
var capitalize__default = /*#__PURE__*/_interopDefaultLegacy(capitalize);
|
|
83
82
|
var filter__default = /*#__PURE__*/_interopDefaultLegacy(filter);
|
|
@@ -139,7 +138,7 @@ const recursivelyCreateResolvedObject = (currentObject, rootCurrentObject, prope
|
|
|
139
138
|
resolvedValue = mergedOptions.resolver({ pointer: value.$ref, source: null }, newPropertyPath, rootCurrentObject);
|
|
140
139
|
}
|
|
141
140
|
catch (e) {
|
|
142
|
-
resolvedValue = Object.assign(Object.assign({}, value), { $error: e.message });
|
|
141
|
+
resolvedValue = Object.assign(Object.assign({}, value), { $error: e instanceof Error ? e.message : String(e) });
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
else {
|
|
@@ -300,14 +299,22 @@ function parseUnknown() {
|
|
|
300
299
|
return undefined;
|
|
301
300
|
}
|
|
302
301
|
|
|
302
|
+
const RouterTypeContext = React__namespace.createContext(null);
|
|
303
|
+
const useRouterType = () => {
|
|
304
|
+
return React__namespace.useContext(RouterTypeContext);
|
|
305
|
+
};
|
|
306
|
+
|
|
303
307
|
const MarkdownViewer = (props) => {
|
|
304
308
|
return React__namespace.createElement(markdownViewer.MarkdownViewer, Object.assign({}, props));
|
|
305
309
|
};
|
|
306
310
|
MarkdownViewer.displayName = 'MarkdownViewer';
|
|
307
311
|
|
|
308
312
|
const ArticleComponent = React__namespace.memo(({ data }) => {
|
|
313
|
+
const { pathname } = reactRouterDom.useLocation();
|
|
314
|
+
const routerKind = React__namespace.useContext(RouterTypeContext);
|
|
315
|
+
const basePath = routerKind === 'hash' ? `#${pathname.split('#')[0]}` : '';
|
|
309
316
|
return (React__namespace.createElement(mosaic.Box, { className: "sl-elements-article" },
|
|
310
|
-
React__namespace.createElement(MarkdownViewer, { className: "sl-elements-article-content", markdown: data, includeToc: true })));
|
|
317
|
+
React__namespace.createElement(MarkdownViewer, { className: "sl-elements-article-content", markdown: data, includeToc: true, tocBasePath: basePath })));
|
|
311
318
|
});
|
|
312
319
|
const Article = reactErrorBoundary.withErrorBoundary(ArticleComponent, { recoverableProps: ['data'] });
|
|
313
320
|
|
|
@@ -583,16 +590,22 @@ const persistAtom = (key, atomInstance) => {
|
|
|
583
590
|
});
|
|
584
591
|
};
|
|
585
592
|
|
|
586
|
-
const convertRequestToSample = (language, library, request) => {
|
|
593
|
+
const convertRequestToSample = (language, library, request) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
594
|
+
if (!httpsnippetLite.isValidTargetId(language))
|
|
595
|
+
return null;
|
|
587
596
|
try {
|
|
588
|
-
const snippet = new
|
|
589
|
-
|
|
597
|
+
const snippet = new httpsnippetLite.HTTPSnippet(request);
|
|
598
|
+
const converted = yield snippet.convert(language, library);
|
|
599
|
+
if (Array.isArray(converted)) {
|
|
600
|
+
return converted[0];
|
|
601
|
+
}
|
|
602
|
+
return converted || null;
|
|
590
603
|
}
|
|
591
604
|
catch (err) {
|
|
592
605
|
console.error(err);
|
|
593
606
|
return null;
|
|
594
607
|
}
|
|
595
|
-
};
|
|
608
|
+
});
|
|
596
609
|
|
|
597
610
|
const requestSampleConfigs = {
|
|
598
611
|
Shell: {
|
|
@@ -618,7 +631,7 @@ const requestSampleConfigs = {
|
|
|
618
631
|
httpSnippetLibrary: 'fetch',
|
|
619
632
|
},
|
|
620
633
|
XMLHttpRequest: {
|
|
621
|
-
httpSnippetLibrary: '
|
|
634
|
+
httpSnippetLibrary: 'xhr',
|
|
622
635
|
},
|
|
623
636
|
jQuery: {
|
|
624
637
|
httpSnippetLibrary: 'jquery',
|
|
@@ -710,6 +723,11 @@ const requestSampleConfigs = {
|
|
|
710
723
|
Http: {
|
|
711
724
|
mosaicCodeViewerLanguage: 'http',
|
|
712
725
|
httpSnippetLanguage: 'http',
|
|
726
|
+
libraries: {
|
|
727
|
+
'Http1.1': {
|
|
728
|
+
httpSnippetLibrary: 'http1.1',
|
|
729
|
+
},
|
|
730
|
+
},
|
|
713
731
|
},
|
|
714
732
|
Clojure: {
|
|
715
733
|
mosaicCodeViewerLanguage: 'clojure',
|
|
@@ -770,7 +788,24 @@ const RequestSamples = React__default["default"].memo(({ request, embeddedInMd =
|
|
|
770
788
|
const [selectedLanguage, setSelectedLanguage] = jotai.useAtom(selectedLanguageAtom);
|
|
771
789
|
const [selectedLibrary, setSelectedLibrary] = jotai.useAtom(selectedLibraryAtom);
|
|
772
790
|
const { httpSnippetLanguage, httpSnippetLibrary, mosaicCodeViewerLanguage } = getConfigFor(selectedLanguage, selectedLibrary);
|
|
773
|
-
const requestSample =
|
|
791
|
+
const [requestSample, setRequestSample] = React__default["default"].useState(null);
|
|
792
|
+
React__default["default"].useEffect(() => {
|
|
793
|
+
let isStale = false;
|
|
794
|
+
convertRequestToSample(httpSnippetLanguage, httpSnippetLibrary, request)
|
|
795
|
+
.then(example => {
|
|
796
|
+
if (!isStale) {
|
|
797
|
+
setRequestSample(example);
|
|
798
|
+
}
|
|
799
|
+
})
|
|
800
|
+
.catch(() => {
|
|
801
|
+
if (!isStale) {
|
|
802
|
+
setRequestSample(fallbackText);
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
return () => {
|
|
806
|
+
isStale = true;
|
|
807
|
+
};
|
|
808
|
+
}, [request, httpSnippetLanguage, httpSnippetLibrary]);
|
|
774
809
|
const menuItems = React.useMemo(() => {
|
|
775
810
|
const items = Object.entries(requestSampleConfigs).map(([language, config]) => {
|
|
776
811
|
const hasLibraries = config.libraries && Object.keys(config.libraries).length > 0;
|
|
@@ -807,13 +842,12 @@ const RequestSamples = React__default["default"].memo(({ request, embeddedInMd =
|
|
|
807
842
|
selectedLanguage,
|
|
808
843
|
" ",
|
|
809
844
|
selectedLibrary ? ` / ${selectedLibrary}` : '')) }))),
|
|
810
|
-
React__default["default"].createElement(mosaic.Panel.Content, { p: 0 },
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
} }))));
|
|
845
|
+
React__default["default"].createElement(mosaic.Panel.Content, { p: 0 }, requestSample !== null && (React__default["default"].createElement(mosaicCodeViewer.CodeViewer, { "aria-label": requestSample, noCopyButton: true, maxHeight: "400px", language: mosaicCodeViewerLanguage, value: requestSample, style: embeddedInMd
|
|
846
|
+
? undefined
|
|
847
|
+
:
|
|
848
|
+
{
|
|
849
|
+
'--fs-code': 12,
|
|
850
|
+
} })))));
|
|
817
851
|
});
|
|
818
852
|
|
|
819
853
|
function getReadableSecurityName(securityScheme, includeKey = false) {
|
|
@@ -2176,11 +2210,6 @@ ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
|
|
|
2176
2210
|
return description;
|
|
2177
2211
|
}
|
|
2178
2212
|
|
|
2179
|
-
const RouterTypeContext = React__namespace.createContext(null);
|
|
2180
|
-
const useRouterType = () => {
|
|
2181
|
-
return React__namespace.useContext(RouterTypeContext);
|
|
2182
|
-
};
|
|
2183
|
-
|
|
2184
2213
|
const LinkHeading = React__namespace.memo(function LinkHeading(props) {
|
|
2185
2214
|
const isUsingRouter = !!useRouterType();
|
|
2186
2215
|
const Comp = isUsingRouter ? CustomLinkHeading : mosaic.LinkHeading;
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __awaiter, __rest } from 'tslib';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default, { useContext, useMemo } from 'react';
|
|
4
4
|
import { convertToJsonSchema } from '@stoplight/http-spec/oas';
|
|
@@ -10,6 +10,7 @@ import { parse } from '@stoplight/yaml';
|
|
|
10
10
|
import { isArray as isArray$1, Box, Panel, CopyButton, Menu, Button, Text, Flex, Input, Icon, Select, FieldButton, Image, Link, useThemeIsDark, HStack, VStack, InvertTheme, Tooltip, Badge, LinkHeading as LinkHeading$1, NodeAnnotation, Tabs, TabList, Tab, TabPanels, TabPanel, Heading, useClipboard, useBreakpoints, useMosaicContext, Provider as Provider$1 } from '@stoplight/mosaic';
|
|
11
11
|
import isObject from 'lodash/isObject.js';
|
|
12
12
|
import { withErrorBoundary } from '@stoplight/react-error-boundary';
|
|
13
|
+
import { useLocation, BrowserRouter, MemoryRouter, HashRouter, StaticRouter, Route } from 'react-router-dom';
|
|
13
14
|
import { MarkdownViewer as MarkdownViewer$1, DefaultSMDComponents, MarkdownViewerProvider } from '@stoplight/markdown-viewer';
|
|
14
15
|
export { DefaultSMDComponents } from '@stoplight/markdown-viewer';
|
|
15
16
|
import cn from 'classnames';
|
|
@@ -17,7 +18,7 @@ import { atomWithStorage, useAtomValue } from 'jotai/utils';
|
|
|
17
18
|
import { atom, useAtom, Provider } from 'jotai';
|
|
18
19
|
import URI from 'urijs';
|
|
19
20
|
import { CodeViewer } from '@stoplight/mosaic-code-viewer';
|
|
20
|
-
import HTTPSnippet from 'httpsnippet';
|
|
21
|
+
import { isValidTargetId, HTTPSnippet } from 'httpsnippet-lite';
|
|
21
22
|
import flatten from 'lodash/flatten.js';
|
|
22
23
|
import capitalize from 'lodash/capitalize.js';
|
|
23
24
|
import filter from 'lodash/filter.js';
|
|
@@ -38,7 +39,6 @@ import uniqBy from 'lodash/uniqBy.js';
|
|
|
38
39
|
import formatXml from 'xml-formatter';
|
|
39
40
|
import entries from 'lodash/entries.js';
|
|
40
41
|
import keys from 'lodash/keys.js';
|
|
41
|
-
import { useLocation, BrowserRouter, MemoryRouter, HashRouter, StaticRouter, Route } from 'react-router-dom';
|
|
42
42
|
import { JsonSchemaViewer } from '@stoplight/json-schema-viewer';
|
|
43
43
|
import sortBy from 'lodash/sortBy.js';
|
|
44
44
|
import { HashLink } from 'react-router-hash-link';
|
|
@@ -85,7 +85,7 @@ const recursivelyCreateResolvedObject = (currentObject, rootCurrentObject, prope
|
|
|
85
85
|
resolvedValue = mergedOptions.resolver({ pointer: value.$ref, source: null }, newPropertyPath, rootCurrentObject);
|
|
86
86
|
}
|
|
87
87
|
catch (e) {
|
|
88
|
-
resolvedValue = Object.assign(Object.assign({}, value), { $error: e.message });
|
|
88
|
+
resolvedValue = Object.assign(Object.assign({}, value), { $error: e instanceof Error ? e.message : String(e) });
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
@@ -246,14 +246,22 @@ function parseUnknown() {
|
|
|
246
246
|
return undefined;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
const RouterTypeContext = React.createContext(null);
|
|
250
|
+
const useRouterType = () => {
|
|
251
|
+
return React.useContext(RouterTypeContext);
|
|
252
|
+
};
|
|
253
|
+
|
|
249
254
|
const MarkdownViewer = (props) => {
|
|
250
255
|
return React.createElement(MarkdownViewer$1, Object.assign({}, props));
|
|
251
256
|
};
|
|
252
257
|
MarkdownViewer.displayName = 'MarkdownViewer';
|
|
253
258
|
|
|
254
259
|
const ArticleComponent = React.memo(({ data }) => {
|
|
260
|
+
const { pathname } = useLocation();
|
|
261
|
+
const routerKind = React.useContext(RouterTypeContext);
|
|
262
|
+
const basePath = routerKind === 'hash' ? `#${pathname.split('#')[0]}` : '';
|
|
255
263
|
return (React.createElement(Box, { className: "sl-elements-article" },
|
|
256
|
-
React.createElement(MarkdownViewer, { className: "sl-elements-article-content", markdown: data, includeToc: true })));
|
|
264
|
+
React.createElement(MarkdownViewer, { className: "sl-elements-article-content", markdown: data, includeToc: true, tocBasePath: basePath })));
|
|
257
265
|
});
|
|
258
266
|
const Article = withErrorBoundary(ArticleComponent, { recoverableProps: ['data'] });
|
|
259
267
|
|
|
@@ -529,16 +537,22 @@ const persistAtom = (key, atomInstance) => {
|
|
|
529
537
|
});
|
|
530
538
|
};
|
|
531
539
|
|
|
532
|
-
const convertRequestToSample = (language, library, request) => {
|
|
540
|
+
const convertRequestToSample = (language, library, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
541
|
+
if (!isValidTargetId(language))
|
|
542
|
+
return null;
|
|
533
543
|
try {
|
|
534
544
|
const snippet = new HTTPSnippet(request);
|
|
535
|
-
|
|
545
|
+
const converted = yield snippet.convert(language, library);
|
|
546
|
+
if (Array.isArray(converted)) {
|
|
547
|
+
return converted[0];
|
|
548
|
+
}
|
|
549
|
+
return converted || null;
|
|
536
550
|
}
|
|
537
551
|
catch (err) {
|
|
538
552
|
console.error(err);
|
|
539
553
|
return null;
|
|
540
554
|
}
|
|
541
|
-
};
|
|
555
|
+
});
|
|
542
556
|
|
|
543
557
|
const requestSampleConfigs = {
|
|
544
558
|
Shell: {
|
|
@@ -564,7 +578,7 @@ const requestSampleConfigs = {
|
|
|
564
578
|
httpSnippetLibrary: 'fetch',
|
|
565
579
|
},
|
|
566
580
|
XMLHttpRequest: {
|
|
567
|
-
httpSnippetLibrary: '
|
|
581
|
+
httpSnippetLibrary: 'xhr',
|
|
568
582
|
},
|
|
569
583
|
jQuery: {
|
|
570
584
|
httpSnippetLibrary: 'jquery',
|
|
@@ -656,6 +670,11 @@ const requestSampleConfigs = {
|
|
|
656
670
|
Http: {
|
|
657
671
|
mosaicCodeViewerLanguage: 'http',
|
|
658
672
|
httpSnippetLanguage: 'http',
|
|
673
|
+
libraries: {
|
|
674
|
+
'Http1.1': {
|
|
675
|
+
httpSnippetLibrary: 'http1.1',
|
|
676
|
+
},
|
|
677
|
+
},
|
|
659
678
|
},
|
|
660
679
|
Clojure: {
|
|
661
680
|
mosaicCodeViewerLanguage: 'clojure',
|
|
@@ -716,7 +735,24 @@ const RequestSamples = React__default.memo(({ request, embeddedInMd = false }) =
|
|
|
716
735
|
const [selectedLanguage, setSelectedLanguage] = useAtom(selectedLanguageAtom);
|
|
717
736
|
const [selectedLibrary, setSelectedLibrary] = useAtom(selectedLibraryAtom);
|
|
718
737
|
const { httpSnippetLanguage, httpSnippetLibrary, mosaicCodeViewerLanguage } = getConfigFor(selectedLanguage, selectedLibrary);
|
|
719
|
-
const requestSample =
|
|
738
|
+
const [requestSample, setRequestSample] = React__default.useState(null);
|
|
739
|
+
React__default.useEffect(() => {
|
|
740
|
+
let isStale = false;
|
|
741
|
+
convertRequestToSample(httpSnippetLanguage, httpSnippetLibrary, request)
|
|
742
|
+
.then(example => {
|
|
743
|
+
if (!isStale) {
|
|
744
|
+
setRequestSample(example);
|
|
745
|
+
}
|
|
746
|
+
})
|
|
747
|
+
.catch(() => {
|
|
748
|
+
if (!isStale) {
|
|
749
|
+
setRequestSample(fallbackText);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
return () => {
|
|
753
|
+
isStale = true;
|
|
754
|
+
};
|
|
755
|
+
}, [request, httpSnippetLanguage, httpSnippetLibrary]);
|
|
720
756
|
const menuItems = useMemo(() => {
|
|
721
757
|
const items = Object.entries(requestSampleConfigs).map(([language, config]) => {
|
|
722
758
|
const hasLibraries = config.libraries && Object.keys(config.libraries).length > 0;
|
|
@@ -753,13 +789,12 @@ const RequestSamples = React__default.memo(({ request, embeddedInMd = false }) =
|
|
|
753
789
|
selectedLanguage,
|
|
754
790
|
" ",
|
|
755
791
|
selectedLibrary ? ` / ${selectedLibrary}` : '')) }))),
|
|
756
|
-
React__default.createElement(Panel.Content, { p: 0 },
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
} }))));
|
|
792
|
+
React__default.createElement(Panel.Content, { p: 0 }, requestSample !== null && (React__default.createElement(CodeViewer, { "aria-label": requestSample, noCopyButton: true, maxHeight: "400px", language: mosaicCodeViewerLanguage, value: requestSample, style: embeddedInMd
|
|
793
|
+
? undefined
|
|
794
|
+
:
|
|
795
|
+
{
|
|
796
|
+
'--fs-code': 12,
|
|
797
|
+
} })))));
|
|
763
798
|
});
|
|
764
799
|
|
|
765
800
|
function getReadableSecurityName(securityScheme, includeKey = false) {
|
|
@@ -2122,11 +2157,6 @@ ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
|
|
|
2122
2157
|
return description;
|
|
2123
2158
|
}
|
|
2124
2159
|
|
|
2125
|
-
const RouterTypeContext = React.createContext(null);
|
|
2126
|
-
const useRouterType = () => {
|
|
2127
|
-
return React.useContext(RouterTypeContext);
|
|
2128
|
-
};
|
|
2129
|
-
|
|
2130
2160
|
const LinkHeading = React.memo(function LinkHeading(props) {
|
|
2131
2161
|
const isUsingRouter = !!useRouterType();
|
|
2132
2162
|
const Comp = isUsingRouter ? CustomLinkHeading : LinkHeading$1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoplight/elements-core",
|
|
3
|
-
"version": "7.7.
|
|
3
|
+
"version": "7.7.13",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"web-components.min.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@stoplight/json-schema-ref-parser": "^9.0.5",
|
|
30
30
|
"@stoplight/json-schema-sampler": "0.2.3",
|
|
31
31
|
"@stoplight/json-schema-viewer": "^4.9.0",
|
|
32
|
-
"@stoplight/markdown-viewer": "^5.
|
|
32
|
+
"@stoplight/markdown-viewer": "^5.6.0",
|
|
33
33
|
"@stoplight/mosaic": "^1.33.0",
|
|
34
34
|
"@stoplight/mosaic-code-editor": "^1.33.0",
|
|
35
35
|
"@stoplight/mosaic-code-viewer": "^1.33.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@stoplight/types": "^13.7.0",
|
|
39
39
|
"@stoplight/yaml": "^4.2.3",
|
|
40
40
|
"classnames": "^2.2.6",
|
|
41
|
-
"httpsnippet": "^
|
|
41
|
+
"httpsnippet-lite": "^3.0.1",
|
|
42
42
|
"jotai": "1.3.9",
|
|
43
43
|
"json-schema": "^0.4.0",
|
|
44
44
|
"lodash": "^4.17.19",
|
|
@@ -6,8 +6,8 @@ declare type Example = {
|
|
|
6
6
|
data: string;
|
|
7
7
|
};
|
|
8
8
|
export declare type GenerateExampleFromMediaTypeContentOptions = Sampler.Options;
|
|
9
|
-
export declare const useGenerateExampleFromMediaTypeContent: (mediaTypeContent: IMediaTypeContent | undefined, chosenExampleIndex?: number
|
|
10
|
-
export declare const generateExampleFromMediaTypeContent: (mediaTypeContent: IMediaTypeContent | undefined, document: any, chosenExampleIndex?: number, options?:
|
|
9
|
+
export declare const useGenerateExampleFromMediaTypeContent: (mediaTypeContent: IMediaTypeContent | undefined, chosenExampleIndex?: number, { skipReadOnly, skipWriteOnly, skipNonRequired, ticks }?: GenerateExampleFromMediaTypeContentOptions) => string;
|
|
10
|
+
export declare const generateExampleFromMediaTypeContent: (mediaTypeContent: IMediaTypeContent | undefined, document: any, chosenExampleIndex?: number, options?: GenerateExampleFromMediaTypeContentOptions) => string;
|
|
11
11
|
export declare const generateExamplesFromJsonSchema: (schema: JSONSchema7) => Example[];
|
|
12
12
|
export declare const exceedsSize: (example: string, size?: number) => boolean;
|
|
13
13
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { IServer } from '@stoplight/types';
|
|
2
|
-
export declare const getServersToDisplay: (originalServers: IServer[], mockUrl?: string
|
|
2
|
+
export declare const getServersToDisplay: (originalServers: IServer[], mockUrl?: string) => IServer[];
|
|
3
3
|
export declare const getServerUrlWithDefaultValues: (server: IServer) => string | null;
|