@gitbook/react-openapi 1.0.3 → 1.0.5

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 (68) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/InteractiveSection.jsx +10 -9
  3. package/dist/OpenAPICodeSample.jsx +8 -9
  4. package/dist/OpenAPIDisclosure.d.ts +2 -1
  5. package/dist/OpenAPIDisclosure.jsx +2 -1
  6. package/dist/OpenAPIDisclosureGroup.d.ts +1 -1
  7. package/dist/OpenAPIDisclosureGroup.jsx +3 -2
  8. package/dist/OpenAPIOperation.jsx +2 -2
  9. package/dist/OpenAPIPath.d.ts +3 -2
  10. package/dist/OpenAPIPath.jsx +4 -15
  11. package/dist/OpenAPIRequestBody.jsx +1 -1
  12. package/dist/OpenAPIResponse.jsx +1 -1
  13. package/dist/OpenAPIResponseExample.jsx +10 -10
  14. package/dist/OpenAPIResponses.d.ts +1 -1
  15. package/dist/OpenAPIResponses.jsx +5 -5
  16. package/dist/OpenAPISchema.d.ts +5 -1
  17. package/dist/OpenAPISchema.jsx +30 -21
  18. package/dist/OpenAPISchemaName.d.ts +4 -3
  19. package/dist/OpenAPISchemaName.jsx +1 -1
  20. package/dist/OpenAPISecurities.jsx +2 -2
  21. package/dist/OpenAPISpec.jsx +3 -4
  22. package/dist/OpenAPITabs.d.ts +3 -3
  23. package/dist/OpenAPITabs.jsx +52 -49
  24. package/dist/ScalarApiButton.jsx +1 -1
  25. package/dist/StaticSection.d.ts +10 -0
  26. package/dist/StaticSection.jsx +23 -0
  27. package/dist/code-samples.js +11 -11
  28. package/dist/generateSchemaExample.js +2 -1
  29. package/dist/resolveOpenAPIOperation.d.ts +3 -3
  30. package/dist/resolveOpenAPIOperation.js +1 -1
  31. package/dist/tsconfig.build.tsbuildinfo +1 -1
  32. package/dist/useSyncedTabsGlobalState.d.ts +10 -1
  33. package/dist/useSyncedTabsGlobalState.js +19 -15
  34. package/dist/util/server.d.ts +1 -1
  35. package/dist/util/server.js +1 -3
  36. package/dist/utils.d.ts +1 -1
  37. package/dist/utils.js +4 -6
  38. package/package.json +2 -7
  39. package/src/InteractiveSection.tsx +13 -21
  40. package/src/OpenAPICodeSample.tsx +11 -12
  41. package/src/OpenAPIDisclosure.tsx +5 -3
  42. package/src/OpenAPIDisclosureGroup.tsx +13 -11
  43. package/src/OpenAPIOperation.tsx +3 -3
  44. package/src/OpenAPIOperationContext.tsx +1 -1
  45. package/src/OpenAPIPath.tsx +11 -10
  46. package/src/OpenAPIRequestBody.tsx +2 -2
  47. package/src/OpenAPIResponse.tsx +3 -3
  48. package/src/OpenAPIResponseExample.tsx +12 -19
  49. package/src/OpenAPIResponses.tsx +7 -7
  50. package/src/OpenAPISchema.test.ts +5 -5
  51. package/src/OpenAPISchema.tsx +77 -27
  52. package/src/OpenAPISchemaName.tsx +5 -4
  53. package/src/OpenAPISecurities.tsx +3 -3
  54. package/src/OpenAPISpec.tsx +3 -5
  55. package/src/OpenAPITabs.tsx +56 -67
  56. package/src/ScalarApiButton.tsx +3 -3
  57. package/src/StaticSection.tsx +59 -0
  58. package/src/code-samples.test.ts +66 -66
  59. package/src/code-samples.ts +14 -14
  60. package/src/generateSchemaExample.ts +3 -3
  61. package/src/json2xml.test.ts +1 -1
  62. package/src/resolveOpenAPIOperation.test.ts +6 -6
  63. package/src/resolveOpenAPIOperation.ts +7 -7
  64. package/src/stringifyOpenAPI.ts +1 -1
  65. package/src/useSyncedTabsGlobalState.ts +33 -21
  66. package/src/util/server.test.ts +3 -3
  67. package/src/util/server.ts +2 -3
  68. package/src/utils.ts +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @gitbook/react-openapi
