@gitbook/react-openapi 1.1.10 → 1.2.1

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 (164) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/InteractiveSection.d.ts +4 -0
  3. package/dist/InteractiveSection.jsx +11 -11
  4. package/dist/OpenAPICodeSample.d.ts +2 -1
  5. package/dist/OpenAPICodeSample.jsx +6 -5
  6. package/dist/OpenAPICodeSampleInteractive.d.ts +3 -0
  7. package/dist/OpenAPICodeSampleInteractive.jsx +19 -43
  8. package/dist/OpenAPICodeSampleSelector.d.ts +3 -4
  9. package/dist/OpenAPICodeSampleSelector.jsx +6 -11
  10. package/dist/OpenAPICopyButton.d.ts +2 -0
  11. package/dist/OpenAPICopyButton.jsx +5 -2
  12. package/dist/OpenAPIDisclosure.d.ts +4 -3
  13. package/dist/OpenAPIDisclosure.jsx +8 -11
  14. package/dist/OpenAPIDisclosureGroup.d.ts +7 -3
  15. package/dist/OpenAPIDisclosureGroup.jsx +18 -18
  16. package/dist/OpenAPIExample.d.ts +4 -22
  17. package/dist/OpenAPIExample.jsx +5 -72
  18. package/dist/OpenAPIMediaType.d.ts +21 -0
  19. package/dist/OpenAPIMediaType.jsx +61 -0
  20. package/dist/OpenAPIOperation.d.ts +3 -2
  21. package/dist/OpenAPIOperation.jsx +9 -68
  22. package/dist/OpenAPIOperationDescription.d.ts +9 -0
  23. package/dist/OpenAPIOperationDescription.jsx +22 -0
  24. package/dist/OpenAPIOperationStability.d.ts +9 -0
  25. package/dist/OpenAPIOperationStability.jsx +27 -0
  26. package/dist/OpenAPIPath.d.ts +2 -0
  27. package/dist/OpenAPIPath.jsx +3 -2
  28. package/dist/OpenAPIRequestBody.d.ts +3 -1
  29. package/dist/OpenAPIRequestBody.jsx +4 -3
  30. package/dist/OpenAPIResponse.d.ts +1 -1
  31. package/dist/OpenAPIResponse.jsx +1 -1
  32. package/dist/OpenAPIResponseExample.d.ts +3 -2
  33. package/dist/OpenAPIResponseExample.jsx +24 -63
  34. package/dist/OpenAPIResponseExampleContent.d.ts +19 -0
  35. package/dist/OpenAPIResponseExampleContent.jsx +57 -0
  36. package/dist/OpenAPIResponses.d.ts +1 -1
  37. package/dist/OpenAPIResponses.jsx +49 -36
  38. package/dist/OpenAPISchema.d.ts +1 -1
  39. package/dist/OpenAPISchema.jsx +103 -15
  40. package/dist/OpenAPISchemaName.d.ts +2 -0
  41. package/dist/OpenAPISchemaName.jsx +19 -10
  42. package/dist/OpenAPISchemaServer.d.ts +1 -1
  43. package/dist/OpenAPISecurities.d.ts +2 -1
  44. package/dist/OpenAPISecurities.jsx +11 -10
  45. package/dist/OpenAPISelect.d.ts +10 -3
  46. package/dist/OpenAPISelect.jsx +20 -9
  47. package/dist/OpenAPISpec.d.ts +3 -2
  48. package/dist/OpenAPISpec.jsx +11 -9
  49. package/dist/OpenAPIWebhook.d.ts +10 -0
  50. package/dist/OpenAPIWebhook.jsx +23 -0
  51. package/dist/OpenAPIWebhookExample.d.ts +6 -0
  52. package/dist/OpenAPIWebhookExample.jsx +41 -0
  53. package/dist/ScalarApiButton.d.ts +2 -0
  54. package/dist/ScalarApiButton.jsx +4 -3
  55. package/dist/StaticSection.d.ts +4 -1
  56. package/dist/StaticSection.jsx +13 -4
  57. package/dist/code-samples.js +57 -39
  58. package/dist/common/OpenAPIColumnSpec.d.ts +6 -0
  59. package/dist/common/OpenAPIColumnSpec.jsx +20 -0
  60. package/dist/common/OpenAPIOperationDescription.d.ts +6 -0
  61. package/dist/common/OpenAPIOperationDescription.jsx +19 -0
  62. package/dist/common/OpenAPIStability.d.ts +4 -0
  63. package/dist/common/OpenAPIStability.jsx +15 -0
  64. package/dist/common/OpenAPISummary.d.ts +6 -0
  65. package/dist/common/OpenAPISummary.jsx +30 -0
  66. package/dist/context.d.ts +23 -2
  67. package/dist/context.js +32 -0
  68. package/dist/getOrCreateStoreByKey.d.ts +1 -1
  69. package/dist/getOrCreateStoreByKey.js +0 -1
  70. package/dist/index.d.ts +5 -1
  71. package/dist/index.js +3 -0
  72. package/dist/resolveOpenAPIWebhook.d.ts +11 -0
  73. package/dist/resolveOpenAPIWebhook.js +127 -0
  74. package/dist/schemas/OpenAPISchemas.d.ts +2 -2
  75. package/dist/schemas/OpenAPISchemas.jsx +19 -23
  76. package/dist/stringifyOpenAPI.d.ts +1 -1
  77. package/dist/stringifyOpenAPI.js +6 -3
  78. package/dist/translate.d.ts +10 -0
  79. package/dist/translate.jsx +75 -0
  80. package/dist/translations/de.d.ts +37 -0
  81. package/dist/translations/de.js +37 -0
  82. package/dist/translations/en.d.ts +37 -0
  83. package/dist/translations/en.js +37 -0
  84. package/dist/translations/es.d.ts +37 -0
  85. package/dist/translations/es.js +37 -0
  86. package/dist/translations/fr.d.ts +37 -0
  87. package/dist/translations/fr.js +37 -0
  88. package/dist/translations/index.d.ts +341 -0
  89. package/dist/translations/index.js +27 -0
  90. package/dist/translations/ja.d.ts +37 -0
  91. package/dist/translations/ja.js +37 -0
  92. package/dist/translations/nl.d.ts +37 -0
  93. package/dist/translations/nl.js +37 -0
  94. package/dist/translations/no.d.ts +37 -0
  95. package/dist/translations/no.js +37 -0
  96. package/dist/translations/pt-br.d.ts +37 -0
  97. package/dist/translations/pt-br.js +37 -0
  98. package/dist/translations/types.d.ts +5 -0
  99. package/dist/translations/types.js +1 -0
  100. package/dist/translations/zh.d.ts +37 -0
  101. package/dist/translations/zh.js +37 -0
  102. package/dist/tsconfig.build.tsbuildinfo +1 -1
  103. package/dist/types.d.ts +8 -50
  104. package/dist/util/example.d.ts +35 -0
  105. package/dist/util/example.jsx +103 -0
  106. package/dist/utils.d.ts +18 -0
  107. package/dist/utils.js +57 -0
  108. package/package.json +3 -3
  109. package/src/InteractiveSection.tsx +16 -14
  110. package/src/OpenAPICodeSample.tsx +22 -4
  111. package/src/OpenAPICodeSampleInteractive.tsx +38 -58
  112. package/src/OpenAPICodeSampleSelector.tsx +19 -12
  113. package/src/OpenAPICopyButton.tsx +7 -2
  114. package/src/OpenAPIDisclosure.tsx +20 -22
  115. package/src/OpenAPIDisclosureGroup.tsx +41 -22
  116. package/src/OpenAPIExample.tsx +8 -82
  117. package/src/OpenAPIMediaType.tsx +139 -0
  118. package/src/OpenAPIOperation.tsx +11 -100
  119. package/src/OpenAPIOperationDescription.tsx +34 -0
  120. package/src/OpenAPIOperationStability.tsx +39 -0
  121. package/src/OpenAPIPath.tsx +4 -1
  122. package/src/OpenAPIRequestBody.tsx +9 -4
  123. package/src/OpenAPIResponse.tsx +2 -2
  124. package/src/OpenAPIResponseExample.tsx +39 -108
  125. package/src/OpenAPIResponseExampleContent.tsx +123 -0
  126. package/src/OpenAPIResponses.tsx +84 -62
  127. package/src/OpenAPISchema.test.ts +80 -0
  128. package/src/OpenAPISchema.tsx +123 -16
  129. package/src/OpenAPISchemaName.tsx +26 -11
  130. package/src/OpenAPISchemaServer.tsx +1 -1
  131. package/src/OpenAPISecurities.tsx +33 -12
  132. package/src/OpenAPISelect.tsx +42 -16
  133. package/src/OpenAPISpec.tsx +21 -10
  134. package/src/OpenAPIWebhook.tsx +33 -0
  135. package/src/OpenAPIWebhookExample.tsx +60 -0
  136. package/src/ScalarApiButton.tsx +6 -6
  137. package/src/StaticSection.tsx +37 -5
  138. package/src/code-samples.test.ts +3 -1
  139. package/src/code-samples.ts +67 -54
  140. package/src/common/OpenAPIColumnSpec.tsx +31 -0
  141. package/src/common/OpenAPIOperationDescription.tsx +31 -0
  142. package/src/common/OpenAPIStability.tsx +23 -0
  143. package/src/common/OpenAPISummary.tsx +45 -0
  144. package/src/context.ts +37 -2
  145. package/src/getOrCreateStoreByKey.ts +1 -3
  146. package/src/index.ts +5 -1
  147. package/src/resolveOpenAPIWebhook.ts +99 -0
  148. package/src/schemas/OpenAPISchemas.tsx +34 -34
  149. package/src/stringifyOpenAPI.ts +11 -3
  150. package/src/translate.tsx +80 -0
  151. package/src/translations/de.ts +37 -0
  152. package/src/translations/en.ts +37 -0
  153. package/src/translations/es.ts +37 -0
  154. package/src/translations/fr.ts +37 -0
  155. package/src/translations/index.ts +33 -0
  156. package/src/translations/ja.ts +37 -0
  157. package/src/translations/nl.ts +37 -0
  158. package/src/translations/no.ts +37 -0
  159. package/src/translations/pt-br.ts +37 -0
  160. package/src/translations/types.ts +7 -0
  161. package/src/translations/zh.ts +37 -0
  162. package/src/types.ts +11 -53
  163. package/src/util/example.tsx +129 -0
  164. package/src/utils.ts +67 -0
