@gitbook/react-openapi 1.1.9 → 1.1.10

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 (60) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/InteractiveSection.jsx +7 -6
  3. package/dist/OpenAPICodeSample.d.ts +2 -2
  4. package/dist/OpenAPICodeSample.jsx +3 -8
  5. package/dist/OpenAPICodeSampleInteractive.jsx +31 -19
  6. package/dist/OpenAPICodeSampleSelector.d.ts +15 -0
  7. package/dist/OpenAPICodeSampleSelector.jsx +49 -0
  8. package/dist/OpenAPIExample.d.ts +34 -0
  9. package/dist/OpenAPIExample.jsx +103 -0
  10. package/dist/OpenAPIOperation.d.ts +2 -2
  11. package/dist/OpenAPIOperation.jsx +3 -7
  12. package/dist/OpenAPIPath.d.ts +10 -2
  13. package/dist/OpenAPIPath.jsx +9 -4
  14. package/dist/OpenAPIResponseExample.d.ts +2 -2
  15. package/dist/OpenAPIResponseExample.jsx +4 -95
  16. package/dist/OpenAPISchema.jsx +18 -5
  17. package/dist/OpenAPISchemaName.jsx +2 -7
  18. package/dist/OpenAPISecurities.jsx +6 -6
  19. package/dist/OpenAPISelect.d.ts +15 -0
  20. package/dist/OpenAPISelect.jsx +32 -0
  21. package/dist/OpenAPITabs.jsx +9 -9
  22. package/dist/context.d.ts +54 -0
  23. package/dist/context.js +11 -0
  24. package/dist/generateSchemaExample.js +4 -0
  25. package/dist/getOrCreateStoreByKey.d.ts +10 -0
  26. package/dist/getOrCreateStoreByKey.js +20 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/resolveOpenAPIOperation.js +10 -5
  29. package/dist/schemas/OpenAPISchemas.d.ts +5 -6
  30. package/dist/schemas/OpenAPISchemas.jsx +45 -38
  31. package/dist/schemas/resolveOpenAPISchemas.d.ts +4 -3
  32. package/dist/schemas/resolveOpenAPISchemas.js +0 -1
  33. package/dist/tsconfig.build.tsbuildinfo +1 -1
  34. package/dist/types.d.ts +32 -26
  35. package/package.json +1 -1
  36. package/src/InteractiveSection.tsx +10 -8
  37. package/src/OpenAPICodeSample.tsx +8 -15
  38. package/src/OpenAPICodeSampleInteractive.tsx +43 -26
  39. package/src/OpenAPICodeSampleSelector.tsx +87 -0
  40. package/src/OpenAPIExample.tsx +129 -0
  41. package/src/OpenAPIOperation.tsx +6 -10
  42. package/src/OpenAPIPath.tsx +23 -6
  43. package/src/OpenAPIResponseExample.tsx +13 -118
  44. package/src/OpenAPISchema.tsx +26 -9
  45. package/src/OpenAPISchemaName.tsx +2 -8
  46. package/src/OpenAPISecurities.tsx +22 -9
  47. package/src/OpenAPISelect.tsx +70 -0
  48. package/src/OpenAPITabs.tsx +9 -9
  49. package/src/context.ts +64 -0
  50. package/src/generateSchemaExample.test.ts +1020 -0
  51. package/src/generateSchemaExample.ts +5 -0
  52. package/src/getOrCreateStoreByKey.ts +35 -0
  53. package/src/index.ts +1 -1
  54. package/src/resolveOpenAPIOperation.ts +14 -3
  55. package/src/schemas/OpenAPISchemas.tsx +75 -70
  56. package/src/schemas/resolveOpenAPISchemas.ts +4 -5
  57. package/src/types.ts +36 -29
  58. package/dist/useSyncedTabsGlobalState.d.ts +0 -10
  59. package/dist/useSyncedTabsGlobalState.js +0 -20
  60. package/src/useSyncedTabsGlobalState.ts +0 -35
@@ -6,6 +6,7 @@ import { OpenAPICopyButton } from './OpenAPICopyButton';
6
6
  import { OpenAPIDisclosure } from './OpenAPIDisclosure';
7
7
  import { OpenAPISchemaName } from './OpenAPISchemaName';
