@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,230 +0,0 @@
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
- import { OpenAPIMediaTypeExamplesBody, OpenAPIMediaTypeExamplesSelector, } from './OpenAPICodeSampleInteractive';
13
- import { OpenAPICodeSampleBody } from './OpenAPICodeSampleSelector';
14
- import { ScalarApiButton } from './ScalarApiButton';
15
- import { codeSampleGenerators } from './code-samples';
16
- import { getOpenAPIClientContext } from './context';
17
- import { generateMediaTypeExamples, generateSchemaExample } from './generateSchemaExample';
18
- import { stringifyOpenAPI } from './stringifyOpenAPI';
19
- import { getDefaultServerURL } from './util/server';
20
- import { checkIsReference } from './utils';
21
- var CUSTOM_CODE_SAMPLES_KEYS = ['x-custom-examples', 'x-code-samples', 'x-codeSamples'];
22
- /**
23
- * Display code samples to execute the operation.
24
- * It supports the Redocly custom syntax as well (https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/)
25
- */
26
- export function OpenAPICodeSample(props) {
27
- var data = props.data, context = props.context;
28
- // If code samples are disabled at operation level, we don't display the code samples.
29
- if (data.operation['x-codeSamples'] === false) {
30
- return null;
31
- }
32
- var customCodeSamples = getCustomCodeSamples(props);
33
- // If code samples are disabled at the top-level and not custom code samples are defined,
34
- // we don't display the code samples.
35
- if (data['x-codeSamples'] === false && !customCodeSamples) {
36
- return null;
37
- }
38
- var samples = customCodeSamples !== null && customCodeSamples !== void 0 ? customCodeSamples : generateCodeSamples(props);
39
- if (samples.length === 0) {
40
- return null;
41
- }
42
- return (<OpenAPICodeSampleBody context={getOpenAPIClientContext(context)} data={data} items={samples} selectIcon={context.icons.chevronDown}/>);
43
- }
44
- /**
45
- * Generate code samples for the operation.
46
- */
47
- function generateCodeSamples(props) {
48
- var _a;
49
- var data = props.data, context = props.context;
50
- var searchParams = new URLSearchParams();
51
- var headersObject = {};
52
- // The parser can sometimes returns invalid parameters (an object instead of an array).
53
- // It should get fixed in scalar, but in the meantime we just ignore the parameters in that case.
54
- var params = Array.isArray(data.operation.parameters) ? data.operation.parameters : [];
55
- params.forEach(function (param) {
56
- if (!param) {
57
- return;
58
- }
59
- if (param.in === 'header' && param.required) {
60
- var example = param.schema
61
- ? generateSchemaExample(param.schema, { mode: 'write' })
62
- : undefined;
63
- if (example !== undefined && param.name) {
64
- headersObject[param.name] =
65
- typeof example !== 'string' ? stringifyOpenAPI(example) : example;
66
- }
67
- }
68
- else if (param.in === 'query' && param.required) {
69
- var example = param.schema
70
- ? generateSchemaExample(param.schema, { mode: 'write' })
71
- : undefined;
72
- if (example !== undefined && param.name) {
73
- searchParams.append(param.name, String(Array.isArray(example) ? example[0] : example));
74
- }
75
- }
76
- });
77
- var requestBody = !checkIsReference(data.operation.requestBody)
78
- ? data.operation.requestBody
79
- : undefined;
80
- var url = getDefaultServerURL(data.servers) +
81
- data.path +
82
- (searchParams.size ? "?".concat(searchParams.toString()) : '');
83
- var genericHeaders = __assign(__assign({}, getSecurityHeaders(data.securities)), headersObject);
84
- var mediaTypeRendererFactories = Object.entries((_a = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
85
- var mediaType = _a[0], mediaTypeObject = _a[1];
86
- return function (generator) {
87
- var mediaTypeHeaders = __assign(__assign({}, genericHeaders), { 'Content-Type': mediaType });
88
- return {
89
- mediaType: mediaType,
90
- element: context.renderCodeBlock({
91
- code: generator.generate({
92
- url: url,
93
- method: data.method,
94
- body: undefined,
95
- headers: mediaTypeHeaders,
96
- }),
97
- syntax: generator.syntax,
98
- }),
99
- examples: generateMediaTypeExamples(mediaTypeObject, {
100
- mode: 'write',
101
- }).map(function (example) { return ({
102
- example: example,
103
- element: context.renderCodeBlock({
104
- code: generator.generate({
105
- url: url,
106
- method: data.method,
107
- body: example.value,
108
- headers: mediaTypeHeaders,
109
- }),
110
- syntax: generator.syntax,
111
- }),
112
- }); }),
113
- };
114
- };
115
- });
116
- return codeSampleGenerators.map(function (generator) {
117
- if (mediaTypeRendererFactories.length > 0) {
118
- var renderers = mediaTypeRendererFactories.map(function (generate) { return generate(generator); });
119
- return {
120
- key: "default-".concat(generator.id),
121
- label: generator.label,
122
- body: (<OpenAPIMediaTypeExamplesBody method={data.method} path={data.path} renderers={renderers} blockKey={context.blockKey}/>),
123
- footer: (<OpenAPICodeSampleFooter renderers={renderers} data={data} context={context}/>),
124
- };
125
- }
126
- return {
127
- key: "default-".concat(generator.id),
128
- label: generator.label,
129
- body: context.renderCodeBlock({
130
- code: generator.generate({
131
- url: url,
132
- method: data.method,
133
- body: undefined,
134
- headers: genericHeaders,
135
- }),
136
- syntax: generator.syntax,
137
- }),
138
- footer: <OpenAPICodeSampleFooter data={data} renderers={[]} context={context}/>,
139
- };
140
- });
141
- }
142
- function OpenAPICodeSampleFooter(props) {
143
- var data = props.data, context = props.context, renderers = props.renderers;
144
- var method = data.method, path = data.path, securities = data.securities, servers = data.servers;
145
- var specUrl = context.specUrl;
146
- var hideTryItPanel = data['x-hideTryItPanel'] || data.operation['x-hideTryItPanel'];
147
- var hasMultipleMediaTypes = renderers.length > 1 || renderers.some(function (renderer) { return renderer.examples.length > 0; });
148
- if (hideTryItPanel && !hasMultipleMediaTypes) {
149
- return null;
150
- }
151
- if (!validateHttpMethod(method)) {
152
- return null;
153
- }
154
- return (<div className="openapi-codesample-footer">
155
- {hasMultipleMediaTypes ? (<OpenAPIMediaTypeExamplesSelector method={data.method} path={data.path} renderers={renderers} selectIcon={context.icons.chevronDown} blockKey={context.blockKey}/>) : (<span />)}
156
- {!hideTryItPanel && (<ScalarApiButton context={getOpenAPIClientContext(context)} method={method} path={path} securities={securities} servers={servers} specUrl={specUrl}/>)}
157
- </div>);
158
- }
159
- /**
160
- * Get custom code samples for the operation.
161
- */
162
- function getCustomCodeSamples(props) {
163
- var data = props.data, context = props.context;
164
- var customCodeSamples = null;
165
- CUSTOM_CODE_SAMPLES_KEYS.forEach(function (key) {
166
- var customSamples = data.operation[key];
167
- if (customSamples && Array.isArray(customSamples)) {
168
- customCodeSamples = customSamples
169
- .filter(function (sample) {
170
- return typeof sample.source === 'string' && typeof sample.lang === 'string';
171
- })
172
- .map(function (sample, index) { return ({
173
- key: "custom-sample-".concat(sample.lang, "-").concat(index),
174
- label: sample.label || sample.lang,
175
- body: context.renderCodeBlock({
176
- code: sample.source,
177
- syntax: sample.lang,
178
- }),
179
- footer: (<OpenAPICodeSampleFooter renderers={[]} data={data} context={context}/>),
180
- }); });
181
- }
182
- });
183
- return customCodeSamples;
184
- }
185
- function getSecurityHeaders(securities) {
186
- var _a;
187
- var _b, _c;
188
- var security = securities[0];
189
- if (!security) {
190
- return {};
191
- }
192
- switch (security[1].type) {
193
- case 'http': {
194
- var scheme = security[1].scheme;
195
- var format = (_b = security[1].bearerFormat) !== null && _b !== void 0 ? _b : 'YOUR_SECRET_TOKEN';
196
- if (scheme === null || scheme === void 0 ? void 0 : scheme.includes('bearer')) {
197
- scheme = 'Bearer';
198
- }
199
- else if (scheme === null || scheme === void 0 ? void 0 : scheme.includes('basic')) {
200
- scheme = 'Basic';
201
- format = 'username:password';
202
- }
203
- else if (scheme === null || scheme === void 0 ? void 0 : scheme.includes('token')) {
204
- scheme = 'Token';
205
- }
206
- return {
207
- Authorization: "".concat(scheme, " ").concat(format),
208
- };
209
- }
210
- case 'apiKey': {
211
- if (security[1].in !== 'header')
212
- return {};
213
- var name_1 = (_c = security[1].name) !== null && _c !== void 0 ? _c : 'Authorization';
214
- return _a = {},
215
- _a[name_1] = 'YOUR_API_KEY',
216
- _a;
217
- }
218
- case 'oauth2': {
219
- return {
220
- Authorization: 'Bearer YOUR_OAUTH2_TOKEN',
221
- };
222
- }
223
- default: {
224
- return {};
225
- }
226
- }
227
- }
228
- function validateHttpMethod(method) {
229
- return ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'].includes(method);
230
- }
@@ -1,14 +0,0 @@
1
- import type { MediaTypeRenderer } from './OpenAPICodeSample';
2
- export declare function OpenAPIMediaTypeExamplesSelector(props: {
3
- method: string;
4
- path: string;
5
- renderers: MediaTypeRenderer[];
6
- selectIcon?: React.ReactNode;
7
- blockKey?: string;
8
- }): import("react").JSX.Element;
9
- export declare function OpenAPIMediaTypeExamplesBody(props: {
10
- method: string;
11
- path: string;
12
- renderers: MediaTypeRenderer[];
13
- blockKey?: string;
14
- }): string | number | boolean | Iterable<import("react").ReactNode> | import("react").JSX.Element | null | undefined;
@@ -1,73 +0,0 @@
1
- 'use client';
2
- import clsx from 'clsx';
3
- import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
4
- import { createStateKey } from './utils';
5
- export function OpenAPIMediaTypeExamplesSelector(props) {
6
- var method = props.method, path = props.path, renderers = props.renderers, selectIcon = props.selectIcon, blockKey = props.blockKey;
7
- if (!renderers[0]) {
8
- throw new Error('No renderers provided');
9
- }
10
- var stateKey = createStateKey('request-body-media-type', blockKey);
11
- var state = useSelectState(stateKey, renderers[0].mediaType);
12
- var selected = renderers.find(function (r) { return r.mediaType === state.key; }) || renderers[0];
13
- return (<div className="openapi-codesample-selectors">
14
- <MediaTypeSelector selectIcon={selectIcon} stateKey={stateKey} renderers={renderers}/>
15
- <ExamplesSelector selectIcon={selectIcon} method={method} path={path} renderer={selected}/>
16
- </div>);
17
- }
18
- function MediaTypeSelector(props) {
19
- var renderers = props.renderers, stateKey = props.stateKey, selectIcon = props.selectIcon;
20
- if (renderers.length < 2) {
21
- return null;
22
- }
23
- var items = renderers.map(function (renderer) { return ({
24
- key: renderer.mediaType,
25
- label: renderer.mediaType,
26
- }); });
27
- return (<OpenAPISelect className={clsx('openapi-select')} items={renderers.map(function (renderer) { return ({
28
- key: renderer.mediaType,
29
- label: renderer.mediaType,
30
- }); })} icon={selectIcon} stateKey={stateKey} placement="bottom start">
31
- {items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
32
- {item.label}
33
- </OpenAPISelectItem>); })}
34
- </OpenAPISelect>);
35
- }
36
- function ExamplesSelector(props) {
37
- var method = props.method, path = props.path, renderer = props.renderer, selectIcon = props.selectIcon;
38
- if (renderer.examples.length < 2) {
39
- return null;
40
- }
41
- var items = renderer.examples.map(function (example, index) { return ({
42
- key: index,
43
- label: example.example.summary || "Example ".concat(index + 1),
44
- }); });
45
- return (<OpenAPISelect items={items} icon={selectIcon} stateKey={"media-type-sample-".concat(renderer.mediaType, "-").concat(method, "-").concat(path)} placement="bottom start">
46
- {items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
47
- {item.label}
48
- </OpenAPISelectItem>); })}
49
- </OpenAPISelect>);
50
- }
51
- export function OpenAPIMediaTypeExamplesBody(props) {
52
- var _a;
53
- var renderers = props.renderers, method = props.method, path = props.path, blockKey = props.blockKey;
54
- if (!renderers[0]) {
55
- throw new Error('No renderers provided');
56
- }
57
- var mediaTypeState = useSelectState(createStateKey('request-body-media-type', blockKey), renderers[0].mediaType);
58
- var selected = (_a = renderers.find(function (r) { return r.mediaType === mediaTypeState.key; })) !== null && _a !== void 0 ? _a : renderers[0];
59
- if (selected.examples.length === 0) {
60
- return selected.element;
61
- }
62
- return <ExamplesBody method={method} path={path} renderer={selected}/>;
63
- }
64
- function ExamplesBody(props) {
65
- var _a;
66
- var method = props.method, path = props.path, renderer = props.renderer;
67
- var exampleState = useSelectState("media-type-sample-".concat(renderer.mediaType, "-").concat(method, "-").concat(path), renderer.mediaType);
68
- var example = (_a = renderer.examples[Number(exampleState.key)]) !== null && _a !== void 0 ? _a : renderer.examples[0];
69
- if (!example) {
70
- throw new Error("No example found for key ".concat(exampleState.key));
71
- }
72
- return example.element;
73
- }
@@ -1,14 +0,0 @@
1
- import { OpenAPISelectItem } from './OpenAPISelect';
2
- import type { OpenAPIClientContext } from './context';
3
- import type { OpenAPIOperationData } from './types';
4
- type CodeSampleItem = OpenAPISelectItem & {
5
- body: React.ReactNode;
6
- footer?: React.ReactNode;
7
- };
8
- export declare function OpenAPICodeSampleBody(props: {
9
- items: CodeSampleItem[];
10
- data: OpenAPIOperationData;
11
- selectIcon?: React.ReactNode;
12
- context: OpenAPIClientContext;
13
- }): import("react").JSX.Element | null;
14
- export {};
@@ -1,44 +0,0 @@
1
- 'use client';
2
- import { useCallback } from 'react';
3
- import { useStore } from 'zustand';
4
- import { OpenAPIPath } from './OpenAPIPath';
5
- import { OpenAPISelect, OpenAPISelectItem } from './OpenAPISelect';
6
- import { StaticSection } from './StaticSection';
7
- import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
8
- function useCodeSampleState(initialKey) {
9
- if (initialKey === void 0) { initialKey = 'default'; }
10
- var store = useStore(getOrCreateStoreByKey('codesample', initialKey));
11
- return {
12
- key: store.key,
13
- setKey: useCallback(function (key) { return store.setKey(key); }, [store.setKey]),
14
- };
15
- }
16
- function OpenAPICodeSampleHeader(props) {
17
- var data = props.data, items = props.items, selectIcon = props.selectIcon, context = props.context;
18
- return (<>
19
- <OpenAPIPath context={context} canCopy={false} withServer={false} data={data}/>
20
- {items.length > 1 ? (<OpenAPISelect icon={selectIcon} items={items} stateKey="codesample" placement="bottom end">
21
- {items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
22
- {item.label}
23
- </OpenAPISelectItem>); })}
24
- </OpenAPISelect>) : items[0] ? (<span className="openapi-codesample-label">{items[0].label}</span>) : null}
25
- </>);
26
- }
27
- export function OpenAPICodeSampleBody(props) {
28
- var _a;
29
- var items = props.items, data = props.data, selectIcon = props.selectIcon, context = props.context;
30
- if (!items[0]) {
31
- throw new Error('No items provided');
32
- }
33
- var state = useCodeSampleState((_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
34
- var selected = items.find(function (item) { return item.key === state.key; }) || items[0];
35
- if (!selected) {
36
- return null;
37
- }
38
- return (<StaticSection header={<OpenAPICodeSampleHeader context={context} selectIcon={selectIcon} data={data} items={items}/>} className="openapi-codesample">
39
- <div id={selected.key} className="openapi-codesample-panel">
40
- {selected.body ? selected.body : null}
41
- {selected.footer ? selected.footer : null}
42
- </div>
43
- </StaticSection>);
44
- }
@@ -1,13 +0,0 @@
1
- import { type ButtonProps } from 'react-aria-components';
2
- import type { OpenAPIClientContext } from './context';
3
- export declare function OpenAPICopyButton(props: ButtonProps & {
4
- value: string;
5
- children: React.ReactNode;
6
- context: OpenAPIClientContext;
7
- label?: string;
8
- /**
9
- * Whether to show a tooltip.
10
- * @default true
11
- */
12
- withTooltip?: boolean;
13
- }): import("react").JSX.Element;
@@ -1,35 +0,0 @@
1
- 'use client';
2
- import { useState } from 'react';
3
- import { Button, Tooltip, TooltipTrigger } from 'react-aria-components';
4
- import { t } from './translate';
5
- export function OpenAPICopyButton(props) {
6
- var value = props.value, label = props.label, children = props.children, onPress = props.onPress, className = props.className, context = props.context, _a = props.withTooltip, withTooltip = _a === void 0 ? true : _a;
7
- var _b = useState(false), copied = _b[0], setCopied = _b[1];
8
- var _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
9
- var handleCopy = function () {
10
- if (!value)
11
- return;
12
- navigator.clipboard.writeText(value).then(function () {
13
- setIsOpen(true);
14
- setCopied(true);
15
- setTimeout(function () {
16
- setCopied(false);
17
- setIsOpen(false);
18
- }, 2000);
19
- });
20
- };
21
- return (<TooltipTrigger isOpen={isOpen} onOpenChange={setIsOpen} isDisabled={!withTooltip} closeDelay={200} delay={200}>
22
- <Button type="button" preventFocusOnPress onPress={function (e) {
23
- handleCopy();
24
- onPress === null || onPress === void 0 ? void 0 : onPress(e);
25
- }} className={"openapi-copy-button ".concat(className)} {...props}>
26
- {children}
27
- </Button>
28
-
29
- <Tooltip isOpen={isOpen} onOpenChange={setIsOpen} placement="top" offset={4} className="openapi-tooltip">
30
- {copied
31
- ? t(context.translation, 'copied')
32
- : label || t(context.translation, 'copy_to_clipboard')}
33
- </Tooltip>
34
- </TooltipTrigger>);
35
- }
@@ -1,11 +0,0 @@
1
- import type React from 'react';
2
- /**
3
- * Display an interactive OpenAPI disclosure.
4
- */
5
- export declare function OpenAPIDisclosure(props: {
6
- icon: React.ReactNode;
7
- header: React.ReactNode;
8
- children: React.ReactNode;
9
- label: string | ((isExpanded: boolean) => string);
10
- className?: string;
11
- }): React.JSX.Element;
@@ -1,30 +0,0 @@
1
- 'use client';
2
- import clsx from 'clsx';
3
- import { useState } from 'react';
4
- import { Button, Disclosure, DisclosurePanel } from 'react-aria-components';
5
- /**
6
- * Display an interactive OpenAPI disclosure.
7
- */
8
- export function OpenAPIDisclosure(props) {
9
- var icon = props.icon, header = props.header, label = props.label, children = props.children, className = props.className;
10
- var _a = useState(false), isExpanded = _a[0], setIsExpanded = _a[1];
11
- return (<Disclosure className={clsx('openapi-disclosure', className)} isExpanded={isExpanded} onExpandedChange={setIsExpanded}>
12
- <Button slot="trigger" className="openapi-disclosure-trigger" style={function (_a) {
13
- var isFocusVisible = _a.isFocusVisible;
14
- return ({
15
- outline: isFocusVisible
16
- ? '2px solid rgb(var(--primary-color-500) / 0.4)'
17
- : 'none',
18
- });
19
- }}>
20
- {header}
21
- <div className="openapi-disclosure-trigger-label">
22
- <span>{typeof label === 'function' ? label(isExpanded) : label}</span>
23
- {icon}
24
- </div>
25
- </Button>
26
- <DisclosurePanel className="openapi-disclosure-panel">
27
- {isExpanded ? children : null}
28
- </DisclosurePanel>
29
- </Disclosure>);
30
- }
@@ -1,23 +0,0 @@
1
- import { type DisclosureGroupProps } from 'react-stately';
2
- interface Props {
3
- groups: TDisclosureGroup[];
4
- icon?: React.ReactNode;
5
- /** State key to use with a store */
6
- selectStateKey?: string;
7
- /** Icon to display for the select */
8
- selectIcon?: React.ReactNode;
9
- }
10
- type TDisclosureGroup = {
11
- key: string;
12
- label: string | React.ReactNode;
13
- tabs?: {
14
- key: string;
15
- label: string | React.ReactNode;
16
- body?: React.ReactNode;
17
- }[];
18
- };
19
- /**
20
- * Display an interactive OpenAPI disclosure group.
21
- */
22
- export declare function OpenAPIDisclosureGroup(props: DisclosureGroupProps & Props): import("react").JSX.Element;
23
- export {};
@@ -1,83 +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
- import { createContext, useContext, useRef } from 'react';
14
- import { mergeProps, useButton, useDisclosure, useFocusRing, useId } from 'react-aria';
15
- import { useDisclosureGroupState, useDisclosureState, } from 'react-stately';
16
- import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
17
- var DisclosureGroupStateContext = createContext(null);
18
- /**
19
- * Display an interactive OpenAPI disclosure group.
20
- */
21
- export function OpenAPIDisclosureGroup(props) {
22
- var icon = props.icon, groups = props.groups, selectStateKey = props.selectStateKey, selectIcon = props.selectIcon;
23
- var state = useDisclosureGroupState(props);
24
- return (<DisclosureGroupStateContext.Provider value={state}>
25
- {groups.map(function (group) { return (<DisclosureItem selectStateKey={selectStateKey} selectIcon={selectIcon} icon={icon} key={group.key} group={group}/>); })}
26
- </DisclosureGroupStateContext.Provider>);
27
- }
28
- function DisclosureItem(props) {
29
- var _a, _b, _c, _d, _e, _f, _g;
30
- var icon = props.icon, group = props.group, selectStateKey = props.selectStateKey, selectIcon = props.selectIcon;
31
- var defaultId = useId();
32
- var id = group.key || defaultId;
33
- var groupState = useContext(DisclosureGroupStateContext);
34
- var isExpanded = (groupState === null || groupState === void 0 ? void 0 : groupState.expandedKeys.has(id)) || false;
35
- var state = useDisclosureState({
36
- isExpanded: isExpanded,
37
- onExpandedChange: function () {
38
- if (groupState) {
39
- groupState.toggleKey(id);
40
- }
41
- },
42
- });
43
- var panelRef = useRef(null);
44
- var triggerRef = useRef(null);
45
- var isDisabled = (groupState === null || groupState === void 0 ? void 0 : groupState.isDisabled) || !((_a = group.tabs) === null || _a === void 0 ? void 0 : _a.length) || false;
46
- var _h = useDisclosure(__assign(__assign({}, props), { isExpanded: isExpanded, isDisabled: isDisabled }), state, panelRef), triggerProps = _h.buttonProps, panelProps = _h.panelProps;
47
- var buttonProps = useButton(triggerProps, triggerRef).buttonProps;
48
- var _j = useFocusRing(), isFocusVisible = _j.isFocusVisible, focusProps = _j.focusProps;
49
- var defaultTab = ((_c = (_b = group.tabs) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.key) || '';
50
- var store = useSelectState(selectStateKey, defaultTab);
51
- var selectedTab = ((_d = group.tabs) === null || _d === void 0 ? void 0 : _d.find(function (tab) { return tab.key === store.key; })) || ((_e = group.tabs) === null || _e === void 0 ? void 0 : _e[0]);
52
- return (<div className="openapi-disclosure-group" aria-expanded={state.isExpanded}>
53
- <div slot="trigger" ref={triggerRef} {...mergeProps(buttonProps, focusProps)} aria-disabled={isDisabled} style={{
54
- outline: isFocusVisible
55
- ? '2px solid rgb(var(--primary-color-500)/0.4)'
56
- : 'none',
57
- }} className="openapi-disclosure-group-trigger">
58
- <div className="openapi-disclosure-group-icon">
59
- {icon || (<svg viewBox="0 0 24 24" className="openapi-disclosure-group-icon">
60
- <path d="m8.25 4.5 7.5 7.5-7.5 7.5"/>
61
- </svg>)}
62
- </div>
63
-
64
- <div className="openapi-disclosure-group-label">
65
- {group.label}
66
-
67
- {group.tabs ? (<div className="openapi-disclosure-group-mediatype" onClick={function (e) { return e.stopPropagation(); }}>
68
- {((_f = group.tabs) === null || _f === void 0 ? void 0 : _f.length) > 1 ? (<OpenAPISelect icon={selectIcon} stateKey={selectStateKey} onSelectionChange={function () {
69
- state.expand();
70
- }} items={group.tabs} placement="bottom end">
71
- {group.tabs.map(function (tab) { return (<OpenAPISelectItem key={tab.key} id={tab.key} value={tab}>
72
- {tab.label}
73
- </OpenAPISelectItem>); })}
74
- </OpenAPISelect>) : ((_g = group.tabs[0]) === null || _g === void 0 ? void 0 : _g.label) ? (<span>{group.tabs[0].label}</span>) : null}
75
- </div>) : null}
76
- </div>
77
- </div>
78
-
79
- {state.isExpanded && selectedTab && (<div className="openapi-disclosure-group-panel" ref={panelRef} {...panelProps}>
80
- {selectedTab.body}
81
- </div>)}
82
- </div>);
83
- }
@@ -1,16 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIContext, OpenAPIUniversalContext } from './context';
3
- /**
4
- * Display an example.
5
- */
6
- export declare function OpenAPIExample(props: {
7
- example: OpenAPIV3.ExampleObject;
8
- context: OpenAPIContext;
9
- syntax: string;
10
- }): string | number | boolean | Iterable<import("react").ReactNode> | import("react").JSX.Element | null | undefined;
11
- /**
12
- * Empty response example.
13
- */
14
- export declare function OpenAPIEmptyExample(props: {
15
- context: OpenAPIUniversalContext;
16
- }): import("react").JSX.Element;
@@ -1,36 +0,0 @@
1
- import { json2xml } from './json2xml';
2
- import { stringifyOpenAPI } from './stringifyOpenAPI';
3
- import { t } from './translate';
4
- /**
5
- * Display an example.
6
- */
7
- export function OpenAPIExample(props) {
8
- var example = props.example, context = props.context, syntax = props.syntax;
9
- var code = stringifyExample({ example: example, xml: syntax === 'xml' });
10
- if (code === null) {
11
- return <OpenAPIEmptyExample context={context}/>;
12
- }
13
- return context.renderCodeBlock({ code: code, syntax: syntax });
14
- }
15
- function stringifyExample(args) {
16
- var example = args.example, xml = args.xml;
17
- if (!example.value) {
18
- return null;
19
- }
20
- if (typeof example.value === 'string') {
21
- return example.value;
22
- }
23
- if (xml) {
24
- return json2xml(example.value);
25
- }
26
- return stringifyOpenAPI(example.value, null, 2);
27
- }
28
- /**
29
- * Empty response example.
30
- */
31
- export function OpenAPIEmptyExample(props) {
32
- var context = props.context;
33
- return (<pre className="openapi-example-empty">
34
- <p>{t(context.translation, 'no_content')}</p>
35
- </pre>);
36
- }
@@ -1,21 +0,0 @@
1
- import type { Key } from 'react-aria';
2
- import { OpenAPISelectItem } from './OpenAPISelect';
3
- import type { OpenAPIClientContext } from './context';
4
- type OpenAPIMediaTypeItem = OpenAPISelectItem & {
5
- body: React.ReactNode;
6
- examples?: OpenAPIMediaTypeItem[];
7
- };
8
- /**
9
- * Get the state of the response examples select.
10
- */
11
- export declare function useMediaTypesState(stateKey: string | undefined, initialKey?: Key): {
12
- key: (string | number) | null;
13
- setKey: (key: Key | null) => void;
14
- };
15
- export declare function OpenAPIMediaTypeContent(props: {
16
- items: OpenAPIMediaTypeItem[];
17
- selectIcon?: React.ReactNode;
18
- stateKey: string;
19
- context: OpenAPIClientContext;
20
- }): import("react").JSX.Element | null;
21
- export {};