@gitbook/react-openapi 1.0.3 → 1.0.4

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/OpenAPICodeSample.jsx +6 -7
  3. package/dist/OpenAPIDisclosure.d.ts +2 -1
  4. package/dist/OpenAPIDisclosure.jsx +1 -1
  5. package/dist/OpenAPIDisclosureGroup.d.ts +1 -1
  6. package/dist/OpenAPIDisclosureGroup.jsx +2 -2
  7. package/dist/OpenAPIOperation.jsx +2 -2
  8. package/dist/OpenAPIPath.d.ts +3 -2
  9. package/dist/OpenAPIPath.jsx +4 -15
  10. package/dist/OpenAPIRequestBody.jsx +1 -1
  11. package/dist/OpenAPIResponse.jsx +1 -1
  12. package/dist/OpenAPIResponseExample.jsx +3 -3
  13. package/dist/OpenAPIResponses.d.ts +1 -1
  14. package/dist/OpenAPIResponses.jsx +2 -2
  15. package/dist/OpenAPISchema.d.ts +5 -1
  16. package/dist/OpenAPISchema.jsx +29 -20
  17. package/dist/OpenAPISchemaName.d.ts +4 -3
  18. package/dist/OpenAPISchemaName.jsx +1 -1
  19. package/dist/OpenAPISecurities.jsx +2 -2
  20. package/dist/OpenAPITabs.d.ts +3 -3
  21. package/dist/OpenAPITabs.jsx +11 -12
  22. package/dist/ScalarApiButton.jsx +1 -1
  23. package/dist/code-samples.js +11 -11
  24. package/dist/generateSchemaExample.js +2 -1
  25. package/dist/resolveOpenAPIOperation.d.ts +3 -3
  26. package/dist/resolveOpenAPIOperation.js +1 -1
  27. package/dist/tsconfig.build.tsbuildinfo +1 -1
  28. package/dist/util/server.d.ts +1 -1
  29. package/dist/util/server.js +1 -3
  30. package/dist/utils.d.ts +1 -1
  31. package/dist/utils.js +4 -6
  32. package/package.json +2 -7
  33. package/src/InteractiveSection.tsx +4 -4
  34. package/src/OpenAPICodeSample.tsx +9 -10
  35. package/src/OpenAPIDisclosure.tsx +4 -3
  36. package/src/OpenAPIDisclosureGroup.tsx +5 -5
  37. package/src/OpenAPIOperation.tsx +3 -3
  38. package/src/OpenAPIOperationContext.tsx +1 -1
  39. package/src/OpenAPIPath.tsx +11 -10
  40. package/src/OpenAPIRequestBody.tsx +2 -2
  41. package/src/OpenAPIResponse.tsx +3 -3
  42. package/src/OpenAPIResponseExample.tsx +5 -5
  43. package/src/OpenAPIResponses.tsx +4 -4
  44. package/src/OpenAPISchema.test.ts +5 -5
  45. package/src/OpenAPISchema.tsx +75 -25
  46. package/src/OpenAPISchemaName.tsx +5 -4
  47. package/src/OpenAPISecurities.tsx +3 -3
  48. package/src/OpenAPITabs.tsx +15 -15
  49. package/src/ScalarApiButton.tsx +3 -3
  50. package/src/code-samples.test.ts +66 -66
  51. package/src/code-samples.ts +14 -14
  52. package/src/generateSchemaExample.ts +3 -3
  53. package/src/json2xml.test.ts +1 -1
  54. package/src/resolveOpenAPIOperation.test.ts +6 -6
  55. package/src/resolveOpenAPIOperation.ts +7 -7
  56. package/src/stringifyOpenAPI.ts +1 -1
  57. package/src/util/server.test.ts +3 -3
  58. package/src/util/server.ts +2 -3
  59. package/src/utils.ts +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @gitbook/react-openapi
2
2
 
3
+ ## 1.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 722f02e: Fix recursion in OpenAPISchemaAlternative
8
+ - Updated dependencies [0924259]
9
+ - @gitbook/openapi-parser@2.0.1
10
+
3
11
  ## 1.0.3
