@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
@@ -3,13 +3,15 @@ import { OpenAPIResponses } from './OpenAPIResponses';
3
3
  import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
4
4
  import { OpenAPISecurities } from './OpenAPISecurities';
5
5
  import { StaticSection } from './StaticSection';
6
+ import { tString } from './translate';
6
7
  import { parameterToProperty } from './utils';
7
8
  export function OpenAPISpec(props) {
8
9
  var _a;
9
10
  var data = props.data, context = props.context;
10
- var operation = data.operation, securities = data.securities;
11
+ var operation = data.operation;
11
12
  var parameters = (_a = operation.parameters) !== null && _a !== void 0 ? _a : [];
12
- var parameterGroups = groupParameters(parameters);
13
+ var parameterGroups = groupParameters(parameters, context);
14
+ var securities = 'securities' in data ? data.securities : [];
13
15
  return (<>
14
16
  {securities.length > 0 ? (<OpenAPISecurities key="securities" securities={securities} context={context}/>) : null}
15
17
 
@@ -19,18 +21,18 @@ export function OpenAPISpec(props) {
19
21
  </StaticSection>);
20
22
  })}
21
23
 
22
- {operation.requestBody ? (<OpenAPIRequestBody key="body" requestBody={operation.requestBody} context={context}/>) : null}
24
+ {operation.requestBody ? (<OpenAPIRequestBody key="body" requestBody={operation.requestBody} context={context} data={data}/>) : null}
23
25
  {operation.responses ? (<OpenAPIResponses key="responses" responses={operation.responses} context={context}/>) : null}
24
26
  </>);
25
27
  }