2
2
 
3
+ ## 1.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [53f5dbe]
8
+ - @gitbook/openapi-parser@2.0.2
9
+
10
+ ## 1.0.4
11
+
12
+ ### Patch Changes
13
+
14
+ - 722f02e: Fix recursion in OpenAPISchemaAlternative
15
+ - Updated dependencies [0924259]
16
+ - @gitbook/openapi-parser@2.0.1
17
+
3
18
  ## 1.0.3
4
19
 
5
20
  ### Patch Changes
@@ -3,6 +3,7 @@ import clsx from 'clsx';
3
3
  import { useRef, useState } from 'react';
4
4
  import { mergeProps, useButton, useDisclosure, useFocusRing } from 'react-aria';
5
5
  import { useDisclosureState } from 'react-stately';
6
+ import { Section, SectionBody, SectionHeader, SectionHeaderContent } from './StaticSection';
6
7
  /**
7
8
  * To optimize rendering, most of the components are server-components,
8
9
  * and the interactiveness is mainly handled by a few key components like this one.
@@ -20,13 +21,13 @@ export function InteractiveSection(props) {
20
21
  var _k = useDisclosure({}, state, panelRef), triggerProps = _k.buttonProps, panelProps = _k.panelProps;
21
22
  var buttonProps = useButton(triggerProps, triggerRef).buttonProps;
22
23
  var _l = useFocusRing(), isFocusVisible = _l.isFocusVisible, focusProps = _l.focusProps;
23
- return (<div id={id} className={clsx('openapi-section', toggeable ? 'openapi-section-toggeable' : null, className, toggeable ? "".concat(className, "-").concat(state.isExpanded ? 'opened' : 'closed') : null)}>
24
- {header ? (<div onClick={function () {
24
+ return (<Section id={id} className={clsx('openapi-section', toggeable ? 'openapi-section-toggeable' : null, className, toggeable ? "".concat(className, "-").concat(state.isExpanded ? 'opened' : 'closed') : null)}>
25
+ {header ? (<SectionHeader onClick={function () {
25
26
  if (toggeable) {
26
27
  state.toggle();
27
28
  }
28
- }} className={clsx('openapi-section-header', "".concat(className, "-header"))}>
29
- <div className={clsx('openapi-section-header-content', "".concat(className, "-header-content"))}>
29
+ }} className={className}>
30
+ <SectionHeaderContent className={className}>
30
31
  {(children || (selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body)) && toggeable ? (<button {...mergeProps(buttonProps, focusProps)} ref={triggerRef} className={clsx('openapi-section-toggle', "".concat(className, "-toggle"))} style={{
31
32
  outline: isFocusVisible
32
33
  ? '2px solid rgb(var(--primary-color-500) / 0.4)'
@@ -35,7 +36,7 @@ export function InteractiveSection(props) {
35
36
  {toggleIcon}
36
37
  </button>) : null}
37
38
  {header}
38
- </div>
39
+ </SectionHeaderContent>
39
40
  <div className={clsx('openapi-section-header-controls', "".concat(className, "-header-controls"))} onClick={function (event) {
40
41
  event.stopPropagation();
41
42
  }}>
@@ -48,13 +49,13 @@ export function InteractiveSection(props) {
48
49
  </option>); })}
49
50
  </select>) : null}
50
51
  </div>
51
- </div>) : null}
52
- {(!toggeable || state.isExpanded) && (children || (selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body)) ? (<div ref={panelRef} {...panelProps} className={clsx('openapi-section-body', "".concat(className, "-body"))}>
52
+ </SectionHeader>) : null}
53
+ {(!toggeable || state.isExpanded) && (children || (selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body)) ? (<SectionBody ref={panelRef} {...panelProps} className={className}>
53
54
  {children}
54
55
  {selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body}
55
- </div>) : null}
56
+ </SectionBody>) : null}
56
57
  {overlay ? (<div className={clsx('openapi-section-overlay', "".concat(className, "-overlay"))}>
57
58
  {overlay}
58
59
  </div>) : null}
59
- </div>);
60
+ </Section>);
60
61
  }
@@ -9,14 +9,13 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
13
+ import { StaticSection } from './StaticSection';
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,
@@ -100,9 +99,9 @@ export function OpenAPICodeSample(props) {
100
99
  return null;
101
100
  }
102
101
  return (<OpenAPITabs stateKey={createStateKey('codesample')} items={samples}>
103
- <InteractiveSection header={<OpenAPITabsList />} className="openapi-codesample">
102
+ <StaticSection header={<OpenAPITabsList />} className="openapi-codesample">
104
103
  <OpenAPITabsPanels />
105
- </InteractiveSection>
104
+ </StaticSection>
106
105
  </OpenAPITabs>);
107
106
  }
108
107
  function getSecurityHeaders(securities) {
@@ -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 {};
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { useRef } from 'react';
2
3
  import { mergeProps, useButton, useDisclosure, useFocusRing } from 'react-aria';
3
4
  import { useDisclosureState } from 'react-stately';
@@ -21,7 +22,7 @@ export function OpenAPIDisclosure(_a) {
21
22
  }}>
22
23
  {context.icons.plus}
23
24
  <span>
24
- {"".concat(state.isExpanded ? 'Hide' : 'Show', " ").concat(label ? label : "child attributes")}
25
+ {"".concat(state.isExpanded ? 'Hide' : 'Show', " ").concat(label ? label : 'child attributes')}
25
26
  </span>
26
27
  </button>
27
28
 
@@ -1,3 +1,4 @@
1
+ import { type DisclosureGroupProps } from 'react-stately';
1
2
  interface Props {
2
3
  groups: TDisclosureGroup[];
3
4
  icon?: React.ReactNode;
@@ -11,7 +12,6 @@ type TDisclosureGroup = {
11
12
  body?: React.ReactNode;
12
13
  }[];
13
14
  };
14
- import { DisclosureGroupProps } from 'react-stately';
15
15
  /**
16
16
  * Display an interactive OpenAPI disclosure group.
17
17
  */
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  var __assign = (this && this.__assign) || function () {
2
3
  __assign = Object.assign || function(t) {
3
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -9,9 +10,9 @@ var __assign = (this && this.__assign) || function () {
9
10
  };
10
11
  return __assign.apply(this, arguments);
11
12
  };
13
+ import { createContext, useContext, useRef, useState } from 'react';
12
14
  import { mergeProps, useButton, useDisclosure, useFocusRing, useId } from 'react-aria';
13
15
  import { useDisclosureGroupState, useDisclosureState, } from 'react-stately';
14
- import { createContext, useContext, useRef, useState } from 'react';
15
16
  var DisclosureGroupStateContext = createContext(null);
16
17
  /**
17
18
  * Display an interactive OpenAPI disclosure group.
@@ -70,7 +71,7 @@ function DisclosureItem(props) {
70
71
  {group.tabs.map(function (tab) { return (<option key={tab.id} value={tab.id}>
71
72
  {tab.label}
72
73
  </option>); })}
73
- </select>) : !!group.tabs[0] ? (<span>{group.tabs[0].label}</span>) : null}
74
+ </select>) : group.tabs[0] ? (<span>{group.tabs[0].label}</span>) : null}
74
75
  </div>) : null}
75
76
  </div>
76
77
 
@@ -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
1
  import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
4
- import { InteractiveSection } from './InteractiveSection';
2
+ import { StaticSection } from './StaticSection';
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
  */
@@ -66,9 +66,9 @@ export function OpenAPIResponseExample(props) {
66
66
  return null;
67
67
  }
68
68
  return (<OpenAPITabs stateKey={createStateKey('response-example')} items={tabs}>
69
- <InteractiveSection header={<OpenAPITabsList />} className="openapi-response-example">
69
+ <StaticSection header={<OpenAPITabsList />} className="openapi-response-example">
70
70
  <OpenAPITabsPanels />
71
- </InteractiveSection>
71
+ </StaticSection>
72
72
  </OpenAPITabs>);
73
73
  }
