@gitbook/react-openapi 1.4.3 → 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 +27 -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
package/dist/context.js DELETED
@@ -1,43 +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
- 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
- }
31
- /**
32
- * Get the client context from the OpenAPI context.
33
- */
34
- export function getOpenAPIClientContext(context) {
35
- return {
36
- translation: context.translation,
37
- icons: context.icons,
38
- defaultInteractiveOpened: context.defaultInteractiveOpened,
39
- blockKey: context.blockKey,
40
- id: context.id,
41
- $$isClientContext$$: true,
42
- };
43
- }
package/dist/decycle.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const decycle: () => (this: any, key: string | symbol, value: any) => any;
2
- export declare function retrocycle(): (this: object, key: string | symbol, value: any) => any;
package/dist/decycle.js DELETED
@@ -1,70 +0,0 @@
1
- // Forked from: https://github.com/YChebotaev/json-decycle/blob/master/src/index.ts
2
- // Replaced `$ref` with `$reference` to avoid conflicts with OpenAPI
3
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
4
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
5
- if (ar || !(i in from)) {
6
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
7
- ar[i] = from[i];
8
- }
9
- }
10
- return to.concat(ar || Array.prototype.slice.call(from));
11
- };
12
- var isObject = function (value) {
13
- return typeof value === 'object' &&
14
- value != null &&
15
- !(value instanceof Boolean) &&
16
- !(value instanceof Date) &&
17
- !(value instanceof Number) &&
18
- !(value instanceof RegExp) &&
19
- !(value instanceof String);
20
- };
21
- var toPointer = function (parts) {
22
- return "#".concat(parts.map(function (part) { return String(part).replace(/~/g, '~0').replace(/\//g, '~1'); }).join('/'));
23
- };
24
- export var decycle = function () {
25
- var paths = new WeakMap();
26
- return function replacer(key, value) {
27
- var _a;
28
- if (key !== '$reference' && isObject(value)) {
29
- var seen = paths.has(value);
30
- if (seen) {
31
- return { $reference: toPointer(paths.get(value)) };
32
- }
33
- paths.set(value, __spreadArray(__spreadArray([], ((_a = paths.get(this)) !== null && _a !== void 0 ? _a : []), true), [key], false));
34
- }
35
- return value;
36
- };
37
- };
38
- export function retrocycle() {
39
- var parents = new WeakMap();
40
- var keys = new WeakMap();
41
- var refs = new Set();
42
- function dereference(ref) {
43
- var _a;
44
- var parts = ref.$reference.slice(1).split('/');
45
- var key;
46
- var value = this;
47
- for (var i = 0; i < parts.length; i++) {
48
- key = (_a = parts[i]) === null || _a === void 0 ? void 0 : _a.replace(/~1/g, '/').replace(/~0/g, '~');
49
- value = value[key];
50
- }
51
- var parent = parents.get(ref);
52
- parent[keys.get(ref)] = value;
53
- }
54
- return function reviver(key, value) {
55
- if (key === '$reference') {
56
- refs.add(this);
57
- }
58
- else if (isObject(value)) {
59
- var isRoot = key === '' && Object.keys(this).length === 1;
60
- if (isRoot) {
61
- refs.forEach(dereference, this);
62
- }
63
- else {
64
- parents.set(value, this);
65
- keys.set(value, key);
66
- }
67
- }
68
- return value;
69
- };
70
- }
@@ -1,5 +0,0 @@
1
- import { type Filesystem, type OpenAPIV3xDocument } from '@gitbook/openapi-parser';
2
- /**
3
- * Memoized version of `dereferenceSchema`.
4
- */
5
- export declare function dereferenceFilesystem(filesystem: Filesystem): Promise<OpenAPIV3xDocument>;
@@ -1,68 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { dereference } from '@gitbook/openapi-parser';
38
- var dereferenceCache = new WeakMap();
39
- /**
40
- * Memoized version of `dereferenceSchema`.
41
- */
42
- export function dereferenceFilesystem(filesystem) {
43
- if (dereferenceCache.has(filesystem)) {
44
- return dereferenceCache.get(filesystem);
45
- }
46
- var promise = baseDereferenceFilesystem(filesystem);
47
- dereferenceCache.set(filesystem, promise);
48
- return promise;
49
- }
50
- /**
51
- * Dereference an OpenAPI schema.
52
- */
53
- function baseDereferenceFilesystem(filesystem) {
54
- return __awaiter(this, void 0, void 0, function () {
55
- var result;
56
- return __generator(this, function (_a) {
57
- switch (_a.label) {
58
- case 0: return [4 /*yield*/, dereference(filesystem)];
59
- case 1:
60
- result = _a.sent();
61
- if (!result.schema) {
62
- throw new Error('Failed to dereference OpenAPI document');
63
- }
64
- return [2 /*return*/, result.schema];
65
- }
66
- });
67
- });
68
- }
@@ -1,45 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- type JSONValue = string | number | boolean | null | JSONValue[] | {
3
- [key: string]: JSONValue;
4
- };
5
- type ScalarGetExampleFromSchemaOptions = NonNullable<Parameters<typeof getExampleFromSchema>[1]>;
6
- type GenerateSchemaExampleOptions = Pick<ScalarGetExampleFromSchemaOptions, 'xml' | 'omitEmptyAndOptionalProperties' | 'mode'>;
7
- /**
8
- * Generate a JSON example from a schema
9
- */
10
- export declare function generateSchemaExample(schema: OpenAPIV3.SchemaObject, options?: GenerateSchemaExampleOptions): JSONValue | undefined;
11
- /**
12
- * Generate an example for a media type.
13
- */
14
- export declare function generateMediaTypeExamples(mediaType: OpenAPIV3.MediaTypeObject, options?: GenerateSchemaExampleOptions): OpenAPIV3.ExampleObject[];
15
- /**
16
- * This function takes an OpenAPI schema and generates an example from it
17
- * Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
18
- */
19
- declare const getExampleFromSchema: (schema: Record<string, any>, options?: {
20
- /**
21
- * The fallback string for empty string values.
22
- * @default ''
23
- */
24
- emptyString?: string;
25
- /**
26
- * Whether to use the XML tag names as keys
27
- * @default false
28
- */
29
- xml?: boolean;
30
- /**
31
- * Whether to show read-only/write-only properties. Otherwise all properties are shown.
32
- * @default undefined
33
- */
34
- mode?: "read" | "write";
35
- /**
36
- * Dynamic values to add to the example.
37
- */
38
- variables?: Record<string, any>;
39
- /**
40
- * Whether to omit empty and optional properties.
41
- * @default false
42
- */
43
- omitEmptyAndOptionalProperties?: boolean;
44
- }, level?: number, parentSchema?: Record<string, any>, name?: string, resultCache?: WeakMap<Record<string, any>, any>) => any;
45
- export {};
@@ -1,342 +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
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
- if (ar || !(i in from)) {
15
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
- ar[i] = from[i];
17
- }
18
- }
19
- return to.concat(ar || Array.prototype.slice.call(from));
20
- };
21
- var _a, _b, _c;
22
- import { checkIsReference } from './utils';
23
- /**
24
- * Generate a JSON example from a schema
25
- */
26
- export function generateSchemaExample(schema, options) {
27
- return getExampleFromSchema(schema, __assign({ emptyString: 'text' }, options));
28
- }
29
- /**
30
- * Generate an example for a media type.
31
- */
32
- export function generateMediaTypeExamples(mediaType, options) {
33
- if (mediaType.example) {
34
- return [{ summary: 'default', value: mediaType.example }];
35
- }
36
- if (mediaType.examples) {
37
- var examples_1 = mediaType.examples;
38
- var keys = Object.keys(examples_1);
39
- if (keys.length > 0) {
40
- return keys.reduce(function (result, key) {
41
- var example = examples_1[key];
42
- if (!example || checkIsReference(example)) {
43
- return result;
44
- }
45
- result.push({
46
- summary: example.summary || key,
47
- value: example.value,
48
- description: example.description,
49
- externalValue: example.externalValue,
50
- });
51
- return result;
52
- }, []);
53
- }
54
- }
55
- if (mediaType.schema) {
56
- return [{ summary: 'default', value: generateSchemaExample(mediaType.schema, options) }];
57
- }
58
- return [];
59
- }
60
- /** Hard limit for rendering circular references */
61
- var MAX_LEVELS_DEEP = 5;
62
- var genericExampleValues = {
63
- 'date-time': new Date().toISOString(),
64
- date: (_a = new Date().toISOString().split('T')[0]) !== null && _a !== void 0 ? _a : '1970-01-01',
65
- email: 'name@gmail.com',
66
- hostname: 'example.com',
67
- ipv4: '0.0.0.0',
68
- ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
69
- uri: 'https://example.com',
70
- uuid: '123e4567-e89b-12d3-a456-426614174000',
71
- binary: 'binary',
72
- byte: 'Ynl0ZXM=',
73
- password: 'password',
74
- 'idn-email': 'jane.doe@example.com',
75
- 'idn-hostname': 'example.com',
76
- 'iri-reference': '/entitiy/1',
77
- // https://tools.ietf.org/html/rfc3987
78
- iri: 'https://example.com/entity/123',
79
- 'json-pointer': '/nested/objects',
80
- regex: '/[a-z]/',
81
- // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
82
- 'relative-json-pointer': '1/nested/objects',
83
- // full-time in https://tools.ietf.org/html/rfc3339#section-5.6
84
- time: (_c = (_b = new Date().toISOString().split('T')[1]) === null || _b === void 0 ? void 0 : _b.split('.')[0]) !== null && _c !== void 0 ? _c : '00:00:00Z',
85
- // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1
86
- 'uri-reference': '../folder',
87
- 'uri-template': 'https://example.com/{id}',
88
- 'object-id': '6592008029c8c3e4dc76256c',
89
- };
90
- /**
91
- * We can use the `format` to generate some random values.
92
- */
93
- function guessFromFormat(schema, fallback) {
94
- var _a;
95
- if (fallback === void 0) { fallback = ''; }
96
- return (_a = genericExampleValues[schema.format]) !== null && _a !== void 0 ? _a : fallback;
97
- }
98
- /**
99
- * This function takes an OpenAPI schema and generates an example from it
100
- * Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
101
- */
102
- var getExampleFromSchema = function (schema, options, level, parentSchema, name, resultCache) {
103
- var _a, _b, _c, _d;
104
- var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
105
- if (level === void 0) { level = 0; }
106
- if (resultCache === void 0) { resultCache = new WeakMap(); }
107
- // Store result in the cache, and return the result
108
- function cache(schema, result) {
109
- // Avoid unnecessary WeakMap operations for primitive values
110
- if (typeof result !== 'object' || result === null) {
111
- return result;
112
- }
113
- resultCache.set(schema, result);
114
- return result;
115
- }
116
- // Check if the result is already cached
117
- if (resultCache.has(schema)) {
118
- return resultCache.get(schema);
119
- }
120
- // Check whether it’s a circular reference
121
- if (level === MAX_LEVELS_DEEP + 1) {
122
- try {
123
- // Fails if it contains a circular reference
124
- JSON.stringify(schema);
125
- }
126
- catch (_w) {
127
- return '[Circular Reference]';
128
- }
129
- }
130
- // Sometimes, we just want the structure and no values.
131
- // But if `emptyString` is set, we do want to see some values.
132
- var makeUpRandomData = !!(options === null || options === void 0 ? void 0 : options.emptyString);
133
- // If the property is deprecated we don't show it in examples.
134
- if (schema.deprecated || (schema.type === 'array' && ((_e = schema.items) === null || _e === void 0 ? void 0 : _e.deprecated))) {
135
- return undefined;
136
- }
137
- // Check if the property is read-only/write-only
138
- if (((options === null || options === void 0 ? void 0 : options.mode) === 'write' && schema.readOnly) ||
139
- ((options === null || options === void 0 ? void 0 : options.mode) === 'read' && schema.writeOnly)) {
140
- return undefined;
141
- }
142
- // Use given variables as values
143
- if (schema['x-variable']) {
144
- var value = (_f = options === null || options === void 0 ? void 0 : options.variables) === null || _f === void 0 ? void 0 : _f[schema['x-variable']];
145
- // Return the value if it’s defined
146
- if (value !== undefined) {
147
- // Type-casting
148
- if (schema.type === 'number' || schema.type === 'integer') {
149
- return Number.parseInt(value, 10);
150
- }
151
- return cache(schema, value);
152
- }
153
- }
154
- // Use the first example, if there’s an array
155
- if (Array.isArray(schema.examples) && schema.examples.length > 0) {
156
- return cache(schema, schema.examples[0]);
157
- }
158
- // Use an example, if there’s one
159
- if (schema.example !== undefined) {
160
- return cache(schema, schema.example);
161
- }
162
- // Use a default value, if there’s one and it’s a string or number
163
- if (schema.default !== undefined &&
164
- ['string', 'number', 'boolean'].includes(typeof schema.default)) {
165
- return cache(schema, schema.default);
166
- }
167
- // enum: [ 'available', 'pending', 'sold' ]
168
- if (Array.isArray(schema.enum) && schema.enum.length > 0) {
169
- return cache(schema, schema.enum[0]);
170
- }
171
- // Check if the property is required
172
- var isObjectOrArray = schema.type === 'object' ||
173
- schema.type === 'array' ||
174
- !!((_h = (_g = schema.allOf) === null || _g === void 0 ? void 0 : _g.at) === null || _h === void 0 ? void 0 : _h.call(_g, 0)) ||
175
- !!((_k = (_j = schema.anyOf) === null || _j === void 0 ? void 0 : _j.at) === null || _k === void 0 ? void 0 : _k.call(_j, 0)) ||
176
- !!((_m = (_l = schema.oneOf) === null || _l === void 0 ? void 0 : _l.at) === null || _m === void 0 ? void 0 : _m.call(_l, 0));
177
- if (!isObjectOrArray && (options === null || options === void 0 ? void 0 : options.omitEmptyAndOptionalProperties) === true) {
178
- var isRequired = schema.required === true ||
179
- (parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.required) === true ||
180
- ((_o = parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.required) === null || _o === void 0 ? void 0 : _o.includes(name !== null && name !== void 0 ? name : schema.name));
181
- if (!isRequired) {
182
- return undefined;
183
- }
184
- }
185
- // Object
186
- if (schema.type === 'object' || schema.properties !== undefined) {
187
- var response = {};
188
- // Regular properties
189
- if (schema.properties !== undefined) {
190
- for (var propertyName in schema.properties) {
191
- if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
192
- var property = schema.properties[propertyName];
193
- var propertyXmlTagName = (options === null || options === void 0 ? void 0 : options.xml) ? (_p = property.xml) === null || _p === void 0 ? void 0 : _p.name : undefined;
194
- response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName, resultCache);
195
- if (typeof response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName] === 'undefined') {
196
- delete response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName];
197
- }
198
- }
199
- }
200
- }
201
- // Pattern properties (regex)
202
- if (schema.patternProperties !== undefined) {
203
- for (var pattern in schema.patternProperties) {
204
- if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
205
- var property = schema.patternProperties[pattern];
206
- // Use the regex pattern as an example key
207
- var exampleKey = pattern;
208
- response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey, resultCache);
209
- }
210
- }
211
- }
212
- // Additional properties
213
- if (schema.additionalProperties !== undefined) {
214
- var anyTypeIsValid =
215
- // true
216
- schema.additionalProperties === true ||
217
- // or an empty object {}
218
- (typeof schema.additionalProperties === 'object' &&
219
- !Object.keys(schema.additionalProperties).length);
220
- if (anyTypeIsValid) {
221
- response.ANY_ADDITIONAL_PROPERTY = 'anything';
222
- }
223
- else if (schema.additionalProperties !== false) {
224
- response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(schema.additionalProperties, options, level + 1, undefined, undefined, resultCache);
225
- }
226
- }
227
- if (schema.anyOf !== undefined) {
228
- Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1, undefined, undefined, resultCache));
229
- }
230
- else if (schema.oneOf !== undefined) {
231
- Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1, undefined, undefined, resultCache));
232
- }
233
- else if (schema.allOf !== undefined) {
234
- Object.assign.apply(Object, __spreadArray([response], schema.allOf
235
- .map(function (item) {
236
- return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
237
- })
238
- .filter(function (item) { return item !== undefined; }), false));
239
- }
240
- return cache(schema, response);
241
- }
242
- // Array
243
- if (schema.type === 'array' || schema.items !== undefined) {
244
- var itemsXmlTagName_1 = (_r = (_q = schema === null || schema === void 0 ? void 0 : schema.items) === null || _q === void 0 ? void 0 : _q.xml) === null || _r === void 0 ? void 0 : _r.name;
245
- var wrapItems = !!((options === null || options === void 0 ? void 0 : options.xml) && ((_s = schema.xml) === null || _s === void 0 ? void 0 : _s.wrapped) && itemsXmlTagName_1);
246
- if (schema.example !== undefined) {
247
- return cache(schema, wrapItems ? (_a = {}, _a[itemsXmlTagName_1] = schema.example, _a) : schema.example);
248
- }
249
- // Check whether the array has a anyOf, oneOf, or allOf rule
250
- if (schema.items) {
251
- // First handle allOf separately since it needs special handling
252
- if (schema.items.allOf) {
253
- // If the first item is an object type, merge all schemas
254
- if (schema.items.allOf[0].type === 'object') {
255
- var mergedExample = getExampleFromSchema({ type: 'object', allOf: schema.items.allOf }, options, level + 1, schema, undefined, resultCache);
256
- return cache(schema, wrapItems ? [(_b = {}, _b[itemsXmlTagName_1] = mergedExample, _b)] : [mergedExample]);
257
- }
258
- // For non-objects (like strings), collect all examples
259
- var examples = schema.items.allOf
260
- .map(function (item) {
261
- return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
262
- })
263
- .filter(function (item) { return item !== undefined; });
264
- return cache(schema, wrapItems
265
- ? examples.map(function (example) {
266
- var _a;
267
- return (_a = {}, _a[itemsXmlTagName_1] = example, _a);
268
- })
269
- : examples);
270
- }
271
- // Handle other rules (anyOf, oneOf)
272
- var rules = ['anyOf', 'oneOf'];
273
- for (var _i = 0, rules_1 = rules; _i < rules_1.length; _i++) {
274
- var rule = rules_1[_i];
275
- if (!schema.items[rule]) {
276
- continue;
277
- }
278
- var schemas = schema.items[rule].slice(0, 1);
279
- var exampleFromRule = schemas
280
- .map(function (item) {
281
- return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
282
- })
283
- .filter(function (item) { return item !== undefined; });
284
- return cache(schema, wrapItems ? [(_c = {}, _c[itemsXmlTagName_1] = exampleFromRule, _c)] : exampleFromRule);
285
- }
286
- }
287
- if ((_t = schema.items) === null || _t === void 0 ? void 0 : _t.type) {
288
- var exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1, undefined, undefined, resultCache);
289
- return wrapItems ? [(_d = {}, _d[itemsXmlTagName_1] = exampleFromSchema, _d)] : [exampleFromSchema];
290
- }
291
- return [];
292
- }
293
- var exampleValues = {
294
- string: makeUpRandomData ? guessFromFormat(schema, options === null || options === void 0 ? void 0 : options.emptyString) : '',
295
- boolean: true,
296
- integer: (_u = schema.min) !== null && _u !== void 0 ? _u : 1,
297
- number: (_v = schema.min) !== null && _v !== void 0 ? _v : 1,
298
- array: [],
299
- };
300
- if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {
301
- return cache(schema, exampleValues[schema.type]);
302
- }
303
- var discriminateSchema = schema.oneOf || schema.anyOf;
304
- // Check if property has the `oneOf` | `anyOf` key
305
- if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
306
- // Get the first item from the `oneOf` | `anyOf` array
307
- var firstOneOfItem = discriminateSchema[0];
308
- // Return an example for the first item
309
- return getExampleFromSchema(firstOneOfItem, options, level + 1, undefined, undefined, resultCache);
310
- }
311
- // Check if schema has the `allOf` key
312
- if (Array.isArray(schema.allOf)) {
313
- var example_1 = null;
314
- // Loop through all `allOf` schemas
315
- schema.allOf.forEach(function (allOfItem) {
316
- // Return an example from the schema
317
- var newExample = getExampleFromSchema(allOfItem, options, level + 1, undefined, undefined, resultCache);
318
- // Merge or overwrite the example
319
- example_1 =
320
- typeof newExample === 'object' && typeof example_1 === 'object'
321
- ? __assign(__assign({}, (example_1 !== null && example_1 !== void 0 ? example_1 : {})), newExample) : Array.isArray(newExample) && Array.isArray(example_1)
322
- ? __spreadArray(__spreadArray([], (example_1 !== null && example_1 !== void 0 ? example_1 : {}), true), newExample, true) : newExample;
323
- });
324
- return cache(schema, example_1);
325
- }
326
- // Check if schema is a union type
327
- if (Array.isArray(schema.type)) {
328
- // Return null if the type is nullable
329
- if (schema.type.includes('null')) {
330
- return null;
331
- }
332
- // Return an example for the first type in the union
333
- var exampleValue = exampleValues[schema.type[0]];
334
- if (exampleValue !== undefined) {
335
- return cache(schema, exampleValue);
336
- }
337
- }
338
- // Warn if the type is unknown …
339
- // console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`)
340
- // … and just return null for now.
341
- return null;
342
- };
@@ -1,7 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './context';
3
- export declare function getDisclosureLabel(props: {
4
- schema: OpenAPIV3.SchemaObject;
5
- isExpanded: boolean;
6
- context: OpenAPIClientContext;
7
- }): string;
@@ -1,18 +0,0 @@
1
- 'use client';
2
- import { tString } from './translate';
3
- export function getDisclosureLabel(props) {
4
- var schema = props.schema, isExpanded = props.isExpanded, context = props.context;
5
- var label;
6
- if (schema.type === 'array' && !!schema.items) {
7
- if (schema.items.oneOf) {
8
- label = tString(context.translation, 'available_items').toLowerCase();
9
- }
10
- else {
11
- label = tString(context.translation, 'properties').toLowerCase();
12
- }
13
- }
14
- else {
15
- label = tString(context.translation, 'properties').toLowerCase();
16
- }
17
- return tString(context.translation, isExpanded ? 'hide' : 'show', label);
18
- }
@@ -1,10 +0,0 @@
1
- type Key = string | number;
2
- type State = {
3
- key: Key | null;
4
- };
5
- type Actions = {
6
- setKey: (key: Key | null) => void;
7
- };
8
- export type Store = State & Actions;
9
- export declare const getOrCreateStoreByKey: (storeKey: string, initialKey?: Key) => import("zustand").StoreApi<Store>;
10
- export {};
@@ -1,19 +0,0 @@
1
- import { createStore } from 'zustand';
2
- var createStateStore = function (initial) {
3
- return createStore()(function (set) { return ({
4
- key: initial !== null && initial !== void 0 ? initial : null,
5
- setKey: function (key) {
6
- set(function () { return ({ key: key }); });
7
- },
8
- }); });
9
- };
10
- var defaultStores = new Map();
11
- var createStateStoreFactory = function (stores) {
12
- return function (storeKey, initialKey) {
13
- if (!stores.has(storeKey)) {
14
- stores.set(storeKey, createStateStore(initialKey));
15
- }
16
- return stores.get(storeKey);
17
- };
18
- };
19
- export var getOrCreateStoreByKey = createStateStoreFactory(defaultStores);
@@ -1,4 +0,0 @@
1
- /**
2
- * This function converts an object to XML.
3
- */
4
- export declare function json2xml(data: Record<string, any>): string;
package/dist/json2xml.js DELETED
@@ -1,7 +0,0 @@
1
- import { jsXml } from 'json-xml-parse';
2
- /**
3
- * This function converts an object to XML.
4
- */
5
- export function json2xml(data) {
6
- return jsXml.toXmlString(data, { beautify: true });
7
- }
@@ -1,11 +0,0 @@
1
- import { fromJSON, toJSON } from 'flatted';
2
- import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
- import type { OpenAPIOperationData } from './types';
4
- export { fromJSON, toJSON };
5
- /**
6
- * Resolve an OpenAPI operation in a file and compile it to a more usable format.
7
- */
8
- export declare function resolveOpenAPIOperation(filesystem: Filesystem<OpenAPIV3xDocument>, operationDescriptor: {
9
- path: string;
10
- method: string;
11
- }): Promise<OpenAPIOperationData | null>;