@gitbook/react-openapi 1.4.2 → 1.5.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 (225) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/index.d.ts +663 -10
  3. package/dist/index.js +3873 -8
  4. package/package.json +11 -7
  5. package/dist/InteractiveSection.d.ts +0 -33
  6. package/dist/InteractiveSection.jsx +0 -61
  7. package/dist/Markdown.d.ts +0 -4
  8. package/dist/Markdown.jsx +0 -5
  9. package/dist/OpenAPICodeSample.d.ts +0 -19
  10. package/dist/OpenAPICodeSample.jsx +0 -230
  11. package/dist/OpenAPICodeSampleInteractive.d.ts +0 -14
  12. package/dist/OpenAPICodeSampleInteractive.jsx +0 -73
  13. package/dist/OpenAPICodeSampleSelector.d.ts +0 -14
  14. package/dist/OpenAPICodeSampleSelector.jsx +0 -44
  15. package/dist/OpenAPICopyButton.d.ts +0 -13
  16. package/dist/OpenAPICopyButton.jsx +0 -35
  17. package/dist/OpenAPIDisclosure.d.ts +0 -11
  18. package/dist/OpenAPIDisclosure.jsx +0 -30
  19. package/dist/OpenAPIDisclosureGroup.d.ts +0 -23
  20. package/dist/OpenAPIDisclosureGroup.jsx +0 -83
  21. package/dist/OpenAPIExample.d.ts +0 -16
  22. package/dist/OpenAPIExample.jsx +0 -36
  23. package/dist/OpenAPIMediaType.d.ts +0 -21
  24. package/dist/OpenAPIMediaType.jsx +0 -61
  25. package/dist/OpenAPIOperation.d.ts +0 -10
  26. package/dist/OpenAPIOperation.jsx +0 -25
  27. package/dist/OpenAPIOperationContext.d.ts +0 -16
  28. package/dist/OpenAPIOperationContext.jsx +0 -26
  29. package/dist/OpenAPIOperationDescription.d.ts +0 -9
  30. package/dist/OpenAPIOperationDescription.jsx +0 -22
  31. package/dist/OpenAPIOperationStability.d.ts +0 -9
  32. package/dist/OpenAPIOperationStability.jsx +0 -27
  33. package/dist/OpenAPIPath.d.ts +0 -18
  34. package/dist/OpenAPIPath.jsx +0 -55
  35. package/dist/OpenAPIPrefillContextProvider.d.ts +0 -22
  36. package/dist/OpenAPIPrefillContextProvider.jsx +0 -19
  37. package/dist/OpenAPIRequestBody.d.ts +0 -11
  38. package/dist/OpenAPIRequestBody.jsx +0 -28
  39. package/dist/OpenAPIRequestBodyHeaderType.d.ts +0 -8
  40. package/dist/OpenAPIRequestBodyHeaderType.jsx +0 -25
  41. package/dist/OpenAPIResponse.d.ts +0 -10
  42. package/dist/OpenAPIResponse.jsx +0 -57
  43. package/dist/OpenAPIResponseExample.d.ts +0 -9
  44. package/dist/OpenAPIResponseExample.jsx +0 -105
  45. package/dist/OpenAPIResponseExampleContent.d.ts +0 -22
  46. package/dist/OpenAPIResponseExampleContent.jsx +0 -60
  47. package/dist/OpenAPIResponses.d.ts +0 -9
  48. package/dist/OpenAPIResponses.jsx +0 -77
  49. package/dist/OpenAPISchema.d.ts +0 -27
  50. package/dist/OpenAPISchema.jsx +0 -400
  51. package/dist/OpenAPISchemaName.d.ts +0 -16
  52. package/dist/OpenAPISchemaName.jsx +0 -43
  53. package/dist/OpenAPISchemaServer.d.ts +0 -12
  54. package/dist/OpenAPISchemaServer.jsx +0 -8
  55. package/dist/OpenAPISecurities.d.ts +0 -9
  56. package/dist/OpenAPISecurities.jsx +0 -114
  57. package/dist/OpenAPISelect.d.ts +0 -22
  58. package/dist/OpenAPISelect.jsx +0 -44
  59. package/dist/OpenAPISpec.d.ts +0 -6
  60. package/dist/OpenAPISpec.jsx +0 -80
  61. package/dist/OpenAPITabs.d.ts +0 -26
  62. package/dist/OpenAPITabs.jsx +0 -109
  63. package/dist/OpenAPIWebhook.d.ts +0 -10
  64. package/dist/OpenAPIWebhook.jsx +0 -23
  65. package/dist/OpenAPIWebhookExample.d.ts +0 -6
  66. package/dist/OpenAPIWebhookExample.jsx +0 -41
  67. package/dist/ScalarApiButton.d.ts +0 -14
  68. package/dist/ScalarApiButton.jsx +0 -81
  69. package/dist/StaticSection.d.ts +0 -13
  70. package/dist/StaticSection.jsx +0 -32
  71. package/dist/code-samples.d.ts +0 -17
  72. package/dist/code-samples.js +0 -427
  73. package/dist/common/OpenAPIColumnSpec.d.ts +0 -6
  74. package/dist/common/OpenAPIColumnSpec.jsx +0 -20
  75. package/dist/common/OpenAPIOperationDescription.d.ts +0 -6
  76. package/dist/common/OpenAPIOperationDescription.jsx +0 -19
  77. package/dist/common/OpenAPIStability.d.ts +0 -4
  78. package/dist/common/OpenAPIStability.jsx +0 -15
  79. package/dist/common/OpenAPISummary.d.ts +0 -6
  80. package/dist/common/OpenAPISummary.jsx +0 -30
  81. package/dist/contentTypeChecks.d.ts +0 -10
  82. package/dist/contentTypeChecks.js +0 -30
  83. package/dist/context.d.ts +0 -75
  84. package/dist/context.js +0 -43
  85. package/dist/decycle.d.ts +0 -2
  86. package/dist/decycle.js +0 -70
  87. package/dist/dereference.d.ts +0 -5
  88. package/dist/dereference.js +0 -68
  89. package/dist/generateSchemaExample.d.ts +0 -45
  90. package/dist/generateSchemaExample.js +0 -342
  91. package/dist/getDisclosureLabel.d.ts +0 -7
  92. package/dist/getDisclosureLabel.js +0 -18
  93. package/dist/getOrCreateStoreByKey.d.ts +0 -10
  94. package/dist/getOrCreateStoreByKey.js +0 -19
  95. package/dist/json2xml.d.ts +0 -4
  96. package/dist/json2xml.js +0 -7
  97. package/dist/resolveOpenAPIOperation.d.ts +0 -11
  98. package/dist/resolveOpenAPIOperation.js +0 -173
  99. package/dist/resolveOpenAPIWebhook.d.ts +0 -11
  100. package/dist/resolveOpenAPIWebhook.js +0 -127
  101. package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
  102. package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
  103. package/dist/schemas/OpenAPISchemas.d.ts +0 -14
  104. package/dist/schemas/OpenAPISchemas.jsx +0 -59
  105. package/dist/schemas/index.d.ts +0 -2
  106. package/dist/schemas/index.js +0 -2
  107. package/dist/schemas/resolveOpenAPISchemas.d.ts +0 -10
  108. package/dist/schemas/resolveOpenAPISchemas.js +0 -61
  109. package/dist/stringifyOpenAPI.d.ts +0 -4
  110. package/dist/stringifyOpenAPI.js +0 -15
  111. package/dist/translate.d.ts +0 -10
  112. package/dist/translate.jsx +0 -75
  113. package/dist/translations/de.d.ts +0 -43
  114. package/dist/translations/de.js +0 -43
  115. package/dist/translations/en.d.ts +0 -43
  116. package/dist/translations/en.js +0 -43
  117. package/dist/translations/es.d.ts +0 -43
  118. package/dist/translations/es.js +0 -43
  119. package/dist/translations/fr.d.ts +0 -43
  120. package/dist/translations/fr.js +0 -43
  121. package/dist/translations/index.d.ts +0 -395
  122. package/dist/translations/index.js +0 -27
  123. package/dist/translations/ja.d.ts +0 -43
  124. package/dist/translations/ja.js +0 -43
  125. package/dist/translations/nl.d.ts +0 -43
  126. package/dist/translations/nl.js +0 -43
  127. package/dist/translations/no.d.ts +0 -43
  128. package/dist/translations/no.js +0 -43
  129. package/dist/translations/pt-br.d.ts +0 -43
  130. package/dist/translations/pt-br.js +0 -43
  131. package/dist/translations/types.d.ts +0 -5
  132. package/dist/translations/types.js +0 -1
  133. package/dist/translations/zh.d.ts +0 -43
  134. package/dist/translations/zh.js +0 -43
  135. package/dist/tsconfig.build.tsbuildinfo +0 -1
  136. package/dist/types.d.ts +0 -31
  137. package/dist/types.js +0 -1
  138. package/dist/util/example.d.ts +0 -35
  139. package/dist/util/example.jsx +0 -103
  140. package/dist/util/server.d.ts +0 -9
  141. package/dist/util/server.js +0 -44
  142. package/dist/util/tryit-prefill.d.ts +0 -20
  143. package/dist/util/tryit-prefill.js +0 -129
  144. package/dist/utils.d.ts +0 -50
  145. package/dist/utils.js +0 -224
  146. package/src/InteractiveSection.tsx +0 -147
  147. package/src/Markdown.tsx +0 -12
  148. package/src/OpenAPICodeSample.tsx +0 -330
  149. package/src/OpenAPICodeSampleInteractive.tsx +0 -136
  150. package/src/OpenAPICodeSampleSelector.tsx +0 -94
  151. package/src/OpenAPICopyButton.tsx +0 -72
  152. package/src/OpenAPIDisclosure.tsx +0 -46
  153. package/src/OpenAPIDisclosureGroup.tsx +0 -158
  154. package/src/OpenAPIExample.tsx +0 -55
  155. package/src/OpenAPIMediaType.tsx +0 -139
  156. package/src/OpenAPIOperation.tsx +0 -35
  157. package/src/OpenAPIOperationContext.tsx +0 -45
  158. package/src/OpenAPIOperationDescription.tsx +0 -34
  159. package/src/OpenAPIOperationStability.tsx +0 -39
  160. package/src/OpenAPIPath.tsx +0 -90
  161. package/src/OpenAPIPrefillContextProvider.tsx +0 -40
  162. package/src/OpenAPIRequestBody.tsx +0 -54
  163. package/src/OpenAPIRequestBodyHeaderType.tsx +0 -36
  164. package/src/OpenAPIResponse.tsx +0 -82
  165. package/src/OpenAPIResponseExample.tsx +0 -151
  166. package/src/OpenAPIResponseExampleContent.tsx +0 -125
  167. package/src/OpenAPIResponses.tsx +0 -125
  168. package/src/OpenAPISchema.test.ts +0 -172
  169. package/src/OpenAPISchema.tsx +0 -654
  170. package/src/OpenAPISchemaName.tsx +0 -80
  171. package/src/OpenAPISchemaServer.tsx +0 -34
  172. package/src/OpenAPISecurities.tsx +0 -231
  173. package/src/OpenAPISelect.tsx +0 -96
  174. package/src/OpenAPISpec.tsx +0 -138
  175. package/src/OpenAPITabs.tsx +0 -147
  176. package/src/OpenAPIWebhook.tsx +0 -33
  177. package/src/OpenAPIWebhookExample.tsx +0 -60
  178. package/src/ScalarApiButton.tsx +0 -132
  179. package/src/StaticSection.tsx +0 -91
  180. package/src/__snapshots__/json2xml.test.ts.snap +0 -18
  181. package/src/code-samples.test.ts +0 -714
  182. package/src/code-samples.ts +0 -448
  183. package/src/common/OpenAPIColumnSpec.tsx +0 -31
  184. package/src/common/OpenAPIOperationDescription.tsx +0 -31
  185. package/src/common/OpenAPIStability.tsx +0 -23
  186. package/src/common/OpenAPISummary.tsx +0 -45
  187. package/src/contentTypeChecks.ts +0 -39
  188. package/src/context.ts +0 -99
  189. package/src/decycle.ts +0 -68
  190. package/src/dereference.ts +0 -29
  191. package/src/generateSchemaExample.test.ts +0 -1040
  192. package/src/generateSchemaExample.ts +0 -530
  193. package/src/getDisclosureLabel.ts +0 -25
  194. package/src/getOrCreateStoreByKey.ts +0 -33
  195. package/src/index.ts +0 -10
  196. package/src/json2xml.test.ts +0 -46
  197. package/src/json2xml.ts +0 -8
  198. package/src/resolveOpenAPIOperation.test.ts +0 -177
  199. package/src/resolveOpenAPIOperation.ts +0 -151
  200. package/src/resolveOpenAPIWebhook.ts +0 -99
  201. package/src/schemas/OpenAPISchemaItem.tsx +0 -34
  202. package/src/schemas/OpenAPISchemas.tsx +0 -98
  203. package/src/schemas/index.ts +0 -2
  204. package/src/schemas/resolveOpenAPISchemas.test.ts +0 -174
  205. package/src/schemas/resolveOpenAPISchemas.ts +0 -28
  206. package/src/stringifyOpenAPI.ts +0 -25
  207. package/src/translate.tsx +0 -80
  208. package/src/translations/de.ts +0 -43
  209. package/src/translations/en.ts +0 -43
  210. package/src/translations/es.ts +0 -43
  211. package/src/translations/fr.ts +0 -43
  212. package/src/translations/index.ts +0 -33
  213. package/src/translations/ja.ts +0 -43
  214. package/src/translations/nl.ts +0 -43
  215. package/src/translations/no.ts +0 -43
  216. package/src/translations/pt-br.ts +0 -43
  217. package/src/translations/types.ts +0 -7
  218. package/src/translations/zh.ts +0 -43
  219. package/src/types.ts +0 -46
  220. package/src/util/example.tsx +0 -129
  221. package/src/util/server.test.ts +0 -58
  222. package/src/util/server.ts +0 -47
  223. package/src/util/tryit-prefill.test.ts +0 -311
  224. package/src/util/tryit-prefill.ts +0 -160
  225. package/src/utils.ts +0 -255