74
74
  function OpenAPIResponse(props) {
@@ -91,9 +91,9 @@ function OpenAPIResponse(props) {
91
91
  };
92
92
  });
93
93
  return (<OpenAPITabs stateKey={createStateKey('response-media-types')} items={tabs}>
94
- <InteractiveSection header={<OpenAPITabsList />} className="openapi-response-media-types">
94
+ <StaticSection header={<OpenAPITabsList />} className="openapi-response-media-types">
95
95
  <OpenAPITabsPanels />
96
- </InteractiveSection>
96
+ </StaticSection>
97
97
  </OpenAPITabs>);
98
98
  }
99
99
  function OpenAPIResponseMediaType(props) {
@@ -111,13 +111,13 @@ function OpenAPIResponseMediaType(props) {
111
111
  return {
112
112
  key: example.key,
113
113
  label: example.example.summary || example.key,
114
- body: (<OpenAPIExample example={firstExample.example} context={props.context} syntax={syntax}/>),
114
+ body: (<OpenAPIExample example={example.example} context={props.context} syntax={syntax}/>),
115
115
  };
116
116
  });
117
117
  return (<OpenAPITabs stateKey={createStateKey('response-media-type-examples')} items={tabs}>
118
- <InteractiveSection header={<OpenAPITabsList />} className="openapi-response-media-type-examples">
118
+ <StaticSection header={<OpenAPITabsList />} className="openapi-response-media-type-examples">
119
119
  <OpenAPITabsPanels />
120
- </InteractiveSection>
120
+ </StaticSection>
121
121
  </OpenAPITabs>);