4
12
 
5
13
  ### Patch Changes
@@ -9,14 +9,13 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ import { InteractiveSection } from './InteractiveSection';
13
+ import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
12
14
  import { codeSampleGenerators } from './code-samples';
13
15
  import { generateMediaTypeExample, generateSchemaExample } from './generateSchemaExample';
14
- import { InteractiveSection } from './InteractiveSection';
15
- import { createStateKey } from './utils';
16
16
  import { stringifyOpenAPI } from './stringifyOpenAPI';
17
- import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
18
- import { checkIsReference } from './utils';
19
17
  import { getDefaultServerURL } from './util/server';
18
+ import { checkIsReference, createStateKey } from './utils';
20
19
  /**
21
20
  * Display code samples to execute the operation.
22
21
  * It supports the Redocly custom syntax as well (https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/)
@@ -82,8 +81,8 @@ export function OpenAPICodeSample(props) {
82
81
  typeof sample.source === 'string' &&
83
82
  typeof sample.lang === 'string');
84
83
  })
85
- .map(function (sample) { return ({
86
- key: "redocly-".concat(sample.lang),
84
+ .map(function (sample, index) { return ({
85
+ key: "redocly-".concat(sample.lang, "-").concat(index),
87
86
  label: sample.label,
88
87
  body: context.renderCodeBlock({
89
88
  code: sample.source,
@@ -127,7 +126,7 @@ function getSecurityHeaders(securities) {
127
126
  scheme = 'Token';
128
127
  }
129
128
  return {
130
- Authorization: scheme + ' ' + format,
129
+ Authorization: "".concat(scheme, " ").concat(format),
131
130
  };
132
131
  }
133
132
  case 'apiKey': {
@@ -1,3 +1,4 @@
1
+ import type React from 'react';
1
2
  import type { OpenAPIClientContext } from './types';
2
3
  interface Props {
3
4
  context: OpenAPIClientContext;
@@ -8,5 +9,5 @@ interface Props {
8
9
  * Display an interactive OpenAPI disclosure.
9
10
  * The label is optional and defaults to "child attributes".
10
11
  */
11
- export declare function OpenAPIDisclosure({ context, children, label }: Props): JSX.Element;
12
+ export declare function OpenAPIDisclosure({ context, children, label }: Props): React.JSX.Element;
12
13
  export {};
@@ -21,7 +21,7 @@ export function OpenAPIDisclosure(_a) {
21
21
  }}>
22
22
  {context.icons.plus}
23
23
  <span>
24
- {"".concat(state.isExpanded ? 'Hide' : 'Show', " ").concat(label ? label : "child attributes")}
24
+ {"".concat(state.isExpanded ? 'Hide' : 'Show', " ").concat(label ? label : 'child attributes')}
25
25
  </span>
26
26
  </button>
27
27
 
@@ -11,7 +11,7 @@ type TDisclosureGroup = {
11
11
  body?: React.ReactNode;
12
12
  }[];
13
13
  };
14
- import { DisclosureGroupProps } from 'react-stately';
14
+ import { type DisclosureGroupProps } from 'react-stately';
15
15
  /**
16
16
  * Display an interactive OpenAPI disclosure group.
17
17
  */
@@ -9,9 +9,9 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ import { createContext, useContext, useRef, useState } from 'react';
12
13
  import { mergeProps, useButton, useDisclosure, useFocusRing, useId } from 'react-aria';
13
14
  import { useDisclosureGroupState, useDisclosureState, } from 'react-stately';
14
- import { createContext, useContext, useRef, useState } from 'react';
15
15
  var DisclosureGroupStateContext = createContext(null);