8
8
  import { retrocycle } from './decycle';
9
+ import { stringifyOpenAPI } from './stringifyOpenAPI';
9
10
  import { checkIsReference, resolveDescription, resolveFirstExample } from './utils';
10
11
  /**
11
12
  * Render a property of an OpenAPI schema.
@@ -60,10 +61,14 @@ function OpenAPIRootSchema(props) {
60
61
  var schema = props.schema, context = props.context, _a = props.circularRefs, parentCircularRefs = _a === void 0 ? new Map() : _a;
61
62
  var id = useId();
62
63
  var properties = getSchemaProperties(schema);
64
+ var description = resolveDescription(schema);
63
65
  if (properties === null || properties === void 0 ? void 0 : properties.length) {
64
66
  var circularRefs = new Map(parentCircularRefs);
65
67
  circularRefs.set(schema, id);
66
- return (<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>);
68
+ return (<>
69
+ {description ? (<Markdown source={description} className="openapi-schema-root-description"/>) : null}
70
+ <OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>
71
+ </>);
67
72
  }
68
73
  return (<OpenAPISchemaProperty className="openapi-schema-root" property={{ schema: schema }} context={context} circularRefs={parentCircularRefs}/>);
69
74
  }
@@ -157,12 +162,20 @@ function OpenAPISchemaPresentation(props) {
157
162
  </span>
158
163
  </div>) : null}
159
164
  {description ? (<Markdown source={description} className="openapi-schema-description"/>) : null}
160
- {typeof example === 'string' ? (<div className="openapi-schema-example">
165
+ {schema.default !== undefined ? (<span className="openapi-schema-default">
166
+ Default:{' '}
167
+ <code>
168
+ {typeof schema.default === 'string' && schema.default
169
+ ? schema.default
170
+ : stringifyOpenAPI(schema.default)}
171
+ </code>
172
+ </span>) : null}
173
+ {typeof example === 'string' ? (<span className="openapi-schema-example">
161
174
  Example: <code>{example}</code>
162
- </div>) : null}
163
- {schema.pattern ? (<div className="openapi-schema-pattern">
175
+ </span>) : null}
176
+ {schema.pattern ? (<span className="openapi-schema-pattern">
164
177
  Pattern: <code>{schema.pattern}</code>
165
- </div>) : null}
178
+ </span>) : null}
166
179
  <OpenAPISchemaEnum schema={schema}/>
167
180
  </div>);
168
181
  }
@@ -1,4 +1,3 @@
1
- import { stringifyOpenAPI } from './stringifyOpenAPI';
2
1
  /**
3
2
  * Display the schema name row.
4
3
  * It includes the property name, type, required and deprecated status.
@@ -6,7 +5,7 @@ import { stringifyOpenAPI } from './stringifyOpenAPI';
6
5
  export function OpenAPISchemaName(props) {
7
6
  var schema = props.schema, type = props.type, propertyName = props.propertyName, required = props.required;
8
7
  var additionalItems = schema && getAdditionalItems(schema);
9
- return (<div className="openapi-schema-name">
8
+ return (<span className="openapi-schema-name">
10
9
  {propertyName ? (<span data-deprecated={schema === null || schema === void 0 ? void 0 : schema.deprecated} className="openapi-schema-propertyname">
11
10
  {propertyName}
12
11
  </span>) : null}
@@ -18,7 +17,7 @@ export function OpenAPISchemaName(props) {
18
17
  {(schema === null || schema === void 0 ? void 0 : schema.writeOnly) ? (<span className="openapi-schema-writeonly">write-only</span>) : null}
19
18
  {required ? (<span className="openapi-schema-required">required</span>) : (<span className="openapi-schema-optional">optional</span>)}
20
19
  {(schema === null || schema === void 0 ? void 0 : schema.deprecated) ? <span className="openapi-deprecated">Deprecated</span> : null}
21
- </div>);
20
+ </span>);
22
21
  }
23
22
  function getAdditionalItems(schema) {
24
23
  var additionalItems = '';
@@ -28,10 +27,6 @@ function getAdditionalItems(schema) {
28
27
  if (schema.maximum || schema.maxLength || schema.maxItems) {
29
28
  additionalItems += " \u00B7 max: ".concat(schema.maximum || schema.maxLength || schema.maxItems);
30
29
  }
31
- // If the schema has a default value, we display it
32
- if (typeof schema.default !== 'undefined') {
33
- additionalItems += " \u00B7 default: ".concat(stringifyOpenAPI(schema.default));
34
- }
35
30
  if (schema.nullable) {
36
31
  additionalItems = ' | nullable';
37
32
  }
@@ -30,24 +30,24 @@ function getLabelForType(security) {
30
30
  var _a;
31
31
  switch (security.type) {
32
32
  case 'apiKey':
33
- return (<OpenAPISchemaName propertyName={(_a = security.name) !== null && _a !== void 0 ? _a : 'apiKey'} type="string" required/>);
33
+ return (<OpenAPISchemaName propertyName={(_a = security.name) !== null && _a !== void 0 ? _a : 'apiKey'} type="string" required={security.required}/>);
34
34
  case 'http':
35
35
  if (security.scheme === 'basic') {
36
- return <OpenAPISchemaName propertyName="Authorization" type="string" required/>;
36
+ return (<OpenAPISchemaName propertyName="Authorization" type="string" required={security.required}/>);
37
37
  }
38
38
  if (security.scheme === 'bearer') {
39
39
  var description = resolveDescription(security);
40
40
  return (<>
41
- <OpenAPISchemaName propertyName="Authorization" type="string" required/>
41
+ <OpenAPISchemaName propertyName="Authorization" type="string" required={security.required}/>
42
42
  {/** Show a default description if none is provided */}