122
122
  }
123
123
  /**
@@ -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,13 +1,13 @@
1
- import { OpenAPIResponse } from './OpenAPIResponse';
2
- import { InteractiveSection } from './InteractiveSection';
3
- import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
4
1
  import { Markdown } from './Markdown';
2
+ import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
3
+ import { OpenAPIResponse } from './OpenAPIResponse';
4
+ import { StaticSection } from './StaticSection';
5
5
  /**
6
6
  * Display an interactive response body.
7
7
  */
8
8
  export function OpenAPIResponses(props) {
9
9
  var responses = props.responses, context = props.context;
10
- return (<InteractiveSection header="Responses" className="openapi-responses">
10
+ return (<StaticSection header="Responses" className="openapi-responses">
11
11
  <OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={Object.entries(responses).map(function (_a) {
12
12
  var _b;
13
13
  var statusCode = _a[0], response = _a[1];
@@ -31,5 +31,5 @@ export function OpenAPIResponses(props) {
31
31
  }),
32
32
  };
33
33
  })}/>
34
- </InteractiveSection>);
34
+ </StaticSection>);
35
35
  }
@@ -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)}>
@@ -64,7 +51,7 @@ export function OpenAPISchemaProperties(props) {
64
51
  return null;
65
52
  }
66
53
  return (<div id={id} className="openapi-schema-properties">
67
- {properties.map(function (property) { return (<OpenAPISchemaProperty key={property.propertyName} circularRefs={circularRefs} {...property} context={context}/>); })}
54
+ {properties.map(function (property, index) { return (<OpenAPISchemaProperty key={index} circularRefs={circularRefs} {...property} context={context}/>); })}
68
55
  </div>);
69
56
  }
70
57
  /**
@@ -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,9 +1,8 @@
1
- 'use client';
2
- import { InteractiveSection } from './InteractiveSection';
3
1
  import { OpenAPIRequestBody } from './OpenAPIRequestBody';
4
2
  import { OpenAPIResponses } from './OpenAPIResponses';
5
3
  import { OpenAPISchemaProperties } from './OpenAPISchema';
6
4
  import { OpenAPISecurities } from './OpenAPISecurities';
5
+ import { StaticSection } from './StaticSection';
7
6
  import { parameterToProperty } from './utils';
8
7
  /**
9
8
  * Client component to render the spec for the request and response.
@@ -21,9 +20,9 @@ export function OpenAPISpec(props) {
21
20
  {securities.length > 0 ? (<OpenAPISecurities securities={securities} context={context}/>) : null}
22
21
 
23
22
  {parameterGroups.map(function (group) {
24
- return (<InteractiveSection key={group.key} className="openapi-parameters" header={group.label}>
23
+ return (<StaticSection key={group.key} className="openapi-parameters" header={group.label}>
25
24
  <OpenAPISchemaProperties properties={group.parameters.map(parameterToProperty)} context={context}/>
26
- </InteractiveSection>);
25
+ </StaticSection>);
27
26
  })}
28
27
 
29
28
  {operation.requestBody ? (<OpenAPIRequestBody requestBody={operation.requestBody} context={context}/>) : null}
@@ -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
  /**