16
16
  /**
17
17
  * Display an interactive OpenAPI disclosure group.
@@ -70,7 +70,7 @@ function DisclosureItem(props) {
70
70
  {group.tabs.map(function (tab) { return (<option key={tab.id} value={tab.id}>
71
71
  {tab.label}
72
72
  </option>); })}
73
- </select>) : !!group.tabs[0] ? (<span>{group.tabs[0].label}</span>) : null}
73
+ </select>) : group.tabs[0] ? (<span>{group.tabs[0].label}</span>) : null}
74
74
  </div>) : null}
75
75
  </div>
76
76
 
@@ -1,9 +1,9 @@
1
1
  import clsx from 'clsx';
2
2
  import { Markdown } from './Markdown';
3
3
  import { OpenAPICodeSample } from './OpenAPICodeSample';
4
+ import { OpenAPIPath } from './OpenAPIPath';
4
5
  import { OpenAPIResponseExample } from './OpenAPIResponseExample';
5
6
  import { OpenAPISpec } from './OpenAPISpec';
6
- import { OpenAPIPath } from './OpenAPIPath';
7
7
  import { resolveDescription } from './utils';
8
8
  /**
9
9
  * Display an interactive OpenAPI operation.
@@ -34,7 +34,7 @@ export function OpenAPIOperation(props) {
34
34
  <span className="openapi-deprecated-sunset-date">
35
35
  {operation['x-deprecated-sunset']}
36
36
  </span>
37
- {"."}
37
+ {'.'}
38
38
  </div>) : null}
39
39
  <OpenAPIOperationDescription operation={operation} context={context}/>
40
40
  <OpenAPIPath data={data} context={context}/>
@@ -1,8 +1,9 @@
1
- import type { OpenAPIOperationData, OpenAPIContextProps } from './types';
1
+ import type React from 'react';
2
+ import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
2
3
  /**
3
4
  * Display the path of an operation.
4
5
  */
5
6
  export declare function OpenAPIPath(props: {
6
7
  data: OpenAPIOperationData;
7
8
  context: OpenAPIContextProps;
8
- }): JSX.Element;
9
+ }): React.JSX.Element;
@@ -1,12 +1,3 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
1
  import { ScalarApiButton } from './ScalarApiButton';
11
2
  /**
12
3
  * Display the path of an operation.
@@ -41,14 +32,12 @@ function formatPath(path) {
41
32
  // Join parts with separators wrapped in <span>
42
33
  var formattedPath = parts.reduce(function (acc, part, index) {
43
34
  if (typeof part === 'string' && index > 0 && part === '/') {
44
- return __spreadArray(__spreadArray([], acc, true), [
45
- <span className="openapi-path-separator" key={"sep-".concat(index)}>
35
+ acc.push(<span className="openapi-path-separator" key={"sep-".concat(index)}>
46
36
  /
47
- </span>,
48
- part,
49
- ], false);
37
+ </span>);
50
38
  }
51
- return __spreadArray(__spreadArray([], acc, true), [part], false);
39
+ acc.push(part);
40
+ return acc;
52
41
  }, []);
53
42
  return <span>{formattedPath}</span>;
54
43
  }
@@ -1,5 +1,5 @@
1
- import { OpenAPIRootSchema } from './OpenAPISchema';
2
1
  import { InteractiveSection } from './InteractiveSection';
2
+ import { OpenAPIRootSchema } from './OpenAPISchema';
3
3
  import { checkIsReference } from './utils';
4
4
  /**
5
5
  * Display an interactive request body.
@@ -9,9 +9,9 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ import { OpenAPIDisclosure } from './OpenAPIDisclosure';
12
13
  import { OpenAPISchemaProperties } from './OpenAPISchema';
13
14
  import { parameterToProperty, resolveDescription } from './utils';
14
- import { OpenAPIDisclosure } from './OpenAPIDisclosure';
15
15
  /**
16
16
  * Display an interactive response body.
17
17
  */
@@ -1,9 +1,9 @@
1
- import { generateSchemaExample } from './generateSchemaExample';
2
- import { checkIsReference, createStateKey, resolveDescription } from './utils';
3
- import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
4
1
  import { InteractiveSection } from './InteractiveSection';
2
+ import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
3
+ import { generateSchemaExample } from './generateSchemaExample';
5
4
  import { json2xml } from './json2xml';
6
5
  import { stringifyOpenAPI } from './stringifyOpenAPI';