26
- function groupParameters(parameters) {
28
+ function groupParameters(parameters, context) {
27
29
  var sorted = ['path', 'query', 'header'];
28
30
  var groups = [];
29
31
  parameters
30
32
  .filter(function (parameter) { return parameter.in; })
31
33
  .forEach(function (parameter) {
32
34
  var key = parameter.in;
33
- var label = getParameterGroupName(parameter.in);
35
+ var label = getParameterGroupName(parameter.in, context);
34
36
  var group = groups.find(function (group) { return group.key === key; });
35
37
  if (group) {
36
38
  group.parameters.push(parameter);
@@ -46,14 +48,14 @@ function groupParameters(parameters) {
46
48
  groups.sort(function (a, b) { return sorted.indexOf(a.key) - sorted.indexOf(b.key); });
47
49
  return groups;
48
50
  }
49
- function getParameterGroupName(paramIn) {
51
+ function getParameterGroupName(paramIn, context) {
50
52
  switch (paramIn) {
51
53
  case 'path':
52
- return 'Path parameters';
54
+ return tString(context.translation, 'path_parameters');
53
55
  case 'query':
54
- return 'Query parameters';
56
+ return tString(context.translation, 'query_parameters');
55
57
  case 'header':
56
- return 'Header parameters';
58
+ return tString(context.translation, 'header_parameters');
57
59
  default:
58
60
  return paramIn;
59
61
  }
@@ -0,0 +1,10 @@
1
+ import { type OpenAPIContextInput } from './context';
2
+ import type { OpenAPIWebhookData } from './types';
3
+ /**
4
+ * Display an interactive OpenAPI webhook.
5
+ */
6
+ export declare function OpenAPIWebhook(props: {
7
+ className?: string;
8
+ data: OpenAPIWebhookData;
9
+ context: OpenAPIContextInput;
10
+ }): import("react").JSX.Element;
@@ -0,0 +1,23 @@
1
+ import clsx from 'clsx';
2
+ import { OpenAPIWebhookExample } from './OpenAPIWebhookExample';
3
+ import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
4
+ import { OpenAPISummary } from './common/OpenAPISummary';
5
+ import { resolveOpenAPIContext } from './context';
6
+ /**
7
+ * Display an interactive OpenAPI webhook.
8
+ */
9
+ export function OpenAPIWebhook(props) {
10
+ var className = props.className, data = props.data, contextInput = props.context;
11
+ var context = resolveOpenAPIContext(contextInput);
12
+ return (<div className={clsx('openapi-webhook', className)}>
13
+ <OpenAPISummary data={data} context={context}/>
14
+ <div className="openapi-columns">
15
+ <OpenAPIColumnSpec data={data} context={context}/>
16
+ <div className="openapi-column-preview">
17
+ <div className="openapi-column-preview-body">
18
+ <OpenAPIWebhookExample data={data} context={context}/>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ </div>);
23
+ }
@@ -0,0 +1,6 @@
1
+ import { type OpenAPIContext } from './context';
2
+ import type { OpenAPIWebhookData } from './types';
3
+ export declare function OpenAPIWebhookExample(props: {
4
+ data: OpenAPIWebhookData;
5
+ context: OpenAPIContext;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,41 @@
1
+ import { OpenAPIEmptyExample } from './OpenAPIExample';
2
+ import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
3
+ import { getOpenAPIClientContext } from './context';
4
+ import { getExamples } from './util/example';
5
+ import { createStateKey } from './utils';
6
+ export function OpenAPIWebhookExample(props) {
7
+ var data = props.data, context = props.context;
8
+ var operation = data.operation;
9
+ var items = (function () {
10
+ if (!operation.requestBody) {
11
+ return [];
12
+ }
13
+ return Object.entries(operation.requestBody.content).map(function (_a) {
14
+ var key = _a[0], value = _a[1];
15
+ var schema = value.schema;
16
+ if (!schema) {
17
+ return {
18
+ key: key,
19
+ label: key,
20
+ body: <OpenAPIEmptyExample context={context}/>,
21
+ };
22
+ }
23
+ return {
24
+ key: key,
25
+ label: key,
26
+ body: <></>,
27
+ examples: getExamples({
28
+ mediaTypeObject: value,
29
+ mediaType: key,
30
+ context: context,
31
+ }),
32
+ };
33
+ });
34
+ })();
35
+ return (<div className="openapi-panel">
36
+ <h4 className="openapi-panel-heading">Payload</h4>
37
+ <div className="openapi-panel-body">
38
+ <OpenAPIMediaTypeContent selectIcon={context.icons.chevronDown} stateKey={createStateKey('request-body-media-type', context.blockKey)} items={items} context={getOpenAPIClientContext(context)}/>
39
+ </div>
40
+ </div>);
41
+ }
@@ -1,4 +1,5 @@
1
1
  import type { OpenAPIV3_1 } from '@gitbook/openapi-parser';
2
+ import type { OpenAPIClientContext } from './context';
2
3
  /**
3
4
  * Button which launches the Scalar API Client
4
5
  */
@@ -6,4 +7,5 @@ export declare function ScalarApiButton(props: {
6
7
  method: OpenAPIV3_1.HttpMethods;
7
8
  path: string;
8
9
  specUrl: string;
10
+ context: OpenAPIClientContext;
9
11
  }): import("react").JSX.Element;
@@ -3,11 +3,12 @@ import { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-re
3
3
  import { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
5
  import { useOpenAPIOperationContext } from './OpenAPIOperationContext';
6
+ import { t } from './translate';
6
7
  /**
7
8
  * Button which launches the Scalar API Client
8
9
  */
9
10
  export function ScalarApiButton(props) {
10
- var method = props.method, path = props.path, specUrl = props.specUrl;
11
+ var method = props.method, path = props.path, specUrl = props.specUrl, context = props.context;
11
12
  var _a = useState(false), isOpen = _a[0], setIsOpen = _a[1];
12
13
  var controllerRef = useRef(null);
13
14
  return (<div className="scalar scalar-activate">
@@ -16,7 +17,7 @@ export function ScalarApiButton(props) {
16
17
  (_b = (_a = controllerRef.current) === null || _a === void 0 ? void 0 : _a.openClient) === null || _b === void 0 ? void 0 : _b.call(_a);
17
18
  setIsOpen(true);
18
19
  }}>
19
- Test it
20
+ {t(context.translation, 'test_it')}
20
21
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 12" fill="currentColor">
21
22
  <path stroke="currentColor" strokeWidth="1.5" d="M1 10.05V1.43c0-.2.2-.31.37-.22l7.26 4.08c.17.1.17.33.01.43l-7.26 4.54a.25.25 0 0 1-.38-.21Z"/>
22
23
  </svg>
@@ -28,7 +29,7 @@ export function ScalarApiButton(props) {
28
29
  }
29
30
  function ScalarModal(props) {
30
31
  var method = props.method, path = props.path, specUrl = props.specUrl, controllerRef = props.controllerRef;
31
- return (<ApiClientModalProvider configuration={{ spec: { url: specUrl } }} initialRequest={{ method: method, path: path }}>
32
+ return (<ApiClientModalProvider configuration={{ url: specUrl }} initialRequest={{ method: method, path: path }}>
32
33
  <ScalarModalController method={method} path={path} controllerRef={controllerRef}/>
33
34
  </ApiClientModalProvider>);
34
35
  }
@@ -3,8 +3,11 @@ export declare function Section(props: ComponentPropsWithoutRef<'div'>): import(
3
3
  export declare function SectionHeader(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
4
4
  export declare function SectionHeaderContent(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
5
5
  export declare const SectionBody: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
6
+ export declare function SectionFooter(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
7
+ export declare function SectionFooterContent(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
6
8
  export declare function StaticSection(props: {
7
9
  className: string;
8
- header: React.ReactNode;
10
+ header?: React.ReactNode;
9
11
  children: React.ReactNode;
12
+ footer?: React.ReactNode;
10
13
  }): import("react").JSX.Element;
@@ -12,12 +12,21 @@ export function SectionHeaderContent(props) {
12
12
  export var SectionBody = forwardRef(function SectionBody(props, ref) {
13
13
  return (<div ref={ref} {...props} className={clsx('openapi-section-body', props.className && "".concat(props.className, "-body"))}/>);
14
14
  });
15
+ export function SectionFooter(props) {
16
+ return (<div {...props} className={clsx('openapi-section-footer', props.className && "".concat(props.className, "-footer"))}/>);
17
+ }
18
+ export function SectionFooterContent(props) {
19
+ return (<div {...props} className={clsx('openapi-section-footer-content', props.className && "".concat(props.className, "-footer-content"))}/>);
20
+ }
15
21
  export function StaticSection(props) {
16
- var className = props.className, header = props.header, children = props.children;
22
+ var className = props.className, header = props.header, children = props.children, footer = props.footer;
17
23
  return (<Section className={className}>
18
- <SectionHeader className={className}>
19
- <SectionHeaderContent className={className}>{header}</SectionHeaderContent>
20
- </SectionHeader>
24
+ {header ? (<SectionHeader className={className}>
25
+ <SectionHeaderContent className={className}>{header}</SectionHeaderContent>
26
+ </SectionHeader>) : null}
21
27
  <SectionBody className={className}>{children}</SectionBody>
28
+ {footer ? (<SectionFooter className={className}>
29
+ <SectionFooterContent className={className}>{footer}</SectionFooterContent>
30
+ </SectionFooter>) : null}
22
31
  </Section>);
23
32
  }
@@ -9,10 +9,44 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { isCSV, isFormData, isFormUrlEncoded, isGraphQL, isPDF, isPlainObject, isText, isXML, } from './contentTypeChecks';
12
+ import { isCSV, isFormData, isFormUrlEncoded, isGraphQL, isJSON, isPDF, isPlainObject, isText, isXML, } from './contentTypeChecks';
13
13
  import { json2xml } from './json2xml';
14
14
  import { stringifyOpenAPI } from './stringifyOpenAPI';
15
15
  export var codeSampleGenerators = [
16
+ {
17
+ id: 'http',
18
+ label: 'HTTP',
19
+ syntax: 'bash',
20
+ generate: function (_a) {
21
+ var method = _a.method, url = _a.url, _b = _a.headers, headers = _b === void 0 ? {} : _b, body = _a.body;
22
+ var _c = parseHostAndPath(url), host = _c.host, path = _c.path;
23
+ if (body) {
24
+ // if we had a body add a content length header
25
+ var bodyContent = body ? stringifyOpenAPI(body) : '';
26
+ // handle unicode chars with a text encoder
27
+ var encoder = new TextEncoder();
28
+ var bodyString_1 = BodyGenerators.getHTTPBody(body, headers);
29
+ if (bodyString_1) {
30
+ body = bodyString_1;
31
+ }
32
+ headers = __assign(__assign({}, headers), { 'Content-Length': encoder.encode(bodyContent).length.toString() });
33
+ }
34
+ if (!headers.hasOwnProperty('Accept')) {
35
+ headers.Accept = '*/*';
36
+ }
37
+ var headerString = headers
38
+ ? "".concat(Object.entries(headers)
39
+ .map(function (_a) {
40
+ var key = _a[0], value = _a[1];
41
+ return key.toLowerCase() !== 'host' ? "".concat(key, ": ").concat(value) : '';
42
+ })
43
+ .join('\n'), "\n")
44
+ : '';
45
+ var bodyString = body ? "\n".concat(body) : '';
46
+ var httpRequest = "".concat(method.toUpperCase(), " ").concat(decodeURI(path), " HTTP/1.1\nHost: ").concat(host, "\n").concat(headerString).concat(bodyString);
47
+ return httpRequest;
48
+ },
49
+ },
16
50
  {
17
51
  id: 'curl',
18
52
  label: 'cURL',
@@ -98,12 +132,16 @@ export var codeSampleGenerators = [
98
132
  if (headers && Object.keys(headers).length > 0) {
99
133
  code += indent("headers=".concat(stringifyOpenAPI(headers), ",\n"), 4);
100
134
  }
135
+ var contentType = headers === null || headers === void 0 ? void 0 : headers['Content-Type'];
101
136
  if (body) {
102
137
  if (body === 'files') {
103
138
  code += indent("files=".concat(body, "\n"), 4);
104
139
  }
140
+ else if (isJSON(contentType)) {
141
+ code += indent("data=json.dumps(".concat(body, ")\n"), 4);
142
+ }
105
143
  else {
106
- code += indent("data=".concat(stringifyOpenAPI(body), "\n"), 4);
144
+ code += indent("data=".concat(body, "\n"), 4);
107
145
  }
108
146
  }
109
147
  code += ')\n\n';
@@ -111,40 +149,6 @@ export var codeSampleGenerators = [
111
149
  return code;
112
150
  },
113
151
  },
114
- {
115
- id: 'http',
116
- label: 'HTTP',
117
- syntax: 'bash',
118
- generate: function (_a) {
119
- var method = _a.method, url = _a.url, _b = _a.headers, headers = _b === void 0 ? {} : _b, body = _a.body;
120
- var _c = parseHostAndPath(url), host = _c.host, path = _c.path;
121
- if (body) {
122
- // if we had a body add a content length header
123
- var bodyContent = body ? stringifyOpenAPI(body) : '';
124
- // handle unicode chars with a text encoder
125
- var encoder = new TextEncoder();
126
- var bodyString_1 = BodyGenerators.getHTTPBody(body, headers);
127
- if (bodyString_1) {
128
- body = bodyString_1;
129
- }
130
- headers = __assign(__assign({}, headers), { 'Content-Length': encoder.encode(bodyContent).length.toString() });
131
- }
132
- if (!headers.hasOwnProperty('Accept')) {
133
- headers.Accept = '*/*';
134
- }
135
- var headerString = headers
136
- ? "".concat(Object.entries(headers)
137
- .map(function (_a) {
138
- var key = _a[0], value = _a[1];
139
- return key.toLowerCase() !== 'host' ? "".concat(key, ": ").concat(value) : '';
140
- })
141
- .join('\n'), "\n")
142
- : '';
143
- var bodyString = body ? "\n".concat(body) : '';
144
- var httpRequest = "".concat(method.toUpperCase(), " ").concat(decodeURI(path), " HTTP/1.1\nHost: ").concat(host, "\n").concat(headerString).concat(bodyString);
145
- return httpRequest;
146
- },
147
- },
148
152
  ];
149
153
  function indent(code, spaces) {
150
154
  var indent = ' '.repeat(spaces);
@@ -319,15 +323,29 @@ var BodyGenerators = {
319
323
  code += '}\n\n';
320
324
  body = 'files';
321
325
  }
322
- if (isPDF(contentType)) {
326
+ else if (isPDF(contentType)) {
323
327
  code += 'files = {\n';
324
328
  code += "".concat(indent("\"file\": \"".concat(body, "\","), 4), "\n");
325
329
  code += '}\n\n';
326
330
  body = 'files';
327
331
  }
328
- if (isXML(contentType)) {
332
+ else if (isXML(contentType)) {
329
333
  // Convert JSON to XML if needed
330
- body = convertBodyToXML(body);
334
+ body = JSON.stringify(convertBodyToXML(body));
335
+ }
336
+ else {
337
+ body = stringifyOpenAPI(body, function (_key, value) {
338
+ switch (value) {
339
+ case true:
340
+ return '$$__TRUE__$$';
341
+ case false:
342
+ return '$$__FALSE__$$';
343
+ default:
344
+ return value;
345
+ }
346
+ })
347
+ .replaceAll('"$$__TRUE__$$"', 'True')
348
+ .replaceAll('"$$__FALSE__$$"', 'False');
331
349
  }
332
350
  return { body: body, code: code, headers: headers };
333
351
  },
@@ -0,0 +1,6 @@
1
+ import { type OpenAPIContext } from '../context';
2
+ import type { OpenAPIOperationData, OpenAPIWebhookData } from '../types';
3
+ export declare function OpenAPIColumnSpec(props: {
4
+ data: OpenAPIOperationData | OpenAPIWebhookData;
5
+ context: OpenAPIContext;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { OpenAPISpec } from '../OpenAPISpec';
2
+ import { getOpenAPIClientContext } from '../context';
3
+ import { t } from '../translate';
4
+ import { OpenAPIOperationDescription } from './OpenAPIOperationDescription';
5
+ export function OpenAPIColumnSpec(props) {
6
+ var data = props.data, context = props.context;
7
+ var operation = data.operation;
8
+ var clientContext = getOpenAPIClientContext(context);
9
+ return (<div className="openapi-column-spec">
10
+ {operation['x-deprecated-sunset'] ? (<div className="openapi-deprecated-sunset openapi-description openapi-markdown">
11
+ {t(context.translation, 'deprecated_and_sunset_on', [
12
+ <span key="date" className="openapi-deprecated-sunset-date">
13
+ {operation['x-deprecated-sunset']}
14
+ </span>,
15
+ ])}
16
+ </div>) : null}
17
+ <OpenAPIOperationDescription operation={operation} context={context}/>
18
+ <OpenAPISpec data={data} context={clientContext}/>
19
+ </div>);
20
+ }
@@ -0,0 +1,6 @@
1
+ import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
2
+ import type { OpenAPIContext } from '../context';
3
+ export declare function OpenAPIOperationDescription(props: {
4
+ operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
5
+ context: OpenAPIContext;
6
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,19 @@
1
+ import { Markdown } from '../Markdown';
2
+ import { resolveDescription } from '../utils';
3
+ export function OpenAPIOperationDescription(props) {
4
+ var operation = props.operation;
5
+ if (operation['x-gitbook-description-document']) {
6
+ return (<div className="openapi-intro">
7
+ {props.context.renderDocument({
8
+ document: operation['x-gitbook-description-document'],
9
+ })}
10
+ </div>);
11
+ }
12
+ var description = resolveDescription(operation);
13
+ if (!description) {
14
+ return null;
15
+ }
16
+ return (<div className="openapi-intro">
17
+ <Markdown className="openapi-description" source={description}/>
18
+ </div>);
19
+ }
@@ -0,0 +1,4 @@
1
+ import type { OpenAPIStability as OpenAPIStabilityType } from '@gitbook/openapi-parser';
2
+ export declare function OpenAPIStability(props: {
3
+ stability: OpenAPIStabilityType;
4
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,15 @@
1
+ var stabilityEnum = {
2
+ experimental: 'Experimental',
3
+ alpha: 'Alpha',
4
+ beta: 'Beta',
5
+ };
6
+ export function OpenAPIStability(props) {
7
+ var stability = props.stability;
8
+ var foundStability = stabilityEnum[stability];
9
+ if (!foundStability) {
10
+ return null;
11
+ }
12
+ return (<div className={"openapi-stability openapi-stability-".concat(foundStability.toLowerCase())}>
13
+ {foundStability}
14
+ </div>);
15
+ }
@@ -0,0 +1,6 @@
1
+ import type { OpenAPIContext } from '../context';
2
+ import type { OpenAPIOperationData, OpenAPIWebhookData } from '../types';
3
+ export declare function OpenAPISummary(props: {
4
+ data: OpenAPIOperationData | OpenAPIWebhookData;
5
+ context: OpenAPIContext;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { OpenAPIPath } from '../OpenAPIPath';
2
+ import { OpenAPIStability } from './OpenAPIStability';
3
+ export function OpenAPISummary(props) {
4
+ var _a;
5
+ var data = props.data, context = props.context;
6
+ var operation = data.operation;
7
+ var title = (function () {
8
+ if (operation.summary) {
9
+ return operation.summary;
10
+ }
11
+ if ('name' in data) {
12
+ return data.name;
13
+ }
14
+ return undefined;
15
+ })();
16
+ return (<div className="openapi-summary" id={operation.summary ? undefined : context.id}>
17
+ {(operation.deprecated || operation['x-stability']) && (<div className="openapi-summary-tags">
18
+ {operation.deprecated && <div className="openapi-deprecated">Deprecated</div>}
19
+ {operation['x-stability'] && (<OpenAPIStability stability={operation['x-stability']}/>)}
20
+ </div>)}
21
+ {title
22
+ ? context.renderHeading({
23
+ deprecated: (_a = operation.deprecated) !== null && _a !== void 0 ? _a : false,
24
+ stability: operation['x-stability'],
25
+ title: title,
26
+ })
27
+ : null}
28
+ {'path' in data ? <OpenAPIPath data={data} context={context}/> : null}
29
+ </div>);
30
+ }
package/dist/context.d.ts CHANGED
@@ -1,4 +1,9 @@
1
+ import { type Translation, type TranslationLocale } from './translations';
1
2
  export interface OpenAPIClientContext {
3
+ /**
4
+ * The translation language to use.
5
+ */
6
+ translation: Translation;
2
7
  /**
3
8
  * Icons used in the block.
4
9
  */
@@ -20,8 +25,12 @@ export interface OpenAPIClientContext {
20
25
  * Optional id attached to the heading and used as an anchor.
21
26
  */
22
27
  id?: string;
28
+ /**
29
+ * Mark the context as a client context.
30
+ */
31
+ $$isClientContext$$: true;
23
32
  }
24
- export interface OpenAPIContext extends OpenAPIClientContext {
33
+ export interface OpenAPIContext extends Omit<OpenAPIClientContext, '$$isClientContext$$'> {
25
34
  /**
26
35
  * Render a code block.
27
36
  */
@@ -48,7 +57,19 @@ export interface OpenAPIContext extends OpenAPIClientContext {
48
57
  */
49
58
  specUrl: string;
50
59
  }
60
+ export type OpenAPIUniversalContext = OpenAPIClientContext | OpenAPIContext;
61
+ export interface OpenAPIContextInput extends Omit<OpenAPIContext, 'translation'> {
62
+ /**
63
+ * The translation language to use.
64
+ * @default 'en'
65
+ */
66
+ locale?: TranslationLocale | undefined;
67
+ }
68
+ /**
69
+ * Resolve OpenAPI context from the input.
70
+ */
71
+ export declare function resolveOpenAPIContext(context: OpenAPIContextInput): OpenAPIContext;
51
72
  /**
52
73
  * Get the client context from the OpenAPI context.
53
74
  */
54
- export declare function getOpenAPIClientContext(context: OpenAPIContext): OpenAPIClientContext;
75
+ export declare function getOpenAPIClientContext(context: OpenAPIUniversalContext): OpenAPIClientContext;
package/dist/context.js CHANGED
@@ -1,11 +1,43 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { translations } from './translations';
24
+ /**
25
+ * Resolve OpenAPI context from the input.
26
+ */
27
+ export function resolveOpenAPIContext(context) {
28
+ var locale = context.locale, rest = __rest(context, ["locale"]);
29
+ return __assign(__assign({}, rest), { translation: translations[locale !== null && locale !== void 0 ? locale : 'en'] });
30
+ }
1
31
  /**
2
32
  * Get the client context from the OpenAPI context.
3
33
  */
4
34
  export function getOpenAPIClientContext(context) {
5
35
  return {
36
+ translation: context.translation,
6
37
  icons: context.icons,
7
38
  defaultInteractiveOpened: context.defaultInteractiveOpened,
8
39
  blockKey: context.blockKey,
9
40
  id: context.id,
41
+ $$isClientContext$$: true,
10
42
  };
11
43
  }
@@ -5,6 +5,6 @@ type State = {
5
5
  type Actions = {
6
6
  setKey: (key: Key | null) => void;
7
7
  };
8
- type Store = State & Actions;
8
+ export type Store = State & Actions;
9
9
  export declare const getOrCreateStoreByKey: (storeKey: string, initialKey?: Key) => import("zustand").StoreApi<Store>;
10
10
  export {};
@@ -1,4 +1,3 @@
1
- 'use client';
2
1
  import { createStore } from 'zustand';
3
2
  var createStateStore = function (initial) {
4
3
  return createStore()(function (set) { return ({
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  export * from './schemas';
2
2
  export * from './OpenAPIOperation';
3
+ export * from './OpenAPIWebhook';
3
4
  export * from './OpenAPIOperationContext';
4
5
  export * from './resolveOpenAPIOperation';
5
- export type { OpenAPIOperationData, OpenAPIContext } from './types';
6
+ export * from './resolveOpenAPIWebhook';
7
+ export type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
8
+ export type { OpenAPIContextInput } from './context';
9
+ export { checkIsValidLocale } from './translations';
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from './schemas';
2
2
  export * from './OpenAPIOperation';
3
+ export * from './OpenAPIWebhook';
3
4
  export * from './OpenAPIOperationContext';
4
5
  export * from './resolveOpenAPIOperation';
6
+ export * from './resolveOpenAPIWebhook';
7
+ export { checkIsValidLocale } from './translations';
@@ -0,0 +1,11 @@
1
+ import { fromJSON, toJSON } from 'flatted';
2
+ import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
+ import type { OpenAPIWebhookData } from './types';
4
+ export { fromJSON, toJSON };
5
+ /**
6
+ * Resolve an OpenAPI webhook in a file and compile it to a more usable format.
7
+ */
8
+ export declare function resolveOpenAPIWebhook(filesystem: Filesystem<OpenAPIV3xDocument>, webhookDescriptor: {
9
+ name: string;
10
+ method: string;
11
+ }): Promise<OpenAPIWebhookData | null>;