43
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
- return <OpenAPISchemaName propertyName="HTTP" required/>;
46
+ return <OpenAPISchemaName propertyName="HTTP" required={security.required}/>;
47
47
  case 'oauth2':
48
- return <OpenAPISchemaName propertyName="OAuth2" required/>;
48
+ return <OpenAPISchemaName propertyName="OAuth2" required={security.required}/>;
49
49
  case 'openIdConnect':
50
- return <OpenAPISchemaName propertyName="OpenID Connect" required/>;
50
+ return <OpenAPISchemaName propertyName="OpenID Connect" required={security.required}/>;
51
51
  default:
52
52
  // @ts-ignore
53
53
  return security.type;
@@ -0,0 +1,15 @@
1
+ import { type Key, type ListBoxItemProps, type PopoverProps, type SelectProps } from 'react-aria-components';
2
+ export type OpenAPISelectItem = {
3
+ key: Key;
4
+ label: string;
5
+ };
6
+ interface OpenAPISelectProps<T extends OpenAPISelectItem> extends Omit<SelectProps<T>, 'children'> {
7
+ items: T[];
8
+ children: React.ReactNode | ((item: T) => React.ReactNode);
9
+ selectedKey?: Key;
10
+ onChange?: (key: string | number) => void;
11
+ placement?: PopoverProps['placement'];
12
+ }
13
+ export declare function OpenAPISelect<T extends OpenAPISelectItem>(props: OpenAPISelectProps<T>): import("react").JSX.Element;
14
+ export declare function OpenAPISelectItem(props: ListBoxItemProps): import("react").JSX.Element;
15
+ export {};
@@ -0,0 +1,32 @@
1
+ 'use client';
2
+ import clsx from 'clsx';
3
+ import { Button, ListBox, ListBoxItem, Popover, Select, SelectValue, } from 'react-aria-components';
4
+ export function OpenAPISelect(props) {
5
+ var items = props.items, children = props.children, className = props.className, placement = props.placement;
6
+ return (<Select {...props} className={clsx('openapi-select', className)}>
7
+ <Button>
8
+ <SelectValue />
9
+ <span aria-hidden="true">
10
+ <svg className="gb-icon" style={{
11
+ maskImage: "url('https://ka-p.fontawesome.com/releases/v6.6.0/svgs/regular/chevron-down.svg?v=2&token=a463935e93')",
12
+ maskRepeat: 'no-repeat',
13
+ maskPosition: 'center center',
14
+ }}/>
15
+ </span>
16
+ </Button>
17
+ <Popover placement={placement} className="openapi-select-popover">
18
+ <ListBox className="openapi-select-listbox" items={items}>
19
+ {children}
20
+ </ListBox>
21
+ </Popover>
22
+ </Select>);
23
+ }
24
+ export function OpenAPISelectItem(props) {
25
+ return (<ListBoxItem {...props} className={function (_a) {
26
+ var isFocused = _a.isFocused, isSelected = _a.isSelected;
27
+ return clsx('openapi-select-item', {
28
+ 'openapi-select-item-focused': isFocused,
29
+ 'openapi-select-item-selected': isSelected,
30
+ });
31
+ }}/>);
32
+ }
@@ -2,7 +2,7 @@
2
2
  import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components';
