@gitbook/react-openapi 1.4.3 → 1.5.2

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 (263) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/InteractiveSection.js +59 -0
  3. package/dist/Markdown.js +10 -0
  4. package/dist/OpenAPICodeSample.js +219 -0
  5. package/dist/OpenAPICodeSampleInteractive.js +66 -0
  6. package/dist/OpenAPICodeSampleSelector.js +45 -0
  7. package/dist/OpenAPICopyButton.js +39 -0
  8. package/dist/OpenAPIDisclosure.js +30 -0
  9. package/dist/OpenAPIDisclosureGroup.js +75 -0
  10. package/dist/OpenAPIExample.js +41 -0
  11. package/dist/OpenAPIMediaType.js +58 -0
  12. package/dist/OpenAPIOperation.d.ts +12 -7
  13. package/dist/OpenAPIOperation.js +30 -0
  14. package/dist/OpenAPIOperationContext.d.ts +10 -6
  15. package/dist/OpenAPIOperationContext.js +30 -0
  16. package/dist/OpenAPIPath.js +51 -0
  17. package/dist/OpenAPIPrefillContextProvider.d.ts +11 -7
  18. package/dist/OpenAPIPrefillContextProvider.js +25 -0
  19. package/dist/OpenAPIRequestBody.js +28 -0
  20. package/dist/OpenAPIRequestBodyHeaderType.js +23 -0
  21. package/dist/OpenAPIResponse.js +39 -0
  22. package/dist/OpenAPIResponseExample.js +75 -0
  23. package/dist/OpenAPIResponseExampleContent.js +61 -0
  24. package/dist/OpenAPIResponses.js +61 -0
  25. package/dist/OpenAPISchema.js +373 -0
  26. package/dist/OpenAPISchemaName.js +45 -0
  27. package/dist/OpenAPISchemaServer.js +13 -0
  28. package/dist/OpenAPISecurities.js +124 -0
  29. package/dist/OpenAPISelect.js +45 -0
  30. package/dist/OpenAPISpec.js +73 -0
  31. package/dist/OpenAPIWebhook.d.ts +12 -7
  32. package/dist/OpenAPIWebhook.js +28 -0
  33. package/dist/OpenAPIWebhookExample.js +40 -0
  34. package/dist/ScalarApiButton.js +87 -0
  35. package/dist/StaticSection.js +37 -0
  36. package/dist/code-samples.js +267 -419
  37. package/dist/common/OpenAPIColumnSpec.js +23 -0
  38. package/dist/common/OpenAPIOperationDescription.js +18 -0
  39. package/dist/common/OpenAPIStability.js +17 -0
  40. package/dist/common/OpenAPISummary.js +27 -0
  41. package/dist/contentTypeChecks.js +24 -20
  42. package/dist/context.d.ts +68 -72
  43. package/dist/context.js +25 -39
  44. package/dist/decycle.js +39 -68
  45. package/dist/dereference.js +20 -64
  46. package/dist/generateSchemaExample.js +188 -332
  47. package/dist/getDisclosureLabel.js +15 -16
  48. package/dist/getOrCreateStoreByKey.js +20 -17
  49. package/dist/index.d.ts +12 -10
  50. package/dist/index.js +11 -8
  51. package/dist/json2xml.js +10 -5
  52. package/dist/resolveOpenAPIOperation.d.ts +11 -7
  53. package/dist/resolveOpenAPIOperation.js +88 -159
  54. package/dist/resolveOpenAPIWebhook.d.ts +11 -7
  55. package/dist/resolveOpenAPIWebhook.js +41 -116
  56. package/dist/schemas/OpenAPISchemaItem.js +26 -0
  57. package/dist/schemas/OpenAPISchemas.d.ts +16 -11
  58. package/dist/schemas/OpenAPISchemas.js +57 -0
  59. package/dist/schemas/resolveOpenAPISchemas.d.ts +9 -4
  60. package/dist/schemas/resolveOpenAPISchemas.js +15 -59
  61. package/dist/stringifyOpenAPI.js +12 -13
  62. package/dist/translate.js +43 -0
  63. package/dist/translations/de.js +47 -42
  64. package/dist/translations/en.d.ts +46 -42
  65. package/dist/translations/en.js +47 -42
  66. package/dist/translations/es.js +47 -42
  67. package/dist/translations/fr.js +47 -42
  68. package/dist/translations/index.d.ts +404 -391
  69. package/dist/translations/index.js +28 -24
  70. package/dist/translations/ja.js +47 -42
  71. package/dist/translations/nl.js +47 -42
  72. package/dist/translations/no.js +47 -42
  73. package/dist/translations/pt-br.js +47 -42
  74. package/dist/translations/types.d.ts +7 -5
  75. package/dist/translations/zh.js +47 -42
  76. package/dist/types.d.ts +30 -24
  77. package/dist/util/example.js +84 -0
  78. package/dist/util/server.js +32 -38
  79. package/dist/util/tryit-prefill.js +135 -121
  80. package/dist/utils.js +135 -196
  81. package/package.json +18 -11
  82. package/dist/InteractiveSection.d.ts +0 -33
  83. package/dist/InteractiveSection.jsx +0 -61
  84. package/dist/Markdown.d.ts +0 -4
  85. package/dist/Markdown.jsx +0 -5
  86. package/dist/OpenAPICodeSample.d.ts +0 -19
  87. package/dist/OpenAPICodeSample.jsx +0 -230
  88. package/dist/OpenAPICodeSampleInteractive.d.ts +0 -14
  89. package/dist/OpenAPICodeSampleInteractive.jsx +0 -73
  90. package/dist/OpenAPICodeSampleSelector.d.ts +0 -14
  91. package/dist/OpenAPICodeSampleSelector.jsx +0 -44
  92. package/dist/OpenAPICopyButton.d.ts +0 -13
  93. package/dist/OpenAPICopyButton.jsx +0 -35
  94. package/dist/OpenAPIDisclosure.d.ts +0 -11
  95. package/dist/OpenAPIDisclosure.jsx +0 -30
  96. package/dist/OpenAPIDisclosureGroup.d.ts +0 -23
  97. package/dist/OpenAPIDisclosureGroup.jsx +0 -83
  98. package/dist/OpenAPIExample.d.ts +0 -16
  99. package/dist/OpenAPIExample.jsx +0 -36
  100. package/dist/OpenAPIMediaType.d.ts +0 -21
  101. package/dist/OpenAPIMediaType.jsx +0 -61
  102. package/dist/OpenAPIOperation.jsx +0 -25
  103. package/dist/OpenAPIOperationContext.jsx +0 -26
  104. package/dist/OpenAPIOperationDescription.d.ts +0 -9
  105. package/dist/OpenAPIOperationDescription.jsx +0 -22
  106. package/dist/OpenAPIOperationStability.d.ts +0 -9
  107. package/dist/OpenAPIOperationStability.jsx +0 -27
  108. package/dist/OpenAPIPath.d.ts +0 -18
  109. package/dist/OpenAPIPath.jsx +0 -55
  110. package/dist/OpenAPIPrefillContextProvider.jsx +0 -19
  111. package/dist/OpenAPIRequestBody.d.ts +0 -11
  112. package/dist/OpenAPIRequestBody.jsx +0 -28
  113. package/dist/OpenAPIRequestBodyHeaderType.d.ts +0 -8
  114. package/dist/OpenAPIRequestBodyHeaderType.jsx +0 -25
  115. package/dist/OpenAPIResponse.d.ts +0 -10
  116. package/dist/OpenAPIResponse.jsx +0 -57
  117. package/dist/OpenAPIResponseExample.d.ts +0 -9
  118. package/dist/OpenAPIResponseExample.jsx +0 -105
  119. package/dist/OpenAPIResponseExampleContent.d.ts +0 -22
  120. package/dist/OpenAPIResponseExampleContent.jsx +0 -60
  121. package/dist/OpenAPIResponses.d.ts +0 -9
  122. package/dist/OpenAPIResponses.jsx +0 -77
  123. package/dist/OpenAPISchema.d.ts +0 -27
  124. package/dist/OpenAPISchema.jsx +0 -400
  125. package/dist/OpenAPISchemaName.d.ts +0 -16
  126. package/dist/OpenAPISchemaName.jsx +0 -43
  127. package/dist/OpenAPISchemaServer.d.ts +0 -12
  128. package/dist/OpenAPISchemaServer.jsx +0 -8
  129. package/dist/OpenAPISecurities.d.ts +0 -9
  130. package/dist/OpenAPISecurities.jsx +0 -114
  131. package/dist/OpenAPISelect.d.ts +0 -22
  132. package/dist/OpenAPISelect.jsx +0 -44
  133. package/dist/OpenAPISpec.d.ts +0 -6
  134. package/dist/OpenAPISpec.jsx +0 -80
  135. package/dist/OpenAPITabs.d.ts +0 -26
  136. package/dist/OpenAPITabs.jsx +0 -109
  137. package/dist/OpenAPIWebhook.jsx +0 -23
  138. package/dist/OpenAPIWebhookExample.d.ts +0 -6
  139. package/dist/OpenAPIWebhookExample.jsx +0 -41
  140. package/dist/ScalarApiButton.d.ts +0 -14
  141. package/dist/ScalarApiButton.jsx +0 -81
  142. package/dist/StaticSection.d.ts +0 -13
  143. package/dist/StaticSection.jsx +0 -32
  144. package/dist/code-samples.d.ts +0 -17
  145. package/dist/common/OpenAPIColumnSpec.d.ts +0 -6
  146. package/dist/common/OpenAPIColumnSpec.jsx +0 -20
  147. package/dist/common/OpenAPIOperationDescription.d.ts +0 -6
  148. package/dist/common/OpenAPIOperationDescription.jsx +0 -19
  149. package/dist/common/OpenAPIStability.d.ts +0 -4
  150. package/dist/common/OpenAPIStability.jsx +0 -15
  151. package/dist/common/OpenAPISummary.d.ts +0 -6
  152. package/dist/common/OpenAPISummary.jsx +0 -30
  153. package/dist/contentTypeChecks.d.ts +0 -10
  154. package/dist/decycle.d.ts +0 -2
  155. package/dist/dereference.d.ts +0 -5
  156. package/dist/generateSchemaExample.d.ts +0 -45
  157. package/dist/getDisclosureLabel.d.ts +0 -7
  158. package/dist/getOrCreateStoreByKey.d.ts +0 -10
  159. package/dist/json2xml.d.ts +0 -4
  160. package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
  161. package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
  162. package/dist/schemas/OpenAPISchemas.jsx +0 -59
  163. package/dist/schemas/index.d.ts +0 -2
  164. package/dist/schemas/index.js +0 -2
  165. package/dist/stringifyOpenAPI.d.ts +0 -4
  166. package/dist/translate.d.ts +0 -10
  167. package/dist/translate.jsx +0 -75
  168. package/dist/translations/de.d.ts +0 -43
  169. package/dist/translations/es.d.ts +0 -43
  170. package/dist/translations/fr.d.ts +0 -43
  171. package/dist/translations/ja.d.ts +0 -43
  172. package/dist/translations/nl.d.ts +0 -43
  173. package/dist/translations/no.d.ts +0 -43
  174. package/dist/translations/pt-br.d.ts +0 -43
  175. package/dist/translations/types.js +0 -1
  176. package/dist/translations/zh.d.ts +0 -43
  177. package/dist/tsconfig.build.tsbuildinfo +0 -1
  178. package/dist/types.js +0 -1
  179. package/dist/util/example.d.ts +0 -35
  180. package/dist/util/example.jsx +0 -103
  181. package/dist/util/server.d.ts +0 -9
  182. package/dist/util/tryit-prefill.d.ts +0 -20
  183. package/dist/utils.d.ts +0 -50
  184. package/src/InteractiveSection.tsx +0 -147
  185. package/src/Markdown.tsx +0 -12
  186. package/src/OpenAPICodeSample.tsx +0 -330
  187. package/src/OpenAPICodeSampleInteractive.tsx +0 -136
  188. package/src/OpenAPICodeSampleSelector.tsx +0 -94
  189. package/src/OpenAPICopyButton.tsx +0 -72
  190. package/src/OpenAPIDisclosure.tsx +0 -46
  191. package/src/OpenAPIDisclosureGroup.tsx +0 -158
  192. package/src/OpenAPIExample.tsx +0 -55
  193. package/src/OpenAPIMediaType.tsx +0 -139
  194. package/src/OpenAPIOperation.tsx +0 -35
  195. package/src/OpenAPIOperationContext.tsx +0 -45
  196. package/src/OpenAPIOperationDescription.tsx +0 -34
  197. package/src/OpenAPIOperationStability.tsx +0 -39
  198. package/src/OpenAPIPath.tsx +0 -90
  199. package/src/OpenAPIPrefillContextProvider.tsx +0 -40
  200. package/src/OpenAPIRequestBody.tsx +0 -54
  201. package/src/OpenAPIRequestBodyHeaderType.tsx +0 -36
  202. package/src/OpenAPIResponse.tsx +0 -82
  203. package/src/OpenAPIResponseExample.tsx +0 -151
  204. package/src/OpenAPIResponseExampleContent.tsx +0 -125
  205. package/src/OpenAPIResponses.tsx +0 -125
  206. package/src/OpenAPISchema.test.ts +0 -172
  207. package/src/OpenAPISchema.tsx +0 -654
  208. package/src/OpenAPISchemaName.tsx +0 -80
  209. package/src/OpenAPISchemaServer.tsx +0 -34
  210. package/src/OpenAPISecurities.tsx +0 -231
  211. package/src/OpenAPISelect.tsx +0 -96
  212. package/src/OpenAPISpec.tsx +0 -138
  213. package/src/OpenAPITabs.tsx +0 -147
  214. package/src/OpenAPIWebhook.tsx +0 -33
  215. package/src/OpenAPIWebhookExample.tsx +0 -60
  216. package/src/ScalarApiButton.tsx +0 -132
  217. package/src/StaticSection.tsx +0 -91
  218. package/src/__snapshots__/json2xml.test.ts.snap +0 -18
  219. package/src/code-samples.test.ts +0 -714
  220. package/src/code-samples.ts +0 -448
  221. package/src/common/OpenAPIColumnSpec.tsx +0 -31
  222. package/src/common/OpenAPIOperationDescription.tsx +0 -31
  223. package/src/common/OpenAPIStability.tsx +0 -23
  224. package/src/common/OpenAPISummary.tsx +0 -45
  225. package/src/contentTypeChecks.ts +0 -39
  226. package/src/context.ts +0 -99
  227. package/src/decycle.ts +0 -68
  228. package/src/dereference.ts +0 -29
  229. package/src/generateSchemaExample.test.ts +0 -1040
  230. package/src/generateSchemaExample.ts +0 -530
  231. package/src/getDisclosureLabel.ts +0 -25
  232. package/src/getOrCreateStoreByKey.ts +0 -33
  233. package/src/index.ts +0 -10
  234. package/src/json2xml.test.ts +0 -46
  235. package/src/json2xml.ts +0 -8
  236. package/src/resolveOpenAPIOperation.test.ts +0 -177
  237. package/src/resolveOpenAPIOperation.ts +0 -151
  238. package/src/resolveOpenAPIWebhook.ts +0 -99
  239. package/src/schemas/OpenAPISchemaItem.tsx +0 -34
  240. package/src/schemas/OpenAPISchemas.tsx +0 -98
  241. package/src/schemas/index.ts +0 -2
  242. package/src/schemas/resolveOpenAPISchemas.test.ts +0 -174
  243. package/src/schemas/resolveOpenAPISchemas.ts +0 -28
  244. package/src/stringifyOpenAPI.ts +0 -25
  245. package/src/translate.tsx +0 -80
  246. package/src/translations/de.ts +0 -43
  247. package/src/translations/en.ts +0 -43
  248. package/src/translations/es.ts +0 -43
  249. package/src/translations/fr.ts +0 -43
  250. package/src/translations/index.ts +0 -33
  251. package/src/translations/ja.ts +0 -43
  252. package/src/translations/nl.ts +0 -43
  253. package/src/translations/no.ts +0 -43
  254. package/src/translations/pt-br.ts +0 -43
  255. package/src/translations/types.ts +0 -7
  256. package/src/translations/zh.ts +0 -43
  257. package/src/types.ts +0 -46
  258. package/src/util/example.tsx +0 -129
  259. package/src/util/server.test.ts +0 -58
  260. package/src/util/server.ts +0 -47
  261. package/src/util/tryit-prefill.test.ts +0 -311
  262. package/src/util/tryit-prefill.ts +0 -160
  263. package/src/utils.ts +0 -255