@@ -0,0 +1,57 @@
1
+ 'use client';
2
+ import clsx from 'clsx';
3
+ import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
4
+ import { StaticSection } from './StaticSection';
5
+ import { createStateKey, getStatusCodeClassName } from './utils';
6
+ /**
7
+ * Get the state of the response examples select.
8
+ */
9
+ export function useResponseExamplesState(blockKey, initialKey) {
10
+ if (initialKey === void 0) { initialKey = 'default'; }
11
+ return useSelectState(getResponseExampleStateKey(blockKey), initialKey);
12
+ }
13
+ export function OpenAPIResponseExampleContent(props) {
14
+ var blockKey = props.blockKey, items = props.items, selectIcon = props.selectIcon;
15
+ return (<StaticSection header={<OpenAPIResponseExampleHeader selectIcon={selectIcon} blockKey={blockKey} items={items}/>} className="openapi-response-examples">
16
+ <OpenAPIResponseExampleBody blockKey={blockKey} items={items}/>
17
+ </StaticSection>);
18
+ }
19
+ function OpenAPIResponseExampleHeader(props) {
20
+ var items = props.items, blockKey = props.blockKey, selectIcon = props.selectIcon;
21
+ if (items.length === 1) {
22
+ var item = items[0];
23
+ if (!item) {
24
+ return null;
25
+ }
26
+ return (<span className="openapi-response-examples-statuscode-title">
27
+ <span className={clsx('openapi-statuscode', "openapi-statuscode-".concat(getStatusCodeClassName(item.statusCode)), 'openapi-response-examples-statuscode')}>
28
+ {item.statusCode}
29
+ </span>
30
+ <span>{item.label}</span>
31
+ </span>);
32
+ }
33
+ return (<OpenAPISelect items={items} icon={selectIcon} stateKey={getResponseExampleStateKey(blockKey)} placement="bottom start">
34
+ {items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
35
+ <span className={clsx('openapi-statuscode', "openapi-statuscode-".concat(getStatusCodeClassName(item.statusCode)), 'openapi-response-examples-statuscode')}>
36
+ {item.statusCode}
37
+ </span>
38
+ <span>{item.label}</span>
39
+ </OpenAPISelectItem>); })}
40
+ </OpenAPISelect>);
41
+ }
42
+ function OpenAPIResponseExampleBody(props) {
43
+ var _a, _b;
44
+ var blockKey = props.blockKey, items = props.items;
45
+ var state = useResponseExamplesState(blockKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
46
+ var selectedItem = (_b = items.find(function (item) { return item.key === state.key; })) !== null && _b !== void 0 ? _b : items[0];
47
+ if (!selectedItem) {
48
+ return null;
49
+ }
50
+ return <div className="openapi-response-examples-panel">{selectedItem.body}</div>;
51
+ }
52
+ /**
53
+ * Return the state key for the response examples.
54
+ */
55
+ function getResponseExampleStateKey(blockKey) {
56
+ return createStateKey('openapi-responses', blockKey);
57
+ }
@@ -1,5 +1,5 @@
1
1
  import type { OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './types';
2
+ import type { OpenAPIClientContext } from './context';
3
3
  /**
4
4
  * Display an interactive response body.
5
5
  */
@@ -1,48 +1,61 @@
1
+ 'use client';
2
+ import clsx from 'clsx';
1
3
  import { Markdown } from './Markdown';
2
4
  import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
3
5
  import { OpenAPIResponse } from './OpenAPIResponse';
6
+ import { useResponseExamplesState } from './OpenAPIResponseExampleContent';
4
7
  import { StaticSection } from './StaticSection';
8
+ import { t } from './translate';
9
+ import { createStateKey, getStatusCodeClassName, getStatusCodeDefaultLabel } from './utils';
5
10
  /**
6
11
  * Display an interactive response body.
7
12
  */
8
13
  export function OpenAPIResponses(props) {
14
+ var _a;
9
15
  var responses = props.responses, context = props.context;
10
- return (<StaticSection header="Responses" className="openapi-responses">
11
- <OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={Object.entries(responses).map(function (_a) {
12
- var statusCode = _a[0], response = _a[1];
13
- var tabs = (function () {
14
- var _a;
15
- // If there is no content, but there are headers, we need to show the headers
16
- if ((!response.content || !Object.keys(response.content).length) &&
17
- response.headers &&
18
- Object.keys(response.headers).length) {
19
- return [
20
- {
21
- id: 'default',
22
- body: (<OpenAPIResponse response={response} mediaType={{}} context={context}/>),
23
- },
24
- ];
25
- }
26
- return Object.entries((_a = response.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
27
- var contentType = _a[0], mediaType = _a[1];
28
- return ({
29
- id: contentType,
30
- label: contentType,
31
- body: (<OpenAPIResponse response={response} mediaType={mediaType} context={context}/>),
32
- });
16
+ var groups = Object.entries(responses).map(function (_a) {
17
+ var statusCode = _a[0], response = _a[1];
18
+ var tabs = (function () {
19
+ var _a;
20
+ // If there is no content, but there are headers, we need to show the headers
21
+ if ((!response.content || !Object.keys(response.content).length) &&
22
+ response.headers &&
23
+ Object.keys(response.headers).length) {
24
+ return [
25
+ {
26
+ key: 'default',
27
+ label: '',
28
+ body: (<OpenAPIResponse response={response} mediaType={{}} context={context}/>),
29
+ },
30
+ ];
31
+ }
32
+ return Object.entries((_a = response.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
33
+ var contentType = _a[0], mediaType = _a[1];
34
+ return ({
35
+ key: contentType,
36
+ label: contentType,
37
+ body: (<OpenAPIResponse response={response} mediaType={mediaType} context={context}/>),
33
38
  });
34
- })();
35
- var description = response.description;
36
- return {
37
- id: statusCode,
38
- label: (<div className="openapi-response-tab-content">
39
- <span className="openapi-response-statuscode">
40
- {statusCode}
41
- </span>
42
- {description ? (<Markdown source={description} className="openapi-response-description"/>) : null}
43
- </div>),
44
- tabs: tabs,
45
- };
46
- })}/>
39
+ });
40
+ })();
41
+ var description = response.description;
42
+ return {
43
+ key: statusCode,
44
+ label: (<div className="openapi-response-tab-content">
45
+ <span className={clsx('openapi-statuscode', "openapi-statuscode-".concat(getStatusCodeClassName(statusCode)))}>
46
+ {statusCode}
47
+ </span>
48
+ {description ? (<Markdown source={description} className="openapi-response-description"/>) : (getStatusCodeDefaultLabel(statusCode, context))}
49
+ </div>),
50
+ tabs: tabs,
51
+ };
52
+ });
53
+ var state = useResponseExamplesState(context.blockKey, (_a = groups[0]) === null || _a === void 0 ? void 0 : _a.key);
54
+ return (<StaticSection header={t(context.translation, 'responses')} className="openapi-responses">
55
+ <OpenAPIDisclosureGroup icon={context.icons.chevronRight} expandedKeys={state.key ? new Set([state.key]) : new Set()} onExpandedChange={function (keys) {
56
+ var _a;
57
+ var key = (_a = keys.values().next().value) !== null && _a !== void 0 ? _a : null;
58
+ state.setKey(key);
59
+ }} groups={groups} selectIcon={context.icons.chevronDown} selectStateKey={createStateKey('response-media-types', context.blockKey)}/>
47
60
  </StaticSection>);
48
61
  }
@@ -1,5 +1,5 @@
1
1
  import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './types';
2
+ import type { OpenAPIClientContext } from './context';
3
3
  export interface OpenAPISchemaPropertyEntry {
4
4
  propertyName?: string | undefined;
5
5
  required?: boolean | undefined;
@@ -1,4 +1,24 @@
1
1
  'use client';
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
2
22
  import { useId } from 'react';
3
23
  import clsx from 'clsx';
4
24
  import { Markdown } from './Markdown';
@@ -7,6 +27,7 @@ import { OpenAPIDisclosure } from './OpenAPIDisclosure';
7
27
  import { OpenAPISchemaName } from './OpenAPISchemaName';
8
28
  import { retrocycle } from './decycle';
9
29
  import { stringifyOpenAPI } from './stringifyOpenAPI';
30
+ import { tString } from './translate';
10
31
  import { checkIsReference, resolveDescription, resolveFirstExample } from './utils';
11
32
  /**
12
33
  * Render a property of an OpenAPI schema.
@@ -16,7 +37,7 @@ function OpenAPISchemaProperty(props) {
16
37
  var schema = property.schema;
17
38
  var id = useId();
18
39
  return (<div id={id} className={clsx('openapi-schema', className)}>
19
- <OpenAPISchemaPresentation property={property}/>
40
+ <OpenAPISchemaPresentation context={context} property={property}/>
20
41
  {(function () {
21
42
  var circularRefId = parentCircularRefs.get(schema);
22
43
  // Avoid recursing infinitely, and instead render a link to the parent schema
@@ -27,7 +48,9 @@ function OpenAPISchemaProperty(props) {
27
48
  circularRefs.set(schema, id);
28
49
  var properties = getSchemaProperties(schema);
29
50
  if (properties === null || properties === void 0 ? void 0 : properties.length) {
30
- return (<OpenAPIDisclosure context={context} label={getDisclosureLabel(schema)}>
51
+ return (<OpenAPIDisclosure icon={context.icons.plus} label={function (isExpanded) {
52
+ return getDisclosureLabel({ schema: schema, isExpanded: isExpanded, context: context });
53
+ }}>
31
54
  <OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>
32
55
  </OpenAPIDisclosure>);
33
56
  }
@@ -86,7 +109,7 @@ function OpenAPISchemaAlternative(props) {
86
109
  var properties = getSchemaProperties(schema);
87
110
  return (<>
88
111
  {description ? (<Markdown source={description} className="openapi-schema-description"/>) : null}
89
- <OpenAPIDisclosure context={context} label={getDisclosureLabel(schema)}>
112
+ <OpenAPIDisclosure icon={context.icons.plus} label={function (isExpanded) { return getDisclosureLabel({ schema: schema, isExpanded: isExpanded, context: context }); }}>
90
113
  {(properties === null || properties === void 0 ? void 0 : properties.length) ? (<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>) : (<OpenAPISchemaProperty property={{ schema: schema }} circularRefs={circularRefs} context={context}/>)}
91
114
  </OpenAPIDisclosure>
92
115
  </>);
@@ -105,7 +128,7 @@ function OpenAPISchemaCircularRef(props) {
105
128
  * Render the enum value for a schema.
106
129
  */
107
130
  function OpenAPISchemaEnum(props) {
108
- var schema = props.schema;
131
+ var schema = props.schema, context = props.context;
109
132
  var enumValues = (function () {
110
133
  var _a;
111
134
  // Render x-gitbook-enum first, as it has a different format
@@ -140,7 +163,7 @@ function OpenAPISchemaEnum(props) {
140
163
  return (<span className="openapi-schema-enum">
141
164
  Available options:{' '}
142
165
  {enumValues.map(function (item, index) { return (<span key={index} className="openapi-schema-enum-value">
143
- <OpenAPICopyButton value={item.value} label={item.description} withTooltip={!!item.description}>
166
+ <OpenAPICopyButton value={item.value} label={item.description} withTooltip={!!item.description} context={context}>
144
167
  <code>{"".concat(item.value)}</code>
145
168
  </OpenAPICopyButton>
146
169
  </span>); })}
@@ -150,11 +173,11 @@ function OpenAPISchemaEnum(props) {
150
173
  * Render the top row of a schema. e.g: name, type, and required status.
151
174
  */
152
175
  function OpenAPISchemaPresentation(props) {
153
- var _a = props.property, schema = _a.schema, propertyName = _a.propertyName, required = _a.required;
176
+ var _a = props.property, schema = _a.schema, propertyName = _a.propertyName, required = _a.required, context = props.context;
154
177
  var description = resolveDescription(schema);
155
178
  var example = resolveFirstExample(schema);
156
179
  return (<div className="openapi-schema-presentation">
157
- <OpenAPISchemaName schema={schema} type={getSchemaTitle(schema)} propertyName={propertyName} required={required}/>
180
+ <OpenAPISchemaName schema={schema} type={getSchemaTitle(schema)} propertyName={propertyName} required={required} context={context}/>
158
181
  {typeof schema['x-deprecated-sunset'] === 'string' ? (<div className="openapi-deprecated-sunset openapi-schema-description openapi-markdown">
159
182
  Sunset date:{' '}
160
183
  <span className="openapi-deprecated-sunset-date">
@@ -176,7 +199,7 @@ function OpenAPISchemaPresentation(props) {
176
199
  {schema.pattern ? (<span className="openapi-schema-pattern">
177
200
  Pattern: <code>{schema.pattern}</code>
178
201
  </span>) : null}
179
- <OpenAPISchemaEnum schema={schema}/>
202
+ <OpenAPISchemaEnum schema={schema} context={context}/>
180
203
  </div>);
181
204
  }
182
205
  /**
@@ -248,7 +271,65 @@ export function getSchemaAlternatives(schema, ancestors) {
248
271
  return null;
249
272
  }
250
273
  var type = alternatives[0], schemas = alternatives[1];
251
- return flattenAlternatives(type, schemas, new Set(ancestors).add(schema));
274
+ return mergeAlternatives(type, flattenAlternatives(type, schemas, new Set(ancestors).add(schema)));
275
+ }
276
+ /**
277
+ * Merge alternatives of the same type into a single schema.
278
+ * - Merge string enums
279
+ */
280
+ function mergeAlternatives(alternativeType, schemasOrRefs) {
281
+ switch (alternativeType) {
282
+ case 'oneOf': {
283
+ return schemasOrRefs.reduce(function (acc, schemaOrRef) {
284
+ var latest = acc.at(-1);
285
+ if (latest &&
286
+ latest.type === 'string' &&
287
+ latest.enum &&
288
+ schemaOrRef.type === 'string' &&
289
+ schemaOrRef.enum) {
290
+ latest.enum = Array.from(new Set(__spreadArray(__spreadArray([], latest.enum, true), schemaOrRef.enum, true)));
291
+ latest.nullable = latest.nullable || schemaOrRef.nullable;
292
+ return acc;
293
+ }
294
+ acc.push(schemaOrRef);
295
+ return acc;
296
+ }, []);
297
+ }
298
+ case 'allOf': {
299
+ return schemasOrRefs.reduce(function (acc, schemaOrRef) {
300
+ var latest = acc.at(-1);
301
+ if (latest &&
302
+ latest.type === 'string' &&
303
+ latest.enum &&
304
+ schemaOrRef.type === 'string' &&
305
+ schemaOrRef.enum) {
306
+ var keys = Object.keys(schemaOrRef);
307
+ if (keys.every(function (key) { return ['type', 'enum', 'nullable'].includes(key); })) {
308
+ latest.enum = Array.from(new Set(__spreadArray(__spreadArray([], latest.enum, true), schemaOrRef.enum, true)));
309
+ latest.nullable = latest.nullable || schemaOrRef.nullable;
310
+ return acc;
311
+ }
312
+ }
313
+ if (latest && latest.type === 'object' && schemaOrRef.type === 'object') {
314
+ var keys = Object.keys(schemaOrRef);
315
+ if (keys.every(function (key) {
316
+ return ['type', 'properties', 'required', 'nullable'].includes(key);
317
+ })) {
318
+ latest.properties = __assign(__assign({}, latest.properties), schemaOrRef.properties);
319
+ latest.required = Array.from(new Set(__spreadArray(__spreadArray([], (Array.isArray(latest.required) ? latest.required : []), true), (Array.isArray(schemaOrRef.required)
320
+ ? schemaOrRef.required
321
+ : []), true)));
322
+ latest.nullable = latest.nullable || schemaOrRef.nullable;
323
+ return acc;
324
+ }
325
+ }
326
+ acc.push(schemaOrRef);
327
+ return acc;
328
+ }, []);
329
+ }
330
+ default:
331
+ return schemasOrRefs;
332
+ }
252
333
  }
253
334
  function flattenAlternatives(alternativeType, schemasOrRefs, ancestors) {
254
335
  return schemasOrRefs.reduce(function (acc, schemaOrRef) {
@@ -300,17 +381,24 @@ function getSchemaTitle(schema) {
300
381
  }
301
382
  return type;
302
383
  }
303
- function getDisclosureLabel(schema) {
384
+ function getDisclosureLabel(props) {
304
385
  var _a, _b;
386
+ var schema = props.schema, isExpanded = props.isExpanded, context = props.context;
387
+ var label;
305
388
  if (schema.type === 'array' && !!schema.items) {
306
389
  if (schema.items.oneOf) {
307
- return 'available items';
390
+ label = tString(context.translation, 'available_items').toLowerCase();
308
391
  }
309
392
  // Fallback to "child attributes" for enums and objects
310
- if (schema.items.enum || schema.items.type === 'object') {
311
- return 'child attributes';
393
+ else if (schema.items.enum || schema.items.type === 'object') {
394
+ label = tString(context.translation, 'child_attributes').toLowerCase();
395
+ }
396
+ else {
397
+ label = (_b = (_a = schema.items.title) !== null && _a !== void 0 ? _a : schema.title) !== null && _b !== void 0 ? _b : getSchemaTitle(schema.items);
312
398
  }
313
- return (_b = (_a = schema.items.title) !== null && _a !== void 0 ? _a : schema.title) !== null && _b !== void 0 ? _b : getSchemaTitle(schema.items);
314
399
  }
315
- return schema.title || 'child attributes';
400
+ else {
401
+ label = schema.title || tString(context.translation, 'child_attributes').toLowerCase();
402
+ }
403
+ return "".concat(isExpanded ? tString(context.translation, 'hide') : tString(context.translation, 'show'), " ").concat(label);
316
404
  }
@@ -1,10 +1,12 @@
1
1
  import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
2
  import type React from 'react';
3
+ import type { OpenAPIClientContext } from './context';
3
4
  interface OpenAPISchemaNameProps {
4
5
  schema?: OpenAPIV3.SchemaObject;
5
6
  propertyName?: string | React.JSX.Element;
6
7
  required?: boolean;
7
8
  type?: string;
9
+ context: OpenAPIClientContext;
8
10
  }
9
11
  /**
10
12
  * Display the schema name row.
@@ -1,10 +1,11 @@
1
+ import { t, tString } from './translate';
1
2
  /**
2
3
  * Display the schema name row.
3
4
  * It includes the property name, type, required and deprecated status.
4
5
  */
5
6
  export function OpenAPISchemaName(props) {
6
- var schema = props.schema, type = props.type, propertyName = props.propertyName, required = props.required;
7
- var additionalItems = schema && getAdditionalItems(schema);
7
+ var schema = props.schema, type = props.type, propertyName = props.propertyName, required = props.required, context = props.context;
8
+ var additionalItems = schema && getAdditionalItems(schema, context);
8
9
  return (<span className="openapi-schema-name">
9
10
  {propertyName ? (<span data-deprecated={schema === null || schema === void 0 ? void 0 : schema.deprecated} className="openapi-schema-propertyname">
10
11
  {propertyName}
@@ -13,22 +14,30 @@ export function OpenAPISchemaName(props) {
13
14
  {type ? <span className="openapi-schema-type">{type}</span> : null}
14
15
  {additionalItems ? (<span className="openapi-schema-type">{additionalItems}</span>) : null}
15
16
  </span>
16
- {(schema === null || schema === void 0 ? void 0 : schema.readOnly) ? <span className="openapi-schema-readonly">read-only</span> : null}
17
- {(schema === null || schema === void 0 ? void 0 : schema.writeOnly) ? (<span className="openapi-schema-writeonly">write-only</span>) : null}
18
- {required ? (<span className="openapi-schema-required">required</span>) : (<span className="openapi-schema-optional">optional</span>)}
19
- {(schema === null || schema === void 0 ? void 0 : schema.deprecated) ? <span className="openapi-deprecated">Deprecated</span> : null}
17
+ {(schema === null || schema === void 0 ? void 0 : schema.readOnly) ? (<span className="openapi-schema-readonly">
18
+ {t(context.translation, 'read_only')}
19
+ </span>) : null}
20
+ {(schema === null || schema === void 0 ? void 0 : schema.writeOnly) ? (<span className="openapi-schema-writeonly">
21
+ {t(context.translation, 'write_only')}
22
+ </span>) : null}
23
+ {required ? (<span className="openapi-schema-required">
24
+ {t(context.translation, 'required')}
25
+ </span>) : (<span className="openapi-schema-optional">
26
+ {t(context.translation, 'optional')}
27
+ </span>)}
28
+ {(schema === null || schema === void 0 ? void 0 : schema.deprecated) ? (<span className="openapi-deprecated">{t(context.translation, 'deprecated')}</span>) : null}
20
29
  </span>);
21
30
  }
22
- function getAdditionalItems(schema) {
31
+ function getAdditionalItems(schema, context) {
23
32
  var additionalItems = '';
24
33
  if (schema.minimum || schema.minLength || schema.minItems) {
25
- additionalItems += " \u00B7 min: ".concat(schema.minimum || schema.minLength || schema.minItems);
34
+ additionalItems += " \u00B7 ".concat(tString(context.translation, 'min').toLowerCase(), ": ").concat(schema.minimum || schema.minLength || schema.minItems);
26
35
  }
27
36
  if (schema.maximum || schema.maxLength || schema.maxItems) {
28
- additionalItems += " \u00B7 max: ".concat(schema.maximum || schema.maxLength || schema.maxItems);
37
+ additionalItems += " \u00B7 ".concat(tString(context.translation, 'max').toLowerCase(), ": ").concat(schema.maximum || schema.maxLength || schema.maxItems);
29
38
  }
30
39
  if (schema.nullable) {
31
- additionalItems = ' | nullable';
40
+ additionalItems = " | ".concat(tString(context.translation, 'nullable').toLowerCase());
32
41
  }
33
42
  return additionalItems;
34
43
  }
@@ -1,6 +1,6 @@
1
1
  import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
2
  import { type OpenAPISchemaPropertyEntry } from './OpenAPISchema';
3
- import type { OpenAPIClientContext } from './types';
3
+ import type { OpenAPIClientContext } from './context';
4
4
  export declare function OpenAPISchemaProperties(props: {
5
5
  id?: string;
6
6
  properties: OpenAPISchemaPropertyEntry[];
@@ -1,4 +1,5 @@
1
- import type { OpenAPIClientContext, OpenAPIOperationData } from './types';
1
+ import type { OpenAPIClientContext } from './context';
2
+ import type { OpenAPIOperationData } from './types';
2
3
  /**
3
4
  * Present securities authorization that can be used for this operation.
4
5
  */
@@ -1,7 +1,8 @@
1
1
  import { InteractiveSection } from './InteractiveSection';
2
2
  import { Markdown } from './Markdown';
3
3
  import { OpenAPISchemaName } from './OpenAPISchemaName';
4
- import { resolveDescription } from './utils';
4
+ import { t } from './translate';
5
+ import { createStateKey, resolveDescription } from './utils';
5
6
  /**
6
7
  * Present securities authorization that can be used for this operation.
7
8
  */
@@ -10,7 +11,7 @@ export function OpenAPISecurities(props) {
10
11
  if (securities.length === 0) {
11
12
  return null;
12
13
  }
13
- return (<InteractiveSection header="Authorizations" toggeable defaultOpened={false} toggleIcon={context.icons.chevronRight} className="openapi-securities" tabs={securities.map(function (_a) {
14
+ return (<InteractiveSection header={t(context.translation, 'authorizations')} stateKey={createStateKey('securities', context.blockKey)} toggeable defaultOpened={false} toggleIcon={context.icons.chevronRight} selectIcon={context.icons.chevronDown} className="openapi-securities" tabs={securities.map(function (_a) {
14
15
  var key = _a[0], security = _a[1];
15
16
  var description = resolveDescription(security);
16
17
  return {
@@ -18,7 +19,7 @@ export function OpenAPISecurities(props) {
18
19
  label: key,
19
20
  body: (<div className="openapi-schema">
20
21
  <div className="openapi-schema-presentation">
21
- {getLabelForType(security)}
22
+ {getLabelForType(security, context)}
22
23
 
23
24
  {description ? (<Markdown source={description} className="openapi-securities-description"/>) : null}
24
25
  </div>
@@ -26,28 +27,28 @@ export function OpenAPISecurities(props) {
26
27
  };
27
28
  })}/>);
28
29
  }
29
- function getLabelForType(security) {
30
+ function getLabelForType(security, context) {
30
31
  var _a;
31
32
  switch (security.type) {
32
33
  case 'apiKey':
33
- return (<OpenAPISchemaName propertyName={(_a = security.name) !== null && _a !== void 0 ? _a : 'apiKey'} type="string" required={security.required}/>);
34
+ return (<OpenAPISchemaName context={context} propertyName={(_a = security.name) !== null && _a !== void 0 ? _a : 'apiKey'} type="string" required={security.required}/>);
34
35
  case 'http':
35
36
  if (security.scheme === 'basic') {
36
- return (<OpenAPISchemaName propertyName="Authorization" type="string" required={security.required}/>);
37
+ return (<OpenAPISchemaName context={context} propertyName="Authorization" type="string" required={security.required}/>);
37
38
  }
38
39
  if (security.scheme === 'bearer') {
39
40
  var description = resolveDescription(security);
40
41
  return (<>
41
- <OpenAPISchemaName propertyName="Authorization" type="string" required={security.required}/>
42
+ <OpenAPISchemaName context={context} propertyName="Authorization" type="string" required={security.required}/>
42
43
  {/** Show a default description if none is provided */}
43
44
  {!description ? (<Markdown source={"Bearer authentication header of the form Bearer ".concat('&lt;token&gt;', ".")} className="openapi-securities-description"/>) : null}
44
45
  </>);
45
46
  }
46
- return <OpenAPISchemaName propertyName="HTTP" required={security.required}/>;
47
+ return (<OpenAPISchemaName context={context} propertyName="HTTP" required={security.required}/>);
47
48
  case 'oauth2':
48
- return <OpenAPISchemaName propertyName="OAuth2" required={security.required}/>;
49
+ return (<OpenAPISchemaName context={context} propertyName="OAuth2" required={security.required}/>);
49
50
  case 'openIdConnect':
50
- return <OpenAPISchemaName propertyName="OpenID Connect" required={security.required}/>;
51
+ return (<OpenAPISchemaName context={context} propertyName="OpenID Connect" required={security.required}/>);
51
52
  default:
52
53
  // @ts-ignore
53
54
  return security.type;
@@ -1,15 +1,22 @@
1
1
  import { type Key, type ListBoxItemProps, type PopoverProps, type SelectProps } from 'react-aria-components';
2
2
  export type OpenAPISelectItem = {
3
3
  key: Key;
4
- label: string;
4
+ label: string | React.ReactNode;
5
5
  };
6
6
  interface OpenAPISelectProps<T extends OpenAPISelectItem> extends Omit<SelectProps<T>, 'children'> {
7
7
  items: T[];
8
8
  children: React.ReactNode | ((item: T) => React.ReactNode);
9
- selectedKey?: Key;
10
- onChange?: (key: string | number) => void;
11
9
  placement?: PopoverProps['placement'];
10
+ stateKey?: string;
11
+ /**
12
+ * Icon to display in the select button.
13
+ */
14
+ icon?: React.ReactNode;
12
15
  }
16
+ export declare function useSelectState(stateKey?: string, initialKey?: Key): {
17
+ key: (string | number) | null;
18
+ setKey: (key: Key | null) => void;
19
+ };
13
20
  export declare function OpenAPISelect<T extends OpenAPISelectItem>(props: OpenAPISelectProps<T>): import("react").JSX.Element;
14
21
  export declare function OpenAPISelectItem(props: ListBoxItemProps): import("react").JSX.Element;
15
22
  export {};
@@ -1,18 +1,29 @@
1
1
  'use client';
2
2
  import clsx from 'clsx';
3
+ import { useCallback } from 'react';
3
4
  import { Button, ListBox, ListBoxItem, Popover, Select, SelectValue, } from 'react-aria-components';
5
+ import { useStore } from 'zustand';
6
+ import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
7
+ export function useSelectState(stateKey, initialKey) {
8
+ if (stateKey === void 0) { stateKey = 'select-state'; }
9
+ var store = useStore(getOrCreateStoreByKey(stateKey, initialKey));
10
+ return {
11
+ key: store.key,
12
+ setKey: useCallback(function (key) { return store.setKey(key); }, [store.setKey]),
13
+ };
14
+ }
4
15
  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)}>
16
+ var _a;
17
+ var _b = props.icon, icon = _b === void 0 ? '' : _b, items = props.items, children = props.children, className = props.className, placement = props.placement, stateKey = props.stateKey, selectedKey = props.selectedKey, onSelectionChange = props.onSelectionChange;
18
+ var state = useSelectState(stateKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
19
+ var selected = items.find(function (item) { return item.key === state.key; }) || items[0];
20
+ return (<Select aria-label="OpenAPI Select" {...props} selectedKey={selectedKey || (selected === null || selected === void 0 ? void 0 : selected.key)} onSelectionChange={function (key) {
21
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(key);
22
+ state.setKey(key);
23
+ }} className={clsx('openapi-select', className)}>
7
24
  <Button>
8
25
  <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>
26
+ {icon}
16
27
  </Button>
17
28
  <Popover placement={placement} className="openapi-select-popover">
18
29
  <ListBox className="openapi-select-listbox" items={items}>
@@ -1,5 +1,6 @@
1
- import type { OpenAPIClientContext, OpenAPIOperationData } from './types';
1
+ import type { OpenAPIClientContext } from './context';
2
+ import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
2
3
  export declare function OpenAPISpec(props: {
3
- data: OpenAPIOperationData;
4
+ data: OpenAPIOperationData | OpenAPIWebhookData;
4
5
  context: OpenAPIClientContext;
5
6
  }): import("react").JSX.Element;