4
4
  import { useEventCallback } from 'usehooks-ts';
5
- import { getOrCreateTabStoreByKey } from './useSyncedTabsGlobalState';
5
+ import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
6
6
  var OpenAPITabsContext = createContext(null);
7
7
  function useOpenAPITabsContext() {
8
8
  var context = useContext(OpenAPITabsContext);
@@ -20,8 +20,8 @@ export function OpenAPITabs(props) {
20
20
  var _c = useState(function () {
21
21
  var _a, _b;
22
22
  if (stateKey && typeof window !== 'undefined') {
23
- var store = getOrCreateTabStoreByKey(stateKey);
24
- var tabKey_1 = store.getState().tabKey;
23
+ var store = getOrCreateStoreByKey(stateKey);
24
+ var tabKey_1 = store.getState().key;
25
25
  if (tabKey_1) {
26
26
  return tabKey_1;
27
27
  }
@@ -44,11 +44,11 @@ export function OpenAPITabs(props) {
44
44
  if (!stateKey) {
45
45
  return undefined;
46
46
  }
47
- var store = getOrCreateTabStoreByKey(stateKey);
47
+ var store = getOrCreateStoreByKey(stateKey);
48
48
  return store.subscribe(function (state) {
49
49
  var _a;
50
50
  (_a = cancelDeferRef.current) === null || _a === void 0 ? void 0 : _a.call(cancelDeferRef);
51
- cancelDeferRef.current = defer(function () { return selectTab(state.tabKey); });
51
+ cancelDeferRef.current = defer(function () { return selectTab(state.key); });
52
52
  });
53
53
  }, [stateKey, selectTab]);
54
54
  useEffect(function () {
@@ -59,8 +59,8 @@ export function OpenAPITabs(props) {
59
59
  <Tabs className="openapi-tabs" onSelectionChange={function (tabKey) {
60
60
  selectTab(tabKey);
61
61
  if (stateKey) {
62
- var store = getOrCreateTabStoreByKey(stateKey);
63
- store.setState({ tabKey: tabKey });
62
+ var store = getOrCreateStoreByKey(stateKey);
63
+ store.setState({ key: tabKey });
64
64
  }
65
65
  }} selectedKey={tabKey}>
66
66
  {children}
@@ -103,7 +103,7 @@ export function OpenAPITabsPanels() {
103
103
  }
104
104
  var key = selectedTab.key.toString();
105
105
  return (<TabPanel id={key} className="openapi-tabs-panel">
106
- <div className="openapi-tabs-body">{selectedTab.body}</div>
107
- {selectedTab.footer ? (<div className="openapi-tabs-footer">{selectedTab.footer}</div>) : null}
106
+ <div className="openapi-panel-body">{selectedTab.body}</div>
107
+ {selectedTab.footer ? (<div className="openapi-panel-footer">{selectedTab.footer}</div>) : null}
108
108
  </TabPanel>);
109
109
  }
@@ -0,0 +1,54 @@
1
+ export interface OpenAPIClientContext {
2
+ /**
3
+ * Icons used in the block.
4
+ */
5
+ icons: {
6
+ chevronDown: React.ReactNode;
7
+ chevronRight: React.ReactNode;
8
+ plus: React.ReactNode;
9
+ };
10
+ /**
11
+ * Force all sections to be opened by default.
12
+ * @default false
13
+ */
14
+ defaultInteractiveOpened?: boolean;
15
+ /**
16
+ * The key of the block
17
+ */
18
+ blockKey?: string;
19
+ /**
20
+ * Optional id attached to the heading and used as an anchor.
21
+ */
22
+ id?: string;
23
+ }
24
+ export interface OpenAPIContext extends OpenAPIClientContext {
25
+ /**
26
+ * Render a code block.
27
+ */
28
+ renderCodeBlock: (props: {
29
+ code: string;
30
+ syntax: string;
31
+ }) => React.ReactNode;
32
+ /**
33
+ * Render the heading of the operation.
34
+ */
35
+ renderHeading: (props: {
36
+ deprecated: boolean;
37
+ title: string;
38
+ stability?: string;
39
+ }) => React.ReactNode;
40
+ /**
41
+ * Render the document of the operation.
42
+ */
43
+ renderDocument: (props: {
44
+ document: object;
45
+ }) => React.ReactNode;
46
+ /**
47
+ * Specification URL.
48
+ */
49
+ specUrl: string;
50
+ }
51
+ /**
52
+ * Get the client context from the OpenAPI context.
53
+ */
54
+ export declare function getOpenAPIClientContext(context: OpenAPIContext): OpenAPIClientContext;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Get the client context from the OpenAPI context.
3
+ */
4
+ export function getOpenAPIClientContext(context) {
5
+ return {
6
+ icons: context.icons,
7
+ defaultInteractiveOpened: context.defaultInteractiveOpened,
8
+ blockKey: context.blockKey,
9
+ id: context.id,
10
+ };
11
+ }
@@ -130,6 +130,10 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name,
130
130
  // Sometimes, we just want the structure and no values.
131
131
  // But if `emptyString` is set, we do want to see some values.
132
132
  var makeUpRandomData = !!(options === null || options === void 0 ? void 0 : options.emptyString);
133
+ // If the property is deprecated we don't show it in examples.
134
+ if (schema.deprecated) {
135
+ return undefined;
136
+ }
133
137
  // Check if the property is read-only/write-only
134
138
  if (((options === null || options === void 0 ? void 0 : options.mode) === 'write' && schema.readOnly) ||
135
139
  ((options === null || options === void 0 ? void 0 : options.mode) === 'read' && schema.writeOnly)) {
@@ -0,0 +1,10 @@
1
+ type Key = string | number;
2
+ type State = {
3
+ key: Key | null;
4
+ };
5
+ type Actions = {
6
+ setKey: (key: Key | null) => void;
7
+ };
8
+ type Store = State & Actions;
9
+ export declare const getOrCreateStoreByKey: (storeKey: string, initialKey?: Key) => import("zustand").StoreApi<Store>;
10
+ export {};
@@ -0,0 +1,20 @@
1
+ 'use client';
2
+ import { createStore } from 'zustand';
3
+ var createStateStore = function (initial) {
4
+ return createStore()(function (set) { return ({
5
+ key: initial !== null && initial !== void 0 ? initial : null,
6
+ setKey: function (key) {
7
+ set(function () { return ({ key: key }); });
8
+ },
9
+ }); });
10
+ };
11
+ var defaultStores = new Map();
12
+ var createStateStoreFactory = function (stores) {
13
+ return function (storeKey, initialKey) {
14
+ if (!stores.has(storeKey)) {
15
+ stores.set(storeKey, createStateStore(initialKey));
16
+ }
17
+ return stores.get(storeKey);
18
+ };
19
+ };
20
+ export var getOrCreateStoreByKey = createStateStoreFactory(defaultStores);
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export * from './schemas';
2
2
  export * from './OpenAPIOperation';
3
3
  export * from './OpenAPIOperationContext';
4
4
  export * from './resolveOpenAPIOperation';
5
- export type { OpenAPISchemasData, OpenAPIOperationData } from './types';
5
+ export type { OpenAPIOperationData, OpenAPIContext } from './types';
@@ -63,7 +63,7 @@ export { fromJSON, toJSON };
63
63
  */
64
64
  export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
65
65
  return __awaiter(this, void 0, void 0, function () {
66
- var path, method, schema, operation, commonParameters, servers, security, securities, _i, security_1, entry, securityKey, securityScheme;
66
+ var path, method, schema, operation, commonParameters, servers, security, isOptionalSecurity, flatSecurities, securities, _i, flatSecurities_1, entry, securityKey, securityScheme;
67
67
  var _a, _b, _c, _d, _e, _f;
68
68
  return __generator(this, function (_g) {
69
69
  switch (_g.label) {
@@ -81,15 +81,20 @@ export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
81
81
  operation = __assign(__assign({}, operation), { parameters: __spreadArray(__spreadArray([], commonParameters, true), ((_a = operation.parameters) !== null && _a !== void 0 ? _a : []), true) });
82
82
  }
83
83
  servers = 'servers' in schema ? ((_b = schema.servers) !== null && _b !== void 0 ? _b : []) : [];
84
- security = flattenSecurities((_d = (_c = operation.security) !== null && _c !== void 0 ? _c : schema.security) !== null && _d !== void 0 ? _d : []);
84
+ security = (_d = (_c = operation.security) !== null && _c !== void 0 ? _c : schema.security) !== null && _d !== void 0 ? _d : [];
85
+ isOptionalSecurity = security.some(function (entry) { return Object.keys(entry).length === 0; });
86
+ flatSecurities = flattenSecurities(security);
85
87
  securities = [];
86
- for (_i = 0, security_1 = security; _i < security_1.length; _i++) {
87
- entry = security_1[_i];
88
+ for (_i = 0, flatSecurities_1 = flatSecurities; _i < flatSecurities_1.length; _i++) {
89
+ entry = flatSecurities_1[_i];
88
90
  securityKey = Object.keys(entry)[0];
89
91
  if (securityKey) {
90
92
  securityScheme = (_f = (_e = schema.components) === null || _e === void 0 ? void 0 : _e.securitySchemes) === null || _f === void 0 ? void 0 : _f[securityKey];
91
93
  if (securityScheme && !checkIsReference(securityScheme)) {
92
- securities.push([securityKey, securityScheme]);
94
+ securities.push([
95
+ securityKey,
96
+ __assign(__assign({}, securityScheme), { required: !isOptionalSecurity }),
97
+ ]);
93
98
  }
94
99
  }
95
100
  }
@@ -1,15 +1,14 @@
1
- import type { OpenAPIContextProps, OpenAPISchemasData } from '../types';
2
- type OpenAPISchemasContextProps = Omit<OpenAPIContextProps, 'renderCodeBlock' | 'renderHeading' | 'renderDocument'>;
1
+ import type { OpenAPISchema } from '@gitbook/openapi-parser';
2
+ import type { OpenAPIContext } from '../types';
3
3
  /**
4
- * Display OpenAPI Schemas.
4
+ * OpenAPI Schemas component.
5
5
  */
6
6
  export declare function OpenAPISchemas(props: {
7
7
  className?: string;
8
- data: OpenAPISchemasData;
9
- context: OpenAPISchemasContextProps;
8
+ schemas: OpenAPISchema[];
9
+ context: OpenAPIContext;
10
10
  /**
11
11
  * Whether to show the schema directly if there is only one.
12
12
  */
13
13
  grouped?: boolean;
14
14
  }): import("react").JSX.Element | null;
15
- export {};
@@ -1,62 +1,69 @@
1
1
  import clsx from 'clsx';
2
2
  import { OpenAPIDisclosureGroup } from '../OpenAPIDisclosureGroup';
3
+ import { OpenAPIExample, getExampleFromSchema } from '../OpenAPIExample';
3
4
  import { OpenAPIRootSchema } from '../OpenAPISchemaServer';
4
- import { Section, SectionBody } from '../StaticSection';
5
+ import { Section, SectionBody, StaticSection } from '../StaticSection';
6
+ import { getOpenAPIClientContext } from '../context';
5
7
  /**
6
- * Display OpenAPI Schemas.
8
+ * OpenAPI Schemas component.
7
9
  */
8
10
  export function OpenAPISchemas(props) {
9
- var className = props.className, data = props.data, context = props.context, grouped = props.grouped;
10
- var schemas = data.schemas;
11
- var clientContext = {
12
- defaultInteractiveOpened: context.defaultInteractiveOpened,
13
- icons: context.icons,
14
- blockKey: context.blockKey,
15
- };
16
- if (!schemas.length) {
11
+ var schemas = props.schemas, context = props.context, grouped = props.grouped, className = props.className;
12
+ var firstSchema = schemas[0];
13
+ if (!firstSchema) {
17
14
  return null;
18
15
  }
19
- return (<div className={clsx('openapi-schemas', className)}>
20
- <OpenAPIRootSchemasSchema grouped={grouped} schemas={schemas} context={clientContext}/>
21
- </div>);
22
- }
23
- /**
24
- * Root schema for OpenAPI schemas.
25
- * It displays a single model or a disclosure group for multiple schemas.
26
- */
27
- function OpenAPIRootSchemasSchema(props) {
28
- var _a;
29
- var schemas = props.schemas, context = props.context, grouped = props.grouped;
16
+ var clientContext = getOpenAPIClientContext(context);
30
17
  // If there is only one model and we are not grouping, we show it directly.
31
18
  if (schemas.length === 1 && !grouped) {
32
- var schema = (_a = schemas === null || schemas === void 0 ? void 0 : schemas[0]) === null || _a === void 0 ? void 0 : _a.schema;
33
- if (!schema) {
34
- return null;
35
- }
36
- return (<Section>
37
- <SectionBody>
38
- <OpenAPIRootSchema schema={schema} context={context}/>
39
- </SectionBody>
40
- </Section>);
19
+ var title = "The ".concat(firstSchema.name, " object");
20
+ return (<div className={clsx('openapi-schemas', className)}>
21
+ <div className="openapi-summary" id={context.id}>
22
+ {context.renderHeading({
23
+ title: title,
24
+ })}
25
+ </div>
26
+ <div className="openapi-columns">
27
+ <div className="openapi-column-spec">
28
+ <StaticSection className="openapi-parameters" header="Attributes">
29
+ <OpenAPIRootSchema schema={firstSchema.schema} context={clientContext}/>
30
+ </StaticSection>
31
+ </div>
32
+ <div className="openapi-column-preview">
33
+ <div className="openapi-column-preview-body">
34
+ <div className="openapi-panel">
35
+ <h4 className="openapi-panel-heading">{title}</h4>
36
+ <div className="openapi-panel-body">
37
+ <OpenAPIExample example={getExampleFromSchema({
38
+ schema: firstSchema.schema,
39
+ })} context={context} syntax="json"/>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ </div>);
41
46
  }
42
47
  // If there are multiple schemas, we use a disclosure group to show them all.
43
- return (<OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={schemas.map(function (_a) {
48
+ return (<div className={clsx('openapi-schemas', className)}>
49
+ <OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={schemas.map(function (_a) {
44
50
  var name = _a.name, schema = _a.schema;
45
51
  return ({
46
52
  id: name,
47
53
  label: (<div className="openapi-response-tab-content" key={"model-".concat(name)}>
48
- <span className="openapi-response-statuscode">{name}</span>
49
- </div>),
54
+ <span className="openapi-response-statuscode">{name}</span>
55
+ </div>),
50
56
  tabs: [
51
57
  {
52
58
  id: 'model',
53
59
  body: (<Section className="openapi-section-schemas">
54
- <SectionBody>
55
- <OpenAPIRootSchema schema={schema} context={context}/>
56
- </SectionBody>
57
- </Section>),
60
+ <SectionBody>
61
+ <OpenAPIRootSchema schema={schema} context={clientContext}/>
62
+ </SectionBody>
63
+ </Section>),
58
64
  },
59
65
  ],
60
66
  });
61
- })}/>);
67
+ })}/>
68
+ </div>);
62
69
  }
@@ -1,9 +1,10 @@
1
- import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
2
- import type { OpenAPISchemasData } from '../types';
1
+ import type { Filesystem, OpenAPISchema, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
2
  /**
4
3
  * Resolve an OpenAPI schemas from a file and compile it to a more usable format.
5
4
  * Schemas are extracted from the OpenAPI components.schemas
6
5
  */
7
6
  export declare function resolveOpenAPISchemas(filesystem: Filesystem<OpenAPIV3xDocument>, options: {
8
7
  schemas: string[];
9
- }): Promise<OpenAPISchemasData | null>;
8
+ }): Promise<{
9
+ schemas: OpenAPISchema[];
10
+ } | null>;
@@ -36,7 +36,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import { filterSelectedOpenAPISchemas } from '@gitbook/openapi-parser';
38
38
  import { dereferenceFilesystem } from '../dereference';
39
- //!!TODO: We should return only the schemas that are used in the block. Still a WIP awaiting future work.
40
39
  /**
41
40
  * Resolve an OpenAPI schemas from a file and compile it to a more usable format.
42
41
  * Schemas are extracted from the OpenAPI components.schemas