@@ -1,77 +0,0 @@
1
- 'use client';
2
- import clsx from 'clsx';
3
- import { Markdown } from './Markdown';
4
- import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
5
- import { OpenAPIResponse } from './OpenAPIResponse';
6
- import { useResponseExamplesState } from './OpenAPIResponseExampleContent';
7
- import { StaticSection } from './StaticSection';
8
- import { t } from './translate';
9
- import { createStateKey, getStatusCodeClassName, getStatusCodeDefaultLabel, resolveDescription, } from './utils';
10
- /**
11
- * Display an interactive response body.
12
- */
13
- export function OpenAPIResponses(props) {
14
- var _a;
15
- var responses = props.responses, context = props.context;
16
- var groups = Object.entries(responses)
17
- .filter(function (_a) {
18
- var _ = _a[0], response = _a[1];
19
- return response && typeof response === 'object';
20
- })
21
- .map(function (_a) {
22
- var statusCode = _a[0], response = _a[1];
23
- var tabs = (function () {
24
- var _a;
25
- // If there is no content, but there are headers, we need to show the headers
26
- if ((!response.content || !Object.keys(response.content).length) &&
27
- response.headers &&
28
- Object.keys(response.headers).length) {
29
- return [
30
- {
31
- key: 'default',
32
- label: '',
33
- body: (<OpenAPIResponse response={response} mediaType={{}} context={context}/>),
34
- },
35
- ];
36
- }
37
- if (!response.content) {
38
- return [
39
- {
40
- key: 'default',
41
- label: '',
42
- body: (<pre className="openapi-example-empty">
43
- <p>{t(context.translation, 'no_content')}</p>
44
- </pre>),
45
- },
46
- ];
47
- }
48
- return Object.entries((_a = response.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
49
- var contentType = _a[0], mediaType = _a[1];
50
- return ({
51
- key: contentType,
52
- label: contentType,
53
- body: (<OpenAPIResponse response={response} mediaType={mediaType} context={context}/>),
54
- });
55
- });
56
- })();
57
- var description = resolveDescription(response);
58
- return {
59
- key: statusCode,
60
- label: (<div className="openapi-response-tab-content">
61
- <span className={clsx('openapi-statuscode', "openapi-statuscode-".concat(getStatusCodeClassName(statusCode)))}>
62
- {statusCode}
63
- </span>
64
- {description ? (<Markdown source={description} className="openapi-response-description"/>) : (getStatusCodeDefaultLabel(statusCode, context))}
65
- </div>),
66
- tabs: tabs,
67
- };
68
- });
69
- var state = useResponseExamplesState(context.blockKey, (_a = groups[0]) === null || _a === void 0 ? void 0 : _a.key);
70
- return (<StaticSection header={t(context.translation, 'responses')} className="openapi-responses">
71
- <OpenAPIDisclosureGroup icon={context.icons.chevronRight} expandedKeys={state.key ? new Set([state.key]) : new Set()} onExpandedChange={function (keys) {
72
- var _a;
73
- var key = (_a = keys.values().next().value) !== null && _a !== void 0 ? _a : null;
74
- state.setKey(key);
75
- }} groups={groups} selectIcon={context.icons.chevronDown} selectStateKey={createStateKey('response-media-types', context.blockKey)}/>
76
- </StaticSection>);
77
- }
@@ -1,27 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './context';
3
- export interface OpenAPISchemaPropertyEntry {
4
- propertyName?: string;
5
- required?: boolean | null;
6
- schema: OpenAPIV3.SchemaObject;
7
- }
8
- export declare function OpenAPISchemaPropertiesFromServer(props: {
9
- id?: string;
10
- properties: string;
11
- context: OpenAPIClientContext;
12
- }): import("react").JSX.Element;
13
- export declare function OpenAPIRootSchemaFromServer(props: {
14
- schema: string;
15
- context: OpenAPIClientContext;
16
- }): import("react").JSX.Element;
17
- /**
18
- * Render the top row of a schema. e.g: name, type, and required status.
19
- */
20
- export declare function OpenAPISchemaPresentation(props: {
21
- property: OpenAPISchemaPropertyEntry;
22
- context: OpenAPIClientContext;
23
- }): import("react").JSX.Element;
24
- /**
25
- * Get the alternatives to display for a schema.
26
- */
27
- export declare function getSchemaAlternatives(schema: OpenAPIV3.SchemaObject, ancestors?: Set<OpenAPIV3.SchemaObject>): OpenAPIV3.SchemaObject[] | null;
@@ -1,400 +0,0 @@
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 __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
25
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
26
- if (ar || !(i in from)) {
27
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
28
- ar[i] = from[i];
29
- }
30
- }
31
- return to.concat(ar || Array.prototype.slice.call(from));
32
- };
33
- import { useId } from 'react';
34
- import clsx from 'clsx';
35
- import { Markdown } from './Markdown';
36
- import { OpenAPICopyButton } from './OpenAPICopyButton';
37
- import { OpenAPIDisclosure } from './OpenAPIDisclosure';
38
- import { OpenAPISchemaName } from './OpenAPISchemaName';
39
- import { retrocycle } from './decycle';
40
- import { getDisclosureLabel } from './getDisclosureLabel';
41
- import { stringifyOpenAPI } from './stringifyOpenAPI';
42
- import { tString } from './translate';
43
- import { checkIsReference, getSchemaTitle, resolveDescription, resolveFirstExample } from './utils';
44
- /**
45
- * Render a property of an OpenAPI schema.
46
- */
47
- function OpenAPISchemaProperty(props) {
48
- var parentCircularRefs = props.circularRefs, context = props.context, className = props.className, property = props.property, rest = __rest(props, ["circularRefs", "context", "className", "property"]);
49
- var schema = property.schema;
50
- var id = useId();
51
- var circularRefId = parentCircularRefs.get(schema);
52
- // Avoid recursing infinitely, and instead render a link to the parent schema
53
- if (circularRefId) {
54
- return <OpenAPISchemaCircularRef id={circularRefId} schema={schema}/>;
55
- }
56
- var circularRefs = new Map(parentCircularRefs);
57
- circularRefs.set(schema, id);
58
- var properties = getSchemaProperties(schema);
59
- var ancestors = new Set(circularRefs.keys());
60
- var alternatives = getSchemaAlternatives(schema, ancestors);
61
- var header = <OpenAPISchemaPresentation context={context} property={property}/>;
62
- var content = (function () {
63
- if (properties === null || properties === void 0 ? void 0 : properties.length) {
64
- return (<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>);
65
- }
66
- if (alternatives) {
67
- return (<div className="openapi-schema-alternatives">
68
- {alternatives.map(function (alternativeSchema, index) { return (<div key={index} className="openapi-schema-alternative">
69
- <OpenAPISchemaAlternative schema={alternativeSchema} circularRefs={circularRefs} context={context}/>
70
- {index < alternatives.length - 1 ? (<OpenAPISchemaAlternativeSeparator schema={schema} context={context}/>) : null}
71
- </div>); })}
72
- </div>);
73
- }
74
- return null;
75
- })();
76
- if (properties === null || properties === void 0 ? void 0 : properties.length) {
77
- return (<OpenAPIDisclosure icon={context.icons.plus} className={clsx('openapi-schema', className)} header={header} label={function (isExpanded) { return getDisclosureLabel({ schema: schema, isExpanded: isExpanded, context: context }); }} {...rest}>
78
- {content}
79
- </OpenAPIDisclosure>);
80
- }
81
- return (<div id={id} {...rest} className={clsx('openapi-schema', className)}>
82
- {header}
83
- {content}
84
- </div>);
85
- }
86
- /**
87
- * Render a set of properties of an OpenAPI schema.
88
- */
89
- function OpenAPISchemaProperties(props) {
90
- var id = props.id, properties = props.properties, _a = props.circularRefs, circularRefs = _a === void 0 ? new Map() : _a, context = props.context;
91
- return (<div id={id} className="openapi-schema-properties">
92
- {properties.map(function (property, index) {
93
- return (<OpenAPISchemaProperty key={index} circularRefs={circularRefs} property={property} context={context} style={{ animationDelay: "".concat(index * 0.02, "s") }}/>);
94
- })}
95
- </div>);
96
- }
97
- export function OpenAPISchemaPropertiesFromServer(props) {
98
- return (<OpenAPISchemaProperties id={props.id} properties={JSON.parse(props.properties, retrocycle())} context={props.context}/>);
99
- }
100
- /**
101
- * Render a root schema (such as the request body or response body).
102
- */
103
- function OpenAPIRootSchema(props) {
104
- var schema = props.schema, context = props.context, _a = props.circularRefs, parentCircularRefs = _a === void 0 ? new Map() : _a;
105
- var id = useId();
106
- var properties = getSchemaProperties(schema);
107
- var description = resolveDescription(schema);
108
- if (properties === null || properties === void 0 ? void 0 : properties.length) {
109
- var circularRefs = new Map(parentCircularRefs);
110
- circularRefs.set(schema, id);
111
- return (<>
112
- {description ? (<Markdown source={description} className="openapi-schema-root-description"/>) : null}
113
- <OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>
114
- </>);
115
- }
116
- return (<OpenAPISchemaProperty className="openapi-schema-root" property={{ schema: schema }} context={context} circularRefs={parentCircularRefs}/>);
117
- }
118
- export function OpenAPIRootSchemaFromServer(props) {
119
- return (<OpenAPIRootSchema schema={JSON.parse(props.schema, retrocycle())} context={props.context}/>);
120
- }
121
- /**
122
- * Render a tab for an alternative schema.
123
- * It renders directly the properties if relevant;
124
- * for primitives, it renders the schema itself.
125
- */
126
- function OpenAPISchemaAlternative(props) {
127
- var schema = props.schema, circularRefs = props.circularRefs, context = props.context;
128
- var properties = getSchemaProperties(schema);
129
- return (properties === null || properties === void 0 ? void 0 : properties.length) ? (<OpenAPIDisclosure icon={context.icons.plus} header={<OpenAPISchemaPresentation property={{ schema: schema }} context={context}/>} label={function (isExpanded) { return getDisclosureLabel({ schema: schema, isExpanded: isExpanded, context: context }); }}>
130
- <OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>
131
- </OpenAPIDisclosure>) : (<OpenAPISchemaProperty property={{ schema: schema }} circularRefs={circularRefs} context={context}/>);
132
- }
133
- function OpenAPISchemaAlternativeSeparator(props) {
134
- var _a, _b, _c;
135
- var schema = props.schema, context = props.context;
136
- var anyOf = schema.anyOf || ((_a = schema.items) === null || _a === void 0 ? void 0 : _a.anyOf);
137
- var oneOf = schema.oneOf || ((_b = schema.items) === null || _b === void 0 ? void 0 : _b.oneOf);
138
- var allOf = schema.allOf || ((_c = schema.items) === null || _c === void 0 ? void 0 : _c.allOf);
139
- if (!anyOf && !oneOf && !allOf) {
140
- return null;
141
- }
142
- return (<span className="openapi-schema-alternative-separator">
143
- {(anyOf || oneOf) && tString(context.translation, 'or')}
144
- {allOf && tString(context.translation, 'and')}
145
- </span>);
146
- }
147
- /**
148
- * Render a circular reference to a schema.
149
- */
150
- function OpenAPISchemaCircularRef(props) {
151
- var id = props.id, schema = props.schema;
152
- return (<div className="openapi-schema-circular">
153
- Circular reference to <a href={"#".concat(id)}>{getSchemaTitle(schema)}</a>{' '}
154
- <span className="openapi-schema-circular-glyph">↩</span>
155
- </div>);
156
- }
157
- /**
158
- * Render the enum value for a schema.
159
- */
160
- function OpenAPISchemaEnum(props) {
161
- var schema = props.schema, context = props.context;
162
- var enumValues = (function () {
163
- var _a;
164
- // Render x-gitbook-enum first, as it has a different format
165
- if (schema['x-gitbook-enum']) {
166
- return Object.entries(schema['x-gitbook-enum']).map(function (_a) {
167
- var name = _a[0], description = _a[1].description;
168
- return {
169
- value: name,
170
- description: description,
171
- };
172
- });
173
- }
174
- if (schema['x-enumDescriptions']) {
175
- return Object.entries(schema['x-enumDescriptions']).map(function (_a) {
176
- var value = _a[0], description = _a[1];
177
- return {
178
- value: value,
179
- description: description,
180
- };
181
- });
182
- }
183
- return (_a = schema.enum) === null || _a === void 0 ? void 0 : _a.map(function (value) {
184
- return {
185
- value: value,
186
- description: undefined,
187
- };
188
- });
189
- })();
190
- if (!(enumValues === null || enumValues === void 0 ? void 0 : enumValues.length)) {
191
- return null;
192
- }
193
- return (<span className="openapi-schema-enum">
194
- {tString(context.translation, 'possible_values')}:{' '}
195
- {enumValues.map(function (item, index) { return (<span key={index} className="openapi-schema-enum-value">
196
- <OpenAPICopyButton value={item.value} label={item.description} withTooltip={!!item.description} context={context}>
197
- <code>{"".concat(item.value)}</code>
198
- </OpenAPICopyButton>
199
- </span>); })}
200
- </span>);
201
- }
202
- /**
203
- * Render the top row of a schema. e.g: name, type, and required status.
204
- */
205
- export function OpenAPISchemaPresentation(props) {
206
- var _a = props.property, schema = _a.schema, propertyName = _a.propertyName, required = _a.required, context = props.context;
207
- var description = resolveDescription(schema);
208
- var example = resolveFirstExample(schema);
209
- return (<div className="openapi-schema-presentation">
210
- <OpenAPISchemaName schema={schema} type={getSchemaTitle(schema)} propertyName={propertyName} required={required} context={context}/>
211
- {typeof schema['x-deprecated-sunset'] === 'string' ? (<div className="openapi-deprecated-sunset openapi-schema-description openapi-markdown">
212
- Sunset date:{' '}
213
- <span className="openapi-deprecated-sunset-date">
214
- {schema['x-deprecated-sunset']}
215
- </span>
216
- </div>) : null}
217
- {description ? (<Markdown source={description} className="openapi-schema-description"/>) : null}
218
- {schema.default !== undefined ? (<span className="openapi-schema-default">
219
- Default:{' '}
220
- <code>
221
- {typeof schema.default === 'string' && schema.default
222
- ? schema.default
223
- : stringifyOpenAPI(schema.default)}
224
- </code>
225
- </span>) : null}
226
- {typeof example === 'string' ? (<span className="openapi-schema-example">
227
- Example: <code>{example}</code>
228
- </span>) : null}
229
- {schema.pattern ? (<span className="openapi-schema-pattern">
230
- Pattern: <code>{schema.pattern}</code>
231
- </span>) : null}
232
- <OpenAPISchemaEnum schema={schema} context={context}/>
233
- </div>);
234
- }
235
- /**
236
- * Get the sub-properties of a schema.
237
- */
238
- function getSchemaProperties(schema) {
239
- // check array AND schema.items as this is sometimes null despite what the type indicates
240
- if (schema.type === 'array' && schema.items && !checkIsReference(schema.items)) {
241
- var items = schema.items;
242
- var itemProperties = getSchemaProperties(items);
243
- if (itemProperties) {
244
- return itemProperties;
245
- }
246
- // If the items are a primitive type, we don't need to display them
247
- if ((items.type === 'string' ||
248
- items.type === 'number' ||
249
- items.type === 'boolean' ||
250
- items.type === 'integer') &&
251
- !items.enum) {
252
- return null;
253
- }
254
- return [{ propertyName: 'items', schema: items }];
255
- }
256
- if (schema.type === 'object' || schema.properties) {
257
- var result_1 = [];
258
- if (schema.properties) {
259
- Object.entries(schema.properties).forEach(function (_a) {
260
- var propertyName = _a[0], propertySchema = _a[1];
261
- if (checkIsReference(propertySchema)) {
262
- return;
263
- }
264
- result_1.push({
265
- propertyName: propertyName,
266
- required: Array.isArray(schema.required)
267
- ? schema.required.includes(propertyName)
268
- : undefined,
269
- schema: propertySchema,
270
- });
271
- });
272
- }
273
- if (schema.additionalProperties && !checkIsReference(schema.additionalProperties)) {
274
- result_1.push({
275
- propertyName: 'Other properties',
276
- schema: schema.additionalProperties === true ? {} : schema.additionalProperties,
277
- });
278
- }
279
- return result_1;
280
- }
281
- return null;
282
- }
283
- /**
284
- * Get the alternatives to display for a schema.
285
- */
286
- export function getSchemaAlternatives(schema, ancestors) {
287
- if (ancestors === void 0) { ancestors = new Set(); }
288
- // Search for alternatives in the items property if it exists
289
- if (schema.items &&
290
- ('oneOf' in schema.items || 'allOf' in schema.items || 'anyOf' in schema.items)) {
291
- return getSchemaAlternatives(schema.items, ancestors);
292
- }
293
- var alternatives = (function () {
294
- if (schema.anyOf) {
295
- return ['anyOf', schema.anyOf];
296
- }
297
- if (schema.oneOf) {
298
- return ['oneOf', schema.oneOf];
299
- }
300
- if (schema.allOf) {
301
- return ['allOf', schema.allOf];
302
- }
303
- return null;
304
- })();
305
- if (!alternatives) {
306
- return null;
307
- }
308
- var type = alternatives[0], schemas = alternatives[1];
309
- return mergeAlternatives(type, flattenAlternatives(type, schemas, new Set(ancestors).add(schema)));
310
- }
311
- /**
312
- * Merge alternatives of the same type into a single schema.
313
- * - Merge string enums
314
- */
315
- function mergeAlternatives(alternativeType, schemasOrRefs) {
316
- switch (alternativeType) {
317
- case 'oneOf': {
318
- return schemasOrRefs.reduce(function (acc, schemaOrRef) {
319
- var latest = acc.at(-1);
320
- if (latest &&
321
- latest.type === 'string' &&
322
- latest.enum &&
323
- schemaOrRef.type === 'string' &&
324
- schemaOrRef.enum) {
325
- latest.enum = Array.from(new Set(__spreadArray(__spreadArray([], latest.enum, true), schemaOrRef.enum, true)));
326
- latest.nullable = latest.nullable || schemaOrRef.nullable;
327
- return acc;
328
- }
329
- acc.push(schemaOrRef);
330
- return acc;
331
- }, []);
332
- }
333
- case 'allOf': {
334
- return schemasOrRefs.reduce(function (acc, schemaOrRef) {
335
- var latest = acc.at(-1);
336
- if (latest &&
337
- latest.type === 'string' &&
338
- latest.enum &&
339
- schemaOrRef.type === 'string' &&
340
- schemaOrRef.enum) {
341
- var keys = Object.keys(schemaOrRef);
342
- if (keys.every(function (key) { return ['type', 'enum', 'nullable'].includes(key); })) {
343
- latest.enum = Array.from(new Set(__spreadArray(__spreadArray([], latest.enum, true), schemaOrRef.enum, true)));
344
- latest.nullable = latest.nullable || schemaOrRef.nullable;
345
- return acc;
346
- }
347
- }
348
- if (latest && latest.type === 'object' && schemaOrRef.type === 'object') {
349
- var keys = Object.keys(schemaOrRef);
350
- if (keys.every(function (key) {
351
- return ['type', 'properties', 'required', 'nullable'].includes(key);
352
- })) {
353
- latest.properties = __assign(__assign({}, latest.properties), schemaOrRef.properties);
354
- latest.required = Array.from(new Set(__spreadArray(__spreadArray([], (Array.isArray(latest.required) ? latest.required : []), true), (Array.isArray(schemaOrRef.required)
355
- ? schemaOrRef.required
356
- : []), true)));
357
- latest.nullable = latest.nullable || schemaOrRef.nullable;
358
- return acc;
359
- }
360
- }
361
- acc.push(schemaOrRef);
362
- return acc;
363
- }, []);
364
- }
365
- default:
366
- return schemasOrRefs;
367
- }
368
- }
369
- function flattenAlternatives(alternativeType, schemasOrRefs, ancestors) {
370
- // Get the parent schema's required fields from the most recent ancestor
371
- var latestAncestor = Array.from(ancestors).pop();
372
- return schemasOrRefs.reduce(function (acc, schemaOrRef) {
373
- if (checkIsReference(schemaOrRef)) {
374
- return acc;
375
- }
376
- if (schemaOrRef[alternativeType] && !ancestors.has(schemaOrRef)) {
377
- var schemas = getSchemaAlternatives(schemaOrRef, ancestors);
378
- if (schemas) {
379
- acc.push.apply(acc, schemas.map(function (schema) { return (__assign(__assign({}, schema), { required: mergeRequiredFields(schema, latestAncestor) })); }));
380
- }
381
- return acc;
382
- }
383
- // For direct schemas, handle required fields
384
- var schema = __assign(__assign({}, schemaOrRef), { required: mergeRequiredFields(schemaOrRef, latestAncestor) });
385
- acc.push(schema);
386
- return acc;
387
- }, []);
388
- }
389
- /**
390
- * Merge the required fields of a schema with the required fields of its latest ancestor.
391
- */
392
- function mergeRequiredFields(schemaOrRef, latestAncestor) {
393
- if (!schemaOrRef.required && !(latestAncestor === null || latestAncestor === void 0 ? void 0 : latestAncestor.required)) {
394
- return undefined;
395
- }
396
- if (checkIsReference(schemaOrRef)) {
397
- return latestAncestor === null || latestAncestor === void 0 ? void 0 : latestAncestor.required;
398
- }
399
- return Array.from(new Set(__spreadArray(__spreadArray([], ((latestAncestor === null || latestAncestor === void 0 ? void 0 : latestAncestor.required) || []), true), (schemaOrRef.required || []), true)));
400
- }
@@ -1,16 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type React from 'react';
3
- import type { OpenAPIClientContext } from './context';
4
- interface OpenAPISchemaNameProps {
5
- schema?: OpenAPIV3.SchemaObject;
6
- propertyName?: string | React.JSX.Element;
7
- required?: boolean | null;
8
- type?: string;
9
- context: OpenAPIClientContext;
10
- }
11
- /**
12
- * Display the schema name row.
13
- * It includes the property name, type, required and deprecated status.
14
- */
15
- export declare function OpenAPISchemaName(props: OpenAPISchemaNameProps): React.JSX.Element;
16
- export {};
@@ -1,43 +0,0 @@
1
- import { t, tString } from './translate';
2
- /**
3
- * Display the schema name row.
4
- * It includes the property name, type, required and deprecated status.
5
- */
6
- export function OpenAPISchemaName(props) {
7
- var schema = props.schema, type = props.type, propertyName = props.propertyName, required = props.required, context = props.context;
8
- var additionalItems = schema && getAdditionalItems(schema, context);
9
- return (<span className="openapi-schema-name">
10
- {propertyName ? (<span data-deprecated={schema === null || schema === void 0 ? void 0 : schema.deprecated} className="openapi-schema-propertyname">
11
- {propertyName}
12
- </span>) : null}
13
- {type || additionalItems ? (<span>
14
- {type ? <span className="openapi-schema-type">{type}</span> : null}
15
- {additionalItems ? (<span className="openapi-schema-type">{additionalItems}</span>) : null}
16
- </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 === null ? null : 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}
29
- </span>);
30
- }
31
- function getAdditionalItems(schema, context) {
32
- var additionalItems = '';
33
- if (schema.minimum || schema.minLength || schema.minItems) {
34
- additionalItems += " \u00B7 ".concat(tString(context.translation, 'min').toLowerCase(), ": ").concat(schema.minimum || schema.minLength || schema.minItems);
35
- }
36
- if (schema.maximum || schema.maxLength || schema.maxItems) {
37
- additionalItems += " \u00B7 ".concat(tString(context.translation, 'max').toLowerCase(), ": ").concat(schema.maximum || schema.maxLength || schema.maxItems);
38
- }
39
- if (schema.nullable) {
40
- additionalItems = " | ".concat(tString(context.translation, 'nullable').toLowerCase());
41
- }
42
- return additionalItems;
43
- }
@@ -1,12 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import { type OpenAPISchemaPropertyEntry } from './OpenAPISchema';
3
- import type { OpenAPIClientContext } from './context';
4
- export declare function OpenAPISchemaProperties(props: {
5
- id?: string;
6
- properties: OpenAPISchemaPropertyEntry[];
7
- context: OpenAPIClientContext;
8
- }): import("react").JSX.Element;
9
- export declare function OpenAPIRootSchema(props: {
10
- schema: OpenAPIV3.SchemaObject;
11
- context: OpenAPIClientContext;
12
- }): import("react").JSX.Element;
@@ -1,8 +0,0 @@
1
- import { OpenAPIRootSchemaFromServer, OpenAPISchemaPropertiesFromServer, } from './OpenAPISchema';
2
- import { decycle } from './decycle';
3
- export function OpenAPISchemaProperties(props) {
4
- return (<OpenAPISchemaPropertiesFromServer id={props.id} properties={JSON.stringify(props.properties, decycle())} context={props.context}/>);
5
- }
6
- export function OpenAPIRootSchema(props) {
7
- return (<OpenAPIRootSchemaFromServer schema={JSON.stringify(props.schema, decycle())} context={props.context}/>);
8
- }
@@ -1,9 +0,0 @@
1
- import type { OpenAPIClientContext } from './context';
2
- import type { OpenAPIOperationData } from './types';
3
- /**
4
- * Present securities authorization that can be used for this operation.
5
- */
6
- export declare function OpenAPISecurities(props: {
7
- securities: OpenAPIOperationData['securities'];
8
- context: OpenAPIClientContext;
9
- }): import("react").JSX.Element | null;