6
+ import { checkIsReference, createStateKey, resolveDescription } from './utils';
7
7
  /**
8
8
  * Display an example of the response content.
9
9
  */
@@ -1,5 +1,5 @@
1
1
  import type { OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
2
- import { OpenAPIClientContext } from './types';
2
+ import type { OpenAPIClientContext } from './types';
3
3
  /**
4
4
  * Display an interactive response body.
5
5
  */
@@ -1,7 +1,7 @@
1
- import { OpenAPIResponse } from './OpenAPIResponse';
2
1
  import { InteractiveSection } from './InteractiveSection';
3
- import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
4
2
  import { Markdown } from './Markdown';
3
+ import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
4
+ import { OpenAPIResponse } from './OpenAPIResponse';
5
5
  /**
6
6
  * Display an interactive response body.
7
7
  */
@@ -38,10 +38,14 @@ export declare function OpenAPISchemaEnum(props: {
38
38
  enumValues: any[];
39
39
  }): import("react").JSX.Element;
40
40
  export declare function OpenAPISchemaPresentation(props: OpenAPISchemaPropertyEntry): import("react").JSX.Element;
41
+ type OpenAPISchemaAlternatives = [
42
+ OpenAPIV3.SchemaObject[],
43
+ OpenAPIV3.DiscriminatorObject | undefined
44
+ ];
41
45
  /**
42
46
  * Get the alternatives to display for a schema.
43
47
  */
44
- export declare function getSchemaAlternatives(schema: OpenAPIV3.SchemaObject, ancestors?: Set<OpenAPIV3.SchemaObject>): null | [OpenAPIV3.SchemaObject[], OpenAPIV3.DiscriminatorObject | undefined];
48
+ export declare function getSchemaAlternatives(schema: OpenAPIV3.SchemaObject, ancestors?: Set<OpenAPIV3.SchemaObject>): null | OpenAPISchemaAlternatives;
45
49
  export declare function getSchemaTitle(schema: OpenAPIV3.SchemaObject,
46
50
  /** If the title is inferred in a oneOf with discriminator, we can use it to optimize the title */
47
51
  discriminator?: OpenAPIV3.DiscriminatorObject): string;
@@ -1,20 +1,11 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
1
  import clsx from 'clsx';
11
2
  import { useId } from 'react';
12
3
  import { InteractiveSection } from './InteractiveSection';
13
4
  import { Markdown } from './Markdown';
14
- import { checkIsReference, resolveDescription } from './utils';
15
- import { stringifyOpenAPI } from './stringifyOpenAPI';
16
- import { OpenAPISchemaName } from './OpenAPISchemaName';
17
5
  import { OpenAPIDisclosure } from './OpenAPIDisclosure';
6
+ import { OpenAPISchemaName } from './OpenAPISchemaName';
7
+ import { stringifyOpenAPI } from './stringifyOpenAPI';
8
+ import { checkIsReference, resolveDescription } from './utils';
18
9
  /**
19
10
  * Render a property of an OpenAPI schema.
20
11
  */
@@ -30,11 +21,7 @@ export function OpenAPISchemaProperty(props) {
30
21
  ? null
31
22
  : getSchemaAlternatives(schema, new Set(circularRefs.keys()));
32
23
  if ((_a = alternatives === null || alternatives === void 0 ? void 0 : alternatives[0]) === null || _a === void 0 ? void 0 : _a.length) {
33
- return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
34
- <OpenAPISchemaPresentation {...props}/>
35
- {alternatives[0].map(function (alternative, index) { return (<OpenAPISchemaAlternative key={"alternative-".concat(index)} schema={alternative} circularRefs={circularRefs} context={context}/>); })}
36
- {parentCircularRef ? (<OpenAPISchemaCircularRef id={parentCircularRef} schema={schema}/>) : null}
37
- </InteractiveSection>);
24
+ return (<OpenAPISchemaAlternativesItem {...props} circularRefs={circularRefs} context={context} alternatives={alternatives} parentCircularRef={parentCircularRef}/>);
38
25
  }
39
26
  if ((properties && properties.length > 0) || schema.type === 'object') {
40
27
  return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
@@ -85,10 +72,20 @@ export function OpenAPIRootSchema(props) {
85
72
  * for primitives, it renders the schema itself.
86
73
  */
87
74
  function OpenAPISchemaAlternative(props) {
75
+ var _a;
88
76
  var schema = props.schema, circularRefs = props.circularRefs, context = props.context;
89
77
  var id = useId();
90
78
  var subProperties = getSchemaProperties(schema);
91
79
  var description = resolveDescription(schema);
80
+ var alternatives = getSchemaAlternatives(schema, new Set(circularRefs === null || circularRefs === void 0 ? void 0 : circularRefs.keys()));
81
+ if (((_a = alternatives === null || alternatives === void 0 ? void 0 : alternatives[0]) === null || _a === void 0 ? void 0 : _a.length) && !(subProperties === null || subProperties === void 0 ? void 0 : subProperties.length)) {
82
+ return (<>
83
+ {description ? (<Markdown source={description} className="openapi-schema-description"/>) : null}
84
+ <OpenAPIDisclosure context={context} label={getDisclosureLabel(schema)}>
85
+ <OpenAPISchemaAlternativesItem schema={schema} circularRefs={circularRefs} context={context} alternatives={alternatives}/>
86
+ </OpenAPIDisclosure>
87
+ </>);
88
+ }
92
89
  return (<>
93
90
  {description ? (<Markdown source={description} className="openapi-schema-description"/>) : null}
94
91
  <OpenAPIDisclosure context={context} label={getDisclosureLabel(schema)}>
@@ -96,6 +93,15 @@ function OpenAPISchemaAlternative(props) {
96
93
  </OpenAPIDisclosure>
97
94
  </>);
98
95
  }
96
+ function OpenAPISchemaAlternativesItem(props) {
97
+ var id = useId();
98
+ var schema = props.schema, circularRefs = props.circularRefs, context = props.context, alternatives = props.alternatives, parentCircularRef = props.parentCircularRef;
99
+ return (<InteractiveSection id={id} className={clsx('openapi-schema')}>
100
+ <OpenAPISchemaPresentation {...props}/>
101
+ {alternatives[0].map(function (alternative, index) { return (<OpenAPISchemaAlternative key={"alternative-".concat(index)} schema={alternative} circularRefs={circularRefs} context={context}/>); })}
102
+ {parentCircularRef ? (<OpenAPISchemaCircularRef id={parentCircularRef} schema={schema}/>) : null}
103
+ </InteractiveSection>);
104
+ }
99
105
  /**
100
106
  * Render a circular reference to a schema.
101
107
  */
@@ -219,9 +225,12 @@ function flattenAlternatives(alternativeType, alternatives, ancestors) {
219
225
  return alternatives.reduce(function (acc, alternative) {
220
226
  var _a;
221
227
  if (!!alternative[alternativeType] && !ancestors.has(alternative)) {
222
- return __spreadArray(__spreadArray([], acc, true), (((_a = getSchemaAlternatives(alternative, ancestors)) === null || _a === void 0 ? void 0 : _a[0]) || []), true);
228
+ acc.push.apply(acc, (((_a = getSchemaAlternatives(alternative, ancestors)) === null || _a === void 0 ? void 0 : _a[0]) || []));
229
+ }
230
+ else {
231
+ acc.push(alternative);
223
232
  }
224
- return __spreadArray(__spreadArray([], acc, true), [alternative], false);
233
+ return acc;
225
234
  }, []);
226
235
  }
227
236
  export function getSchemaTitle(schema,
@@ -255,7 +264,7 @@ discriminator) {
255
264
  type += " \u00B7 ".concat(schema.format);
256
265
  }
257
266
  }
258
- else if ('anyOf' in schema) {
267
+ if ('anyOf' in schema) {
259
268
  type = 'any of';
260
269
  }
261
270
  else if ('oneOf' in schema) {
@@ -1,7 +1,8 @@
1
- import { OpenAPIV3 } from '@gitbook/openapi-parser';
1
+ import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
+ import type React from 'react';
2
3
  interface OpenAPISchemaNameProps {
3
4
  schema?: OpenAPIV3.SchemaObject;
4
- propertyName?: string | JSX.Element;
5
+ propertyName?: string | React.JSX.Element;
5
6
  required?: boolean;
6
7
  type?: string;
7
8
  }
@@ -9,5 +10,5 @@ interface OpenAPISchemaNameProps {
9
10
  * Display the schema name row.
10
11
  * It includes the property name, type, required and deprecated status.
11
12
  */
12
- export declare function OpenAPISchemaName(props: OpenAPISchemaNameProps): JSX.Element;
13
+ export declare function OpenAPISchemaName(props: OpenAPISchemaNameProps): React.JSX.Element;
13
14
  export {};
@@ -30,7 +30,7 @@ function getAdditionalItems(schema) {
30
30
  additionalItems += " \u00B7 default: ".concat(schema.default);
31
31
  }
32
32
  if (schema.nullable) {
33
- additionalItems = " | nullable";
33
+ additionalItems = ' | nullable';
34
34
  }
35
35
  return additionalItems;
36
36
  }
@@ -35,12 +35,12 @@ function getLabelForType(security) {
35
35
  if (security.scheme === 'basic') {
36
36
  return <OpenAPISchemaName propertyName="Authorization" type="string" required/>;
37
37
  }
38
- if (security.scheme == 'bearer') {
38
+ if (security.scheme === 'bearer') {
39
39
  var description = resolveDescription(security);
40
40
  return (<>
41
41
  <OpenAPISchemaName propertyName="Authorization" type="string" required/>
42
42
  {/** Show a default description if none is provided */}
43
- {!description ? (<Markdown source={"Bearer authentication header of the form Bearer ".concat("&lt;token&gt;", ".")} className="openapi-securities-description"/>) : null}
43
+ {!description ? (<Markdown source={"Bearer authentication header of the form Bearer ".concat('&lt;token&gt;', ".")} className="openapi-securities-description"/>) : null}
44
44
  </>);
45
45
  }
46
46
  return <OpenAPISchemaName propertyName="HTTP" required/>;
@@ -1,5 +1,5 @@
1
- import { Key, TabsProps } from 'react-aria-components';
2
- export type Tab = {
1
+ import { type Key, type TabsProps } from 'react-aria-components';
2
+ export type TabItem = {
3
3
  key: Key;
4
4
  label: string;
5
5
  body: React.ReactNode;
@@ -9,7 +9,7 @@ export type Tab = {
9
9
  * The OpenAPI Tabs wrapper component.
10
10
  */
11
11
  export declare function OpenAPITabs(props: React.PropsWithChildren<TabsProps & {
12
- items: Tab[];
12
+ items: TabItem[];
13
13
  stateKey?: string;
14
14
  }>): import("react").JSX.Element;
15
15
  /**
@@ -1,9 +1,9 @@
1
1
  'use client';
2
2
  import { createContext, useContext, useEffect, useMemo, useState } from 'react';
3
3
  import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components';
4
+ import { useIntersectionObserver } from 'usehooks-ts';
4
5
  import { Markdown } from './Markdown';
5
6
  import { useSyncedTabsGlobalState } from './useSyncedTabsGlobalState';
6
- import { useIntersectionObserver } from 'usehooks-ts';
7
7
  var OpenAPITabsContext = createContext(null);
8
8
  function useOpenAPITabsContext() {
9
9
  var context = useContext(OpenAPITabsContext);
@@ -17,23 +17,22 @@ function useOpenAPITabsContext() {
17
17
  */
18
18
  export function OpenAPITabs(props) {
19
19
  var children = props.children, items = props.items, stateKey = props.stateKey;
20
- var isVisible = stateKey
21
- ? useIntersectionObserver({
22
- threshold: 0.1,
23
- rootMargin: '200px',
24
- })
25
- : true;
20
+ var _a = useIntersectionObserver({
21
+ threshold: 0.1,
22
+ rootMargin: '200px',
23
+ }), ref = _a[0], isIntersectionVisible = _a[1];
24
+ var isVisible = stateKey ? isIntersectionVisible : true;
26
25
  var defaultTab = items[0];
27
- var _a = useSyncedTabsGlobalState(), syncedTabs = _a[0], setSyncedTabs = _a[1];
28
- var _b = useState(function () {
26
+ var _b = useSyncedTabsGlobalState(), syncedTabs = _b[0], setSyncedTabs = _b[1];
27
+ var _c = useState(function () {
29
28
  var _a, _b, _c;
30
29
  if (isVisible && stateKey && syncedTabs && syncedTabs.has(stateKey)) {
31
30
  var tabFromState = syncedTabs.get(stateKey);
32
31
  return (_a = tabFromState === null || tabFromState === void 0 ? void 0 : tabFromState.key) !== null && _a !== void 0 ? _a : (_b = items[0]) === null || _b === void 0 ? void 0 : _b.key;
33
32
  }
34
33
  return (_c = items[0]) === null || _c === void 0 ? void 0 : _c.key;
35
- }), selectedTabKey = _b[0], setSelectedTabKey = _b[1];
36
- var _c = useState(defaultTab), selectedTab = _c[0], setSelectedTab = _c[1];
34
+ }), selectedTabKey = _c[0], setSelectedTabKey = _c[1];
35
+ var _d = useState(defaultTab), selectedTab = _d[0], setSelectedTab = _d[1];
37
36
  var handleSelectionChange = function (key) {
38
37
  setSelectedTabKey(key);
39
38
  if (stateKey) {
@@ -65,7 +64,7 @@ export function OpenAPITabs(props) {
65
64
  }, [isVisible, stateKey, syncedTabs, selectedTabKey]);
66
65
  var contextValue = useMemo(function () { return ({ items: items, selectedTab: selectedTab }); }, [items, selectedTab]);
67
66
  return (<OpenAPITabsContext.Provider value={contextValue}>
68
- <Tabs className="openapi-tabs" onSelectionChange={handleSelectionChange} selectedKey={selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.key}>
67
+ <Tabs ref={ref} className="openapi-tabs" onSelectionChange={handleSelectionChange} selectedKey={selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.key}>
69
68
  {children}
70
69
  </Tabs>
71
70
  </OpenAPITabsContext.Provider>);
@@ -2,8 +2,8 @@
2
2
  import { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-react';
3
3
  import { useEffect, useImperativeHandle, useRef, useState } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
- import { useOpenAPIOperationContext } from './OpenAPIOperationContext';
6
5
  import { useEventCallback } from 'usehooks-ts';
6
+ import { useOpenAPIOperationContext } from './OpenAPIOperationContext';
7
7
  /**
8
8
  * Button which launches the Scalar API Client
9
9
  */
@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { isFormData, isPDF, isFormUrlEncoded, isText, isXML, isCSV, isGraphQL, isPlainObject, } from './contentTypeChecks';
12
+ import { isCSV, isFormData, isFormUrlEncoded, isGraphQL, isPDF, isPlainObject, isText, isXML, } from './contentTypeChecks';
13
13
  import { stringifyOpenAPI } from './stringifyOpenAPI';
14
14
  export var codeSampleGenerators = [
15
15
  {
@@ -71,8 +71,8 @@ export var codeSampleGenerators = [
71
71
  if (body) {
72
72
  code += indent("body: ".concat(body, "\n"), 4);
73
73
  }
74
- code += "});\n\n";
75
- code += "const data = await response.json();";
74
+ code += '});\n\n';
75
+ code += 'const data = await response.json();';
76
76
  return code;
77
77
  },
78
78
  },
@@ -106,7 +106,7 @@ export var codeSampleGenerators = [
106
106
  }
107
107
  }
108
108
  code += ')\n\n';
109
- code += "data = response.json()";
109
+ code += 'data = response.json()';
110
110
  return code;
111
111
  },
112
112
  },
@@ -132,12 +132,12 @@ export var codeSampleGenerators = [
132
132
  headers.Accept = '*/*';
133
133
  }
134
134
  var headerString = headers
135
- ? Object.entries(headers)
135
+ ? "".concat(Object.entries(headers)
136
136
  .map(function (_a) {
137
137
  var key = _a[0], value = _a[1];
138
- return key.toLowerCase() !== 'host' ? "".concat(key, ": ").concat(value) : "";
138
+ return key.toLowerCase() !== 'host' ? "".concat(key, ": ").concat(value) : '';
139
139
  })
140
- .join('\n') + '\n'
140
+ .join('\n'), "\n")
141
141
  : '';
142
142
  var bodyString = body ? "\n".concat(body) : '';
143
143
  var httpRequest = "".concat(method.toUpperCase(), " ").concat(decodeURI(path), " HTTP/1.1\nHost: ").concat(host, "\n").concat(headerString).concat(bodyString);
@@ -158,7 +158,7 @@ export function parseHostAndPath(url) {
158
158
  var path = urlObj.pathname || '/';
159
159
  return { host: urlObj.host, path: path };
160
160
  }
161
- catch (e) {
161
+ catch (_e) {
162
162
  // If the URL was invalid do our best to parse the URL.
163
163
  // Check for the protocol part and pull it off to grab the host
164
164
  var splitted = url.split('//');
@@ -168,7 +168,7 @@ export function parseHostAndPath(url) {
168
168
  // pull off the host (mutates)
169
169
  var host = parts.shift();
170
170
  // add a leading slash and join the paths again
171
- var path = '/' + parts.join('/');
171
+ var path = "/".concat(parts.join('/'));
172
172
  return { host: host, path: path };
173
173
  }
174
174
  }
@@ -307,7 +307,7 @@ var BodyGenerators = {
307
307
  if (isPlainObject(body)) {
308
308
  Object.entries(body).forEach(function (_a) {
309
309
  var key = _a[0], value = _a[1];
310
- code += indent("\"".concat(key, "\": \"").concat(String(value), "\","), 4) + '\n';
310
+ code += "".concat(indent("\"".concat(key, "\": \"").concat(String(value), "\","), 4), "\n");
311
311
  });
312
312
  }
313
313
  code += '}\n\n';
@@ -315,7 +315,7 @@ var BodyGenerators = {
315
315
  }
316
316
  if (isPDF(contentType)) {
317
317
  code += 'files = {\n';
318
- code += indent("\"file\": \"".concat(body, "\","), 4) + '\n';
318
+ code += "".concat(indent("\"file\": \"".concat(body, "\","), 4), "\n");
319
319
  code += '}\n\n';
320
320
  body = 'files';
321
321
  }
@@ -26,7 +26,8 @@ export function generateSchemaExample(schema, options) {
26
26
  binary: 'binary',
27
27
  byte: 'Ynl0ZXM=',
28
28
  password: 'password',
29
- } }, options), 3);
29
+ } }, options), 3 // Max depth for circular references
30
+ );
30
31
  }
31
32
  /**
32
33
  * Generate an example for a media type.
@@ -1,6 +1,6 @@
1
- import { toJSON, fromJSON } from 'flatted';
2
- import { type OpenAPIV3xDocument, type Filesystem } from '@gitbook/openapi-parser';
3
- import { OpenAPIOperationData } from './types';
1
+ import { fromJSON, toJSON } from 'flatted';
2
+ import { type Filesystem, type OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
+ import type { OpenAPIOperationData } from './types';
4
4
  export { toJSON, fromJSON };
5
5
  /**
6
6
  * Resolve an OpenAPI operation in a file and compile it to a more usable format.
@@ -54,7 +54,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
54
54
  }
55
55
  return to.concat(ar || Array.prototype.slice.call(from));
56
56
  };
57
- import { toJSON, fromJSON } from 'flatted';
57
+ import { fromJSON, toJSON } from 'flatted';
58
58
  import { dereference, } from '@gitbook/openapi-parser';
59
59
  import { checkIsReference } from './utils';
60
60
  export { toJSON, fromJSON };