@@ -1,427 +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 yaml from 'js-yaml';
13
- import { isCSV, isFormData, isFormUrlEncoded, isGraphQL, isJSON, isPDF, isPlainObject, isText, isXML, isYAML, } from './contentTypeChecks';
14
- import { json2xml } from './json2xml';
15
- import { stringifyOpenAPI } from './stringifyOpenAPI';
16
- export var codeSampleGenerators = [
17
- {
18
- id: 'http',
19
- label: 'HTTP',
20
- syntax: 'http',
21
- generate: function (_a) {
22
- var method = _a.method, url = _a.url, _b = _a.headers, headers = _b === void 0 ? {} : _b, body = _a.body;
23
- var _c = parseHostAndPath(url), host = _c.host, path = _c.path;
24
- if (body) {
25
- // if we had a body add a content length header
26
- var bodyContent = body ? stringifyOpenAPI(body) : '';
27
- // handle unicode chars with a text encoder
28
- var encoder = new TextEncoder();
29
- var bodyString_1 = BodyGenerators.getHTTPBody(body, headers);
30
- if (bodyString_1) {
31
- body = bodyString_1;
32
- }
33
- headers = __assign(__assign({}, headers), { 'Content-Length': encoder.encode(bodyContent).length.toString() });
34
- }
35
- if (!headers.hasOwnProperty('Accept')) {
36
- headers.Accept = '*/*';
37
- }
38
- var headerString = headers
39
- ? "".concat(Object.entries(headers)
40
- .map(function (_a) {
41
- var key = _a[0], value = _a[1];
42
- return key.toLowerCase() !== 'host' ? "".concat(key, ": ").concat(value) : '';
43
- })
44
- .join('\n'), "\n")
45
- : '';
46
- var bodyString = body ? "\n".concat(body) : '';
47
- var httpRequest = "".concat(method.toUpperCase(), " ").concat(decodeURI(path), " HTTP/1.1\nHost: ").concat(host, "\n").concat(headerString).concat(bodyString);
48
- return httpRequest;
49
- },
50
- },
51
- {
52
- id: 'curl',
53
- label: 'cURL',
54
- syntax: 'bash',
55
- generate: function (_a) {
56
- var method = _a.method, url = _a.url, headers = _a.headers, body = _a.body;
57
- var separator = ' \\\n';
58
- var lines = ['curl -L'];
59
- if (method.toUpperCase() !== 'GET') {
60
- lines.push("--request ".concat(method.toUpperCase()));
61
- }
62
- lines.push("--url '".concat(url, "'"));
63
- if (body) {
64
- var bodyContent = BodyGenerators.getCurlBody(body, headers);
65
- if (bodyContent) {
66
- body = bodyContent.body;
67
- headers = bodyContent.headers;
68
- }
69
- }
70
- if (headers && Object.keys(headers).length > 0) {
71
- Object.entries(headers).forEach(function (_a) {
72
- var key = _a[0], value = _a[1];
73
- lines.push("--header '".concat(key, ": ").concat(value, "'"));
74
- });
75
- }
76
- if (body) {
77
- if (Array.isArray(body)) {
78
- lines.push.apply(lines, body);
79
- }
80
- else {
81
- lines.push(body);
82
- }
83
- }
84
- return lines.map(function (line, index) { return (index > 0 ? indent(line, 2) : line); }).join(separator);
85
- },
86
- },
87
- {
88
- id: 'javascript',
89
- label: 'JavaScript',
90
- syntax: 'javascript',
91
- generate: function (_a) {
92
- var method = _a.method, url = _a.url, headers = _a.headers, body = _a.body;
93
- var code = '';
94
- if (body) {
95
- var lines = BodyGenerators.getJavaScriptBody(body, headers);
96
- if (lines) {
97
- // add the generated code to the top
98
- code += lines.code;
99
- body = lines.body;
100
- headers = lines.headers;
101
- }
102
- }
103
- code += "const response = await fetch('".concat(url, "', {\n method: '").concat(method.toUpperCase(), "',\n");
104
- if (headers && Object.keys(headers).length > 0) {
105
- code += indent("headers: ".concat(stringifyOpenAPI(headers, null, 2), ",\n"), 4);
106
- }
107
- if (body) {
108
- code += indent("body: ".concat(body, "\n"), 4);
109
- }
110
- code += '});\n\n';
111
- code += 'const data = await response.json();';
112
- return code;
113
- },
114
- },
115
- {
116
- id: 'python',
117
- label: 'Python',
118
- syntax: 'python',
119
- generate: function (_a) {
120
- var method = _a.method, url = _a.url, headers = _a.headers, body = _a.body;
121
- var contentType = headers === null || headers === void 0 ? void 0 : headers['Content-Type'];
122
- var code = "".concat(isJSON(contentType) ? 'import json\n' : '', "import requests\n\n");
123
- if (body) {
124
- var lines = BodyGenerators.getPythonBody(body, headers);
125
- // add the generated code to the top
126
- if (lines) {
127
- code += lines.code;
128
- body = lines.body;
129
- headers = lines.headers;
130
- }
131
- }
132
- code += "response = requests.".concat(method.toLowerCase(), "(\n");
133
- code += indent("\"".concat(url, "\",\n"), 4);
134
- if (headers && Object.keys(headers).length > 0) {
135
- code += indent("headers=".concat(stringifyOpenAPI(headers), ",\n"), 4);
136
- }
137
- if (body) {
138
- if (body === 'files') {
139
- code += indent("files=".concat(body, "\n"), 4);
140
- }
141
- else if (isJSON(contentType)) {
142
- code += indent("data=json.dumps(".concat(body, ")\n"), 4);
143
- }
144
- else {
145
- code += indent("data=".concat(body, "\n"), 4);
146
- }
147
- }
148
- code += ')\n\n';
149
- code += 'data = response.json()';
150
- return code;
151
- },
152
- },
153
- ];
154
- function indent(code, spaces) {
155
- var indent = ' '.repeat(spaces);
156
- return code
157
- .split('\n')
158
- .map(function (line) { return (line ? indent + line : ''); })
159
- .join('\n');
160
- }
161
- export function parseHostAndPath(url) {
162
- try {
163
- var urlObj = new URL(url);
164
- var path = urlObj.pathname || '/';
165
- return { host: urlObj.host, path: path };
166
- }
167
- catch (_e) {
168
- // If the URL was invalid do our best to parse the URL.
169
- // Check for the protocol part and pull it off to grab the host
170
- var splitted = url.split('//');
171
- var fullUrl = splitted[1] ? splitted[1] : url;
172
- // separate paths from the first element (host)
173
- var parts = fullUrl.split('/');
174
- // pull off the host (mutates)
175
- var host = parts.shift();
176
- // add a leading slash and join the paths again
177
- var path = "/".concat(parts.join('/'));
178
- return { host: host, path: path };
179
- }
180
- }
181
- // Body Generators
182
- var BodyGenerators = {
183
- getCurlBody: function (body, headers) {
184
- if (!body || !headers)
185
- return undefined;
186
- // Copy headers to avoid mutating the original object
187
- var headersCopy = __assign({}, headers);
188
- var contentType = headersCopy['Content-Type'] || '';
189
- if (isFormData(contentType)) {
190
- body = isPlainObject(body)
191
- ? Object.entries(body).map(function (_a) {
192
- var key = _a[0], value = _a[1];
193
- return "--form '".concat(key, "=").concat(String(value), "'");
194
- })
195
- : "--form 'file=@".concat(body, "'");
196
- }
197
- else if (isFormUrlEncoded(contentType)) {
198
- body = isPlainObject(body)
199
- ? "--data '".concat(Object.entries(body)
200
- .map(function (_a) {
201
- var key = _a[0], value = _a[1];
202
- return "".concat(key, "=").concat(String(value));
203
- })
204
- .join('&'), "'")
205
- : String(body);
206
- }
207
- else if (isText(contentType)) {
208
- body = "--data '".concat(String(body).replace(/"/g, ''), "'");
209
- }
210
- else if (isXML(contentType)) {
211
- // Convert to XML and ensure proper formatting
212
- body = "--data-binary $'".concat(convertBodyToXML(body), "'");
213
- }
214
- else if (isCSV(contentType)) {
215
- // We use --data-binary to avoid cURL converting newlines to \r\n
216
- body = "--data-binary $'".concat(stringifyOpenAPI(body).replace(/"/g, '').replace(/\\n/g, '\n'), "'");
217
- }
218
- else if (isGraphQL(contentType)) {
219
- body = "--data '".concat(stringifyOpenAPI(body), "'");
220
- // Set Content-Type to application/json for GraphQL, recommended by GraphQL spec
221
- headersCopy['Content-Type'] = 'application/json';
222
- }
223
- else if (isPDF(contentType)) {
224
- // We use --data-binary to avoid cURL converting newlines to \r\n
225
- body = "--data-binary '@".concat(String(body), "'");
226
- }
227
- else if (isYAML(contentType)) {
228
- body = "--data-binary $'".concat(yaml.dump(body).replace(/'/g, '').replace(/\\n/g, '\n'), "'");
229
- }
230
- else {
231
- body = "--data '".concat(stringifyOpenAPI(body, null, 2).replace(/\\n/g, '\n'), "'");
232
- }
233
- return {
234
- body: body,
235
- headers: headersCopy,
236
- };
237
- },
238
- getJavaScriptBody: function (body, headers) {
239
- if (!body || !headers)
240
- return;
241
- var code = '';
242
- // Copy headers to avoid mutating the original object
243
- var headersCopy = __assign({}, headers);
244
- var contentType = headersCopy['Content-Type'] || '';
245
- // Use FormData for file uploads
246
- if (isFormData(contentType)) {
247
- code += 'const formData = new FormData();\n\n';
248
- if (isPlainObject(body)) {
249
- Object.entries(body).forEach(function (_a) {
250
- var key = _a[0], value = _a[1];
251
- code += "formData.append(\"".concat(key, "\", \"").concat(String(value), "\");\n");
252
- });
253
- }
254
- else if (typeof body === 'string') {
255
- code += "formData.append(\"file\", \"".concat(body, "\");\n");
256
- }
257
- code += '\n';
258
- body = 'formData';
259
- }
260
- else if (isFormUrlEncoded(contentType)) {
261
- // Use URLSearchParams for form-urlencoded data
262
- code += 'const params = new URLSearchParams();\n\n';
263
- if (isPlainObject(body)) {
264
- Object.entries(body).forEach(function (_a) {
265
- var key = _a[0], value = _a[1];
266
- code += "params.append(\"".concat(key, "\", \"").concat(String(value), "\");\n");
267
- });
268
- }
269
- code += '\n';
270
- body = 'params.toString()';
271
- }
272
- else if (isGraphQL(contentType)) {
273
- if (isPlainObject(body)) {
274
- Object.entries(body).forEach(function (_a) {
275
- var key = _a[0], value = _a[1];
276
- code += "const ".concat(key, " = `\n").concat(indent(String(value), 4), "`;\n\n");
277
- });
278
- body = "JSON.stringify({ ".concat(Object.keys(body).join(', '), " })");
279
- // Set Content-Type to application/json for GraphQL, recommended by GraphQL spec
280
- headersCopy['Content-Type'] = 'application/json';
281
- }
282
- else {
283
- code += "const query = `\n".concat(indent(String(body), 4), "`;\n\n");
284
- body = 'JSON.stringify(query)';
285
- }
286
- }
287
- else if (isCSV(contentType)) {
288
- code += 'const csv = `\n';
289
- code += indent(String(body), 4);
290
- code += '`;\n\n';
291
- body = 'csv';
292
- }
293
- else if (isPDF(contentType)) {
294
- // Use FormData to upload PDF files
295
- code += 'const formData = new FormData();\n\n';
296
- code += "formData.append(\"file\", \"".concat(body, "\");\n\n");
297
- body = 'formData';
298
- }
299
- else if (isXML(contentType)) {
300
- code += 'const xml = `\n';
301
- // Convert JSON to XML if needed
302
- code += indent(convertBodyToXML(body), 4);
303
- code += '`;\n\n';
304
- body = 'xml';
305
- }
306
- else if (isYAML(contentType)) {
307
- code += "const yamlBody = `\n".concat(indent(yaml.dump(body), 4), "`;\n\n");
308
- body = 'yamlBody';
309
- }
310
- else if (isText(contentType)) {
311
- body = stringifyOpenAPI(body, null, 2);
312
- }
313
- else {
314
- body = "JSON.stringify(".concat(stringifyOpenAPI(body, null, 2), ")");
315
- }
316
- return { body: body, code: code, headers: headersCopy };
317
- },
318
- getPythonBody: function (body, headers) {
319
- if (!body || !headers)
320
- return;
321
- var code = '';
322
- var contentType = headers['Content-Type'] || '';
323
- if (isFormData(contentType)) {
324
- code += 'files = {\n';
325
- if (isPlainObject(body)) {
326
- Object.entries(body).forEach(function (_a) {
327
- var key = _a[0], value = _a[1];
328
- code += "".concat(indent("\"".concat(key, "\": \"").concat(String(value), "\","), 4), "\n");
329
- });
330
- }
331
- code += '}\n\n';
332
- body = 'files';
333
- }
334
- else if (isPDF(contentType)) {
335
- code += 'files = {\n';
336
- code += "".concat(indent("\"file\": \"".concat(body, "\","), 4), "\n");
337
- code += '}\n\n';
338
- body = 'files';
339
- }
340
- else if (isXML(contentType)) {
341
- // Convert JSON to XML if needed
342
- body = JSON.stringify(convertBodyToXML(body));
343
- }
344
- else if (isYAML(contentType)) {
345
- code += "yamlBody = \"\"\"\n".concat(indent(yaml.dump(body), 4), "\"\"\"\n\n");
346
- body = 'yamlBody';
347
- }
348
- else {
349
- body = stringifyOpenAPI(body, function (_key, value) {
350
- switch (value) {
351
- case true:
352
- return '$$__TRUE__$$';
353
- case false:
354
- return '$$__FALSE__$$';
355
- case null:
356
- return '$$__NULL__$$';
357
- default:
358
- return value;
359
- }
360
- }, 2)
361
- .replaceAll('"$$__TRUE__$$"', 'True')
362
- .replaceAll('"$$__FALSE__$$"', 'False')
363
- .replaceAll('"$$__NULL__$$"', 'None');
364
- }
365
- return { body: body, code: code, headers: headers };
366
- },
367
- getHTTPBody: function (body, headers) {
368
- if (!body || !headers)
369
- return undefined;
370
- var contentType = headers['Content-Type'] || '';
371
- var typeHandlers = {
372
- pdf: function () { return "".concat(stringifyOpenAPI(body, null, 2)); },
373
- formUrlEncoded: function () {
374
- var encoded = isPlainObject(body)
375
- ? Object.entries(body)
376
- .map(function (_a) {
377
- var key = _a[0], value = _a[1];
378
- return "".concat(key, "=").concat(stringifyOpenAPI(value));
379
- })
380
- .join('&')
381
- : stringifyOpenAPI(body);
382
- return "\"".concat(encoded.replace(/"/g, "'"), "\"");
383
- },
384
- text: function () { return "\"".concat(String(body), "\""); },
385
- xml: function () {
386
- // Convert JSON to XML if needed
387
- return "\"".concat(convertBodyToXML(body), "\"");
388
- },
389
- yaml: function () { return "\"".concat(yaml.dump(body).replace(/"/g, '\\"'), "\""); },
390
- csv: function () { return "\"".concat(stringifyOpenAPI(body).replace(/"/g, ''), "\""); },
391
- default: function () { return "".concat(stringifyOpenAPI(body, null, 2)); },
392
- };
393
- if (isPDF(contentType))
394
- return typeHandlers.pdf();
395
- if (isFormUrlEncoded(contentType))
396
- return typeHandlers.formUrlEncoded();
397
- if (isText(contentType))
398
- return typeHandlers.text();
399
- if (isXML(contentType))
400
- return typeHandlers.xml();
401
- if (isYAML(contentType))
402
- return typeHandlers.yaml();
403
- if (isCSV(contentType))
404
- return typeHandlers.csv();
405
- return typeHandlers.default();
406
- },
407
- };
408
- /**
409
- * Converts a body to XML format
410
- */
411
- function convertBodyToXML(body) {
412
- // If body is already a string and looks like XML, return it as is
413
- if (typeof body === 'string' && body.trim().startsWith('<')) {
414
- return body;
415
- }
416
- // If body is not an object, try to parse it as JSON
417
- if (typeof body !== 'object' || body === null) {
418
- try {
419
- body = JSON.parse(body);
420
- }
421
- catch (_a) {
422
- // If parsing fails, return the original body
423
- return body;
424
- }
425
- }
426
- return json2xml(body).replace(/"/g, '').replace(/\\n/g, '\n').replace(/\\t/g, '\t');
427
- }
@@ -1,6 +0,0 @@
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;
@@ -1,20 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
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;
@@ -1,19 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
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;
@@ -1,15 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
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;
@@ -1,30 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
1
- export declare function isJSON(contentType?: string): boolean;
2
- export declare function isXML(contentType?: string): boolean;
3
- export declare function isYAML(contentType?: string): boolean;
4
- export declare function isGraphQL(contentType?: string): boolean;
5
- export declare function isCSV(contentType?: string): boolean;
6
- export declare function isPDF(contentType?: string): boolean;
7
- export declare function isText(contentType?: string): boolean;
8
- export declare function isFormUrlEncoded(contentType?: string): boolean;
9
- export declare function isFormData(contentType?: string): boolean;
10
- export declare function isPlainObject(value: unknown): boolean;
@@ -1,30 +0,0 @@
1
- export function isJSON(contentType) {
2
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/json')) || false;
3
- }
4
- export function isXML(contentType) {
5
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/xml')) || false;
6
- }
7
- export function isYAML(contentType) {
8
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/yaml')) || false;
9
- }
10
- export function isGraphQL(contentType) {
11
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/graphql')) || false;
12
- }
13
- export function isCSV(contentType) {
14
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('text/csv')) || false;
15
- }
16
- export function isPDF(contentType) {
17
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/pdf')) || false;
18
- }
19
- export function isText(contentType) {
20
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('text/plain')) || false;
21
- }
22
- export function isFormUrlEncoded(contentType) {
23
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/x-www-form-urlencoded')) || false;
24
- }
25
- export function isFormData(contentType) {
26
- return !!contentType && contentType.toLowerCase().includes('multipart/form-data');
27
- }
28
- export function isPlainObject(value) {
29
- return typeof value === 'object' && value !== null && !Array.isArray(value);
30
- }
package/dist/context.d.ts DELETED
@@ -1,75 +0,0 @@
1
- import { type Translation, type TranslationLocale } from './translations';
2
- export interface OpenAPIClientContext {
3
- /**
4
- * The translation language to use.
5
- */
6
- translation: Translation;
7
- /**
8
- * Icons used in the block.
9
- */
10
- icons: {
11
- chevronDown: React.ReactNode;
12
- chevronRight: React.ReactNode;
13
- plus: React.ReactNode;
14
- };
15
- /**
16
- * Force all sections to be opened by default.
17
- * @default false
18
- */
19
- defaultInteractiveOpened?: boolean;
20
- /**
21
- * The key of the block
22
- */
23
- blockKey?: string;
24
- /**
25
- * Optional id attached to the heading and used as an anchor.
26
- */
27
- id?: string;
28
- /**
29
- * Mark the context as a client context.
30
- */
31
- $$isClientContext$$: true;
32
- }
33
- export interface OpenAPIContext extends Omit<OpenAPIClientContext, '$$isClientContext$$'> {
34
- /**
35
- * Render a code block.
36
- */
37
- renderCodeBlock: (props: {
38
- code: string;
39
- syntax: string;
40
- }) => React.ReactNode;
41
- /**
42
- * Render the heading of the operation.
43
- */
44
- renderHeading: (props: {
45
- deprecated: boolean;
46
- title: string;
47
- stability?: string;
48
- }) => React.ReactNode;
49
- /**
50
- * Render the document of the operation.
51
- */
52
- renderDocument: (props: {
53
- document: object;
54
- }) => React.ReactNode;
55
- /**
56
- * Specification URL.
57
- */
58
- specUrl: string;
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;
72
- /**
73
- * Get the client context from the OpenAPI context.
74
- */
75
- export declare function getOpenAPIClientContext(context: OpenAPIUniversalContext): OpenAPIClientContext;