@gitbook/react-openapi 1.1.9 → 1.2.0

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 (177) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/InteractiveSection.d.ts +4 -0
  3. package/dist/InteractiveSection.jsx +14 -13
  4. package/dist/OpenAPICodeSample.d.ts +3 -2
  5. package/dist/OpenAPICodeSample.jsx +8 -12
  6. package/dist/OpenAPICodeSampleInteractive.d.ts +3 -0
  7. package/dist/OpenAPICodeSampleInteractive.jsx +37 -49
  8. package/dist/OpenAPICodeSampleSelector.d.ts +14 -0
  9. package/dist/OpenAPICodeSampleSelector.jsx +44 -0
  10. package/dist/OpenAPICopyButton.d.ts +2 -0
  11. package/dist/OpenAPICopyButton.jsx +5 -2
  12. package/dist/OpenAPIDisclosure.d.ts +4 -3
  13. package/dist/OpenAPIDisclosure.jsx +8 -11
  14. package/dist/OpenAPIDisclosureGroup.d.ts +7 -3
  15. package/dist/OpenAPIDisclosureGroup.jsx +18 -18
  16. package/dist/OpenAPIExample.d.ts +16 -0
  17. package/dist/OpenAPIExample.jsx +36 -0
  18. package/dist/OpenAPIMediaType.d.ts +21 -0
  19. package/dist/OpenAPIMediaType.jsx +61 -0
  20. package/dist/OpenAPIOperation.d.ts +3 -2
  21. package/dist/OpenAPIOperation.jsx +9 -72
  22. package/dist/OpenAPIOperationDescription.d.ts +9 -0
  23. package/dist/OpenAPIOperationDescription.jsx +22 -0
  24. package/dist/OpenAPIOperationStability.d.ts +9 -0
  25. package/dist/OpenAPIOperationStability.jsx +27 -0
  26. package/dist/OpenAPIPath.d.ts +12 -2
  27. package/dist/OpenAPIPath.jsx +10 -4
  28. package/dist/OpenAPIRequestBody.d.ts +3 -1
  29. package/dist/OpenAPIRequestBody.jsx +4 -3
  30. package/dist/OpenAPIResponse.d.ts +1 -1
  31. package/dist/OpenAPIResponse.jsx +1 -1
  32. package/dist/OpenAPIResponseExample.d.ts +4 -3
  33. package/dist/OpenAPIResponseExample.jsx +24 -154
  34. package/dist/OpenAPIResponseExampleContent.d.ts +19 -0
  35. package/dist/OpenAPIResponseExampleContent.jsx +57 -0
  36. package/dist/OpenAPIResponses.d.ts +1 -1
  37. package/dist/OpenAPIResponses.jsx +49 -36
  38. package/dist/OpenAPISchema.d.ts +1 -1
  39. package/dist/OpenAPISchema.jsx +121 -20
  40. package/dist/OpenAPISchemaName.d.ts +2 -0
  41. package/dist/OpenAPISchemaName.jsx +21 -17
  42. package/dist/OpenAPISchemaServer.d.ts +1 -1
  43. package/dist/OpenAPISecurities.d.ts +2 -1
  44. package/dist/OpenAPISecurities.jsx +11 -10
  45. package/dist/OpenAPISelect.d.ts +22 -0
  46. package/dist/OpenAPISelect.jsx +43 -0
  47. package/dist/OpenAPISpec.d.ts +3 -2
  48. package/dist/OpenAPISpec.jsx +11 -9
  49. package/dist/OpenAPITabs.jsx +9 -9
  50. package/dist/OpenAPIWebhook.d.ts +10 -0
  51. package/dist/OpenAPIWebhook.jsx +23 -0
  52. package/dist/OpenAPIWebhookExample.d.ts +6 -0
  53. package/dist/OpenAPIWebhookExample.jsx +41 -0
  54. package/dist/ScalarApiButton.d.ts +2 -0
  55. package/dist/ScalarApiButton.jsx +4 -3
  56. package/dist/StaticSection.d.ts +4 -1
  57. package/dist/StaticSection.jsx +13 -4
  58. package/dist/code-samples.js +57 -39
  59. package/dist/common/OpenAPIColumnSpec.d.ts +6 -0
  60. package/dist/common/OpenAPIColumnSpec.jsx +20 -0
  61. package/dist/common/OpenAPIOperationDescription.d.ts +6 -0
  62. package/dist/common/OpenAPIOperationDescription.jsx +19 -0
  63. package/dist/common/OpenAPIStability.d.ts +4 -0
  64. package/dist/common/OpenAPIStability.jsx +15 -0
  65. package/dist/common/OpenAPISummary.d.ts +6 -0
  66. package/dist/common/OpenAPISummary.jsx +30 -0
  67. package/dist/context.d.ts +75 -0
  68. package/dist/context.js +43 -0
  69. package/dist/generateSchemaExample.js +4 -0
  70. package/dist/getOrCreateStoreByKey.d.ts +10 -0
  71. package/dist/getOrCreateStoreByKey.js +19 -0
  72. package/dist/index.d.ts +5 -1
  73. package/dist/index.js +3 -0
  74. package/dist/resolveOpenAPIOperation.js +10 -5
  75. package/dist/resolveOpenAPIWebhook.d.ts +11 -0
  76. package/dist/resolveOpenAPIWebhook.js +127 -0
  77. package/dist/schemas/OpenAPISchemas.d.ts +5 -6
  78. package/dist/schemas/OpenAPISchemas.jsx +52 -49
  79. package/dist/schemas/resolveOpenAPISchemas.d.ts +4 -3
  80. package/dist/schemas/resolveOpenAPISchemas.js +0 -1
  81. package/dist/stringifyOpenAPI.d.ts +1 -1
  82. package/dist/stringifyOpenAPI.js +6 -3
  83. package/dist/translate.d.ts +10 -0
  84. package/dist/translate.jsx +75 -0
  85. package/dist/translations/de.d.ts +37 -0
  86. package/dist/translations/de.js +37 -0
  87. package/dist/translations/en.d.ts +37 -0
  88. package/dist/translations/en.js +37 -0
  89. package/dist/translations/es.d.ts +37 -0
  90. package/dist/translations/es.js +37 -0
  91. package/dist/translations/fr.d.ts +37 -0
  92. package/dist/translations/fr.js +37 -0
  93. package/dist/translations/index.d.ts +341 -0
  94. package/dist/translations/index.js +27 -0
  95. package/dist/translations/ja.d.ts +37 -0
  96. package/dist/translations/ja.js +37 -0
  97. package/dist/translations/nl.d.ts +37 -0
  98. package/dist/translations/nl.js +37 -0
  99. package/dist/translations/no.d.ts +37 -0
  100. package/dist/translations/no.js +37 -0
  101. package/dist/translations/pt-br.d.ts +37 -0
  102. package/dist/translations/pt-br.js +37 -0
  103. package/dist/translations/types.d.ts +5 -0
  104. package/dist/translations/types.js +1 -0
  105. package/dist/translations/zh.d.ts +37 -0
  106. package/dist/translations/zh.js +37 -0
  107. package/dist/tsconfig.build.tsbuildinfo +1 -1
  108. package/dist/types.d.ts +12 -48
  109. package/dist/util/example.d.ts +35 -0
  110. package/dist/util/example.jsx +103 -0
  111. package/dist/utils.d.ts +18 -0
  112. package/dist/utils.js +57 -0
  113. package/package.json +3 -3
  114. package/src/InteractiveSection.tsx +22 -18
  115. package/src/OpenAPICodeSample.tsx +26 -15
  116. package/src/OpenAPICodeSampleInteractive.tsx +67 -70
  117. package/src/OpenAPICodeSampleSelector.tsx +94 -0
  118. package/src/OpenAPICopyButton.tsx +7 -2
  119. package/src/OpenAPIDisclosure.tsx +20 -22
  120. package/src/OpenAPIDisclosureGroup.tsx +40 -22
  121. package/src/OpenAPIExample.tsx +55 -0
  122. package/src/OpenAPIMediaType.tsx +139 -0
  123. package/src/OpenAPIOperation.tsx +11 -104
  124. package/src/OpenAPIOperationDescription.tsx +34 -0
  125. package/src/OpenAPIOperationStability.tsx +39 -0
  126. package/src/OpenAPIPath.tsx +26 -6
  127. package/src/OpenAPIRequestBody.tsx +9 -4
  128. package/src/OpenAPIResponse.tsx +2 -2
  129. package/src/OpenAPIResponseExample.tsx +41 -215
  130. package/src/OpenAPIResponseExampleContent.tsx +123 -0
  131. package/src/OpenAPIResponses.tsx +83 -62
  132. package/src/OpenAPISchema.test.ts +80 -0
  133. package/src/OpenAPISchema.tsx +149 -25
  134. package/src/OpenAPISchemaName.tsx +28 -19
  135. package/src/OpenAPISchemaServer.tsx +1 -1
  136. package/src/OpenAPISecurities.tsx +46 -12
  137. package/src/OpenAPISelect.tsx +96 -0
  138. package/src/OpenAPISpec.tsx +21 -10
  139. package/src/OpenAPITabs.tsx +9 -9
  140. package/src/OpenAPIWebhook.tsx +33 -0
  141. package/src/OpenAPIWebhookExample.tsx +60 -0
  142. package/src/ScalarApiButton.tsx +6 -6
  143. package/src/StaticSection.tsx +37 -5
  144. package/src/code-samples.test.ts +3 -1
  145. package/src/code-samples.ts +67 -54
  146. package/src/common/OpenAPIColumnSpec.tsx +31 -0
  147. package/src/common/OpenAPIOperationDescription.tsx +31 -0
  148. package/src/common/OpenAPIStability.tsx +23 -0
  149. package/src/common/OpenAPISummary.tsx +45 -0
  150. package/src/context.ts +99 -0
  151. package/src/generateSchemaExample.test.ts +1020 -0
  152. package/src/generateSchemaExample.ts +5 -0
  153. package/src/getOrCreateStoreByKey.ts +33 -0
  154. package/src/index.ts +5 -1
  155. package/src/resolveOpenAPIOperation.ts +14 -3
  156. package/src/resolveOpenAPIWebhook.ts +99 -0
  157. package/src/schemas/OpenAPISchemas.tsx +76 -71
  158. package/src/schemas/resolveOpenAPISchemas.ts +4 -5
  159. package/src/stringifyOpenAPI.ts +11 -3
  160. package/src/translate.tsx +80 -0
  161. package/src/translations/de.ts +37 -0
  162. package/src/translations/en.ts +37 -0
  163. package/src/translations/es.ts +37 -0
  164. package/src/translations/fr.ts +37 -0
  165. package/src/translations/index.ts +33 -0
  166. package/src/translations/ja.ts +37 -0
  167. package/src/translations/nl.ts +37 -0
  168. package/src/translations/no.ts +37 -0
  169. package/src/translations/pt-br.ts +37 -0
  170. package/src/translations/types.ts +7 -0
  171. package/src/translations/zh.ts +37 -0
  172. package/src/types.ts +11 -46
  173. package/src/util/example.tsx +129 -0
  174. package/src/utils.ts +67 -0
  175. package/dist/useSyncedTabsGlobalState.d.ts +0 -10
  176. package/dist/useSyncedTabsGlobalState.js +0 -20
  177. package/src/useSyncedTabsGlobalState.ts +0 -35
@@ -0,0 +1,43 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { translations } from './translations';
24
+ /**
25
+ * Resolve OpenAPI context from the input.
26
+ */
27
+ export function resolveOpenAPIContext(context) {
28
+ var locale = context.locale, rest = __rest(context, ["locale"]);
29
+ return __assign(__assign({}, rest), { translation: translations[locale !== null && locale !== void 0 ? locale : 'en'] });
30
+ }
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
+ }
@@ -130,6 +130,10 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name,
130
130
  // Sometimes, we just want the structure and no values.
131
131
  // But if `emptyString` is set, we do want to see some values.
132
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) {
135
+ return undefined;
136
+ }
133
137
  // Check if the property is read-only/write-only
134
138
  if (((options === null || options === void 0 ? void 0 : options.mode) === 'write' && schema.readOnly) ||
135
139
  ((options === null || options === void 0 ? void 0 : options.mode) === 'read' && schema.writeOnly)) {
@@ -0,0 +1,10 @@
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 {};
@@ -0,0 +1,19 @@
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);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  export * from './schemas';
2
2
  export * from './OpenAPIOperation';
3
+ export * from './OpenAPIWebhook';
3
4
  export * from './OpenAPIOperationContext';
4
5
  export * from './resolveOpenAPIOperation';
5
- export type { OpenAPISchemasData, OpenAPIOperationData } from './types';
6
+ export * from './resolveOpenAPIWebhook';
7
+ export type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
8
+ export type { OpenAPIContextInput } from './context';
9
+ export { checkIsValidLocale } from './translations';
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from './schemas';
2
2
  export * from './OpenAPIOperation';
3
+ export * from './OpenAPIWebhook';
3
4
  export * from './OpenAPIOperationContext';
4
5
  export * from './resolveOpenAPIOperation';
6
+ export * from './resolveOpenAPIWebhook';
7
+ export { checkIsValidLocale } from './translations';
@@ -63,7 +63,7 @@ export { fromJSON, toJSON };
63
63
  */
64
64
  export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
65
65
  return __awaiter(this, void 0, void 0, function () {
66
- var path, method, schema, operation, commonParameters, servers, security, securities, _i, security_1, entry, securityKey, securityScheme;
66
+ var path, method, schema, operation, commonParameters, servers, security, isOptionalSecurity, flatSecurities, securities, _i, flatSecurities_1, entry, securityKey, securityScheme;
67
67
  var _a, _b, _c, _d, _e, _f;
68
68
  return __generator(this, function (_g) {
69
69
  switch (_g.label) {
@@ -81,15 +81,20 @@ export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
81
81
  operation = __assign(__assign({}, operation), { parameters: __spreadArray(__spreadArray([], commonParameters, true), ((_a = operation.parameters) !== null && _a !== void 0 ? _a : []), true) });
82
82
  }
83
83
  servers = 'servers' in schema ? ((_b = schema.servers) !== null && _b !== void 0 ? _b : []) : [];
84
- security = flattenSecurities((_d = (_c = operation.security) !== null && _c !== void 0 ? _c : schema.security) !== null && _d !== void 0 ? _d : []);
84
+ security = (_d = (_c = operation.security) !== null && _c !== void 0 ? _c : schema.security) !== null && _d !== void 0 ? _d : [];
85
+ isOptionalSecurity = security.some(function (entry) { return Object.keys(entry).length === 0; });
86
+ flatSecurities = flattenSecurities(security);
85
87
  securities = [];
86
- for (_i = 0, security_1 = security; _i < security_1.length; _i++) {
87
- entry = security_1[_i];
88
+ for (_i = 0, flatSecurities_1 = flatSecurities; _i < flatSecurities_1.length; _i++) {
89
+ entry = flatSecurities_1[_i];
88
90
  securityKey = Object.keys(entry)[0];
89
91
  if (securityKey) {
90
92
  securityScheme = (_f = (_e = schema.components) === null || _e === void 0 ? void 0 : _e.securitySchemes) === null || _f === void 0 ? void 0 : _f[securityKey];
91
93
  if (securityScheme && !checkIsReference(securityScheme)) {
92
- securities.push([securityKey, securityScheme]);
94
+ securities.push([
95
+ securityKey,
96
+ __assign(__assign({}, securityScheme), { required: !isOptionalSecurity }),
97
+ ]);
93
98
  }
94
99
  }
95
100
  }
@@ -0,0 +1,11 @@
1
+ import { fromJSON, toJSON } from 'flatted';
2
+ import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
+ import type { OpenAPIWebhookData } from './types';
4
+ export { fromJSON, toJSON };
5
+ /**
6
+ * Resolve an OpenAPI webhook in a file and compile it to a more usable format.
7
+ */
8
+ export declare function resolveOpenAPIWebhook(filesystem: Filesystem<OpenAPIV3xDocument>, webhookDescriptor: {
9
+ name: string;
10
+ method: string;
11
+ }): Promise<OpenAPIWebhookData | null>;
@@ -0,0 +1,127 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ 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);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ 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;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
57
+ import { fromJSON, toJSON } from 'flatted';
58
+ import { dereferenceFilesystem } from './dereference';
59
+ export { fromJSON, toJSON };
60
+ /**
61
+ * Resolve an OpenAPI webhook in a file and compile it to a more usable format.
62
+ */
63
+ export function resolveOpenAPIWebhook(filesystem, webhookDescriptor) {
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var name, method, schema, operation, commonParameters, servers;
66
+ var _a, _b;
67
+ return __generator(this, function (_c) {
68
+ switch (_c.label) {
69
+ case 0:
70
+ name = webhookDescriptor.name, method = webhookDescriptor.method;
71
+ return [4 /*yield*/, dereferenceFilesystem(filesystem)];
72
+ case 1:
73
+ schema = _c.sent();
74
+ operation = getWebhookByNameAndMethod(schema, name, method);
75
+ if (!operation) {
76
+ return [2 /*return*/, null];
77
+ }
78
+ commonParameters = getPathObjectParameter(schema, name);
79
+ if (commonParameters) {
80
+ operation = __assign(__assign({}, operation), { parameters: __spreadArray(__spreadArray([], commonParameters, true), ((_a = operation.parameters) !== null && _a !== void 0 ? _a : []), true) });
81
+ }
82
+ servers = 'servers' in schema ? ((_b = schema.servers) !== null && _b !== void 0 ? _b : []) : [];
83
+ return [2 /*return*/, {
84
+ servers: servers,
85
+ operation: operation,
86
+ method: method,
87
+ name: name,
88
+ }];
89
+ }
90
+ });
91
+ });
92
+ }
93
+ /**
94
+ * Get a path object from its path.
95
+ */
96
+ function getPathObject(schema, name) {
97
+ var _a;
98
+ if ((_a = schema.webhooks) === null || _a === void 0 ? void 0 : _a[name]) {
99
+ return schema.webhooks[name];
100
+ }
101
+ return null;
102
+ }
103
+ /**
104
+ * Resolve parameters from a path in an OpenAPI schema.
105
+ */
106
+ function getPathObjectParameter(schema, path) {
107
+ var pathObject = getPathObject(schema, path);
108
+ if (pathObject === null || pathObject === void 0 ? void 0 : pathObject.parameters) {
109
+ return pathObject.parameters;
110
+ }
111
+ return null;
112
+ }
113
+ /**
114
+ * Get an operation by its path and method.
115
+ */
116
+ function getWebhookByNameAndMethod(schema, name, method) {
117
+ // Types are buffy for OpenAPIV3_1.OperationObject, so we use v3
118
+ var pathObject = getPathObject(schema, name);
119
+ if (!pathObject) {
120
+ return null;
121
+ }
122
+ var normalizedMethod = method.toLowerCase();
123
+ if (!pathObject[normalizedMethod]) {
124
+ return null;
125
+ }
126
+ return pathObject[normalizedMethod];
127
+ }
@@ -1,15 +1,14 @@
1
- import type { OpenAPIContextProps, OpenAPISchemasData } from '../types';
2
- type OpenAPISchemasContextProps = Omit<OpenAPIContextProps, 'renderCodeBlock' | 'renderHeading' | 'renderDocument'>;
1
+ import type { OpenAPISchema } from '@gitbook/openapi-parser';
2
+ import { type OpenAPIContextInput } from '../context';
3
3
  /**
4
- * Display OpenAPI Schemas.
4
+ * OpenAPI Schemas component.
5
5
  */
6
6
  export declare function OpenAPISchemas(props: {
7
7
  className?: string;
8
- data: OpenAPISchemasData;
9
- context: OpenAPISchemasContextProps;
8
+ schemas: OpenAPISchema[];
9
+ context: OpenAPIContextInput;
10
10
  /**
11
11
  * Whether to show the schema directly if there is only one.
12
12
  */
13
13
  grouped?: boolean;
14
14
  }): import("react").JSX.Element | null;
15
- export {};
@@ -1,62 +1,65 @@
1
1
  import clsx from 'clsx';
2
- import { OpenAPIDisclosureGroup } from '../OpenAPIDisclosureGroup';
2
+ import { OpenAPIDisclosure } from '../OpenAPIDisclosure';
3
+ import { OpenAPIExample } from '../OpenAPIExample';
3
4
  import { OpenAPIRootSchema } from '../OpenAPISchemaServer';
4
- import { Section, SectionBody } from '../StaticSection';
5
+ import { Section, SectionBody, StaticSection } from '../StaticSection';
6
+ import { getOpenAPIClientContext, resolveOpenAPIContext, } from '../context';
7
+ import { t } from '../translate';
8
+ import { getExampleFromSchema } from '../util/example';
5
9
  /**
6
- * Display OpenAPI Schemas.
10
+ * OpenAPI Schemas component.
7
11
  */
8
12
  export function OpenAPISchemas(props) {
9
- var className = props.className, data = props.data, context = props.context, grouped = props.grouped;
10
- var schemas = data.schemas;
11
- var clientContext = {
12
- defaultInteractiveOpened: context.defaultInteractiveOpened,
13
- icons: context.icons,
14
- blockKey: context.blockKey,
15
- };
16
- if (!schemas.length) {
13
+ var schemas = props.schemas, contextInput = props.context, grouped = props.grouped, className = props.className;
14
+ var firstSchema = schemas[0];
15
+ if (!firstSchema) {
17
16
  return null;
18
17
  }
19
- return (<div className={clsx('openapi-schemas', className)}>
20
- <OpenAPIRootSchemasSchema grouped={grouped} schemas={schemas} context={clientContext}/>
21
- </div>);
22
- }
23
- /**
24
- * Root schema for OpenAPI schemas.
25
- * It displays a single model or a disclosure group for multiple schemas.
26
- */
27
- function OpenAPIRootSchemasSchema(props) {
28
- var _a;
29
- var schemas = props.schemas, context = props.context, grouped = props.grouped;
18
+ var context = resolveOpenAPIContext(contextInput);
19
+ var clientContext = getOpenAPIClientContext(context);
30
20
  // If there is only one model and we are not grouping, we show it directly.
31
21
  if (schemas.length === 1 && !grouped) {
32
- var schema = (_a = schemas === null || schemas === void 0 ? void 0 : schemas[0]) === null || _a === void 0 ? void 0 : _a.schema;
33
- if (!schema) {
34
- return null;
35
- }
36
- return (<Section>
37
- <SectionBody>
38
- <OpenAPIRootSchema schema={schema} context={context}/>
39
- </SectionBody>
40
- </Section>);
22
+ var title = "The ".concat(firstSchema.name, " object");
23
+ return (<div className={clsx('openapi-schemas', className)}>
24
+ <div className="openapi-summary" id={context.id}>
25
+ {context.renderHeading({
26
+ title: title,
27
+ deprecated: Boolean(firstSchema.schema.deprecated),
28
+ stability: firstSchema.schema['x-stability'],
29
+ })}
30
+ </div>
31
+ <div className="openapi-columns">
32
+ <div className="openapi-column-spec">
33
+ <StaticSection className="openapi-parameters" header={t(context.translation, 'attributes')}>
34
+ <OpenAPIRootSchema schema={firstSchema.schema} context={clientContext}/>
35
+ </StaticSection>
36
+ </div>
37
+ <div className="openapi-column-preview">
38
+ <div className="openapi-column-preview-body">
39
+ <div className="openapi-panel">
40
+ <h4 className="openapi-panel-heading">{title}</h4>
41
+ <div className="openapi-panel-body">
42
+ <OpenAPIExample example={getExampleFromSchema({
43
+ schema: firstSchema.schema,
44
+ })} context={context} syntax="json"/>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ </div>
50
+ </div>);
41
51
  }
42
52
  // If there are multiple schemas, we use a disclosure group to show them all.
43
- return (<OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={schemas.map(function (_a) {
53
+ return (<div className={clsx('openapi-schemas', className)}>
54
+ {schemas.map(function (_a) {
44
55
  var name = _a.name, schema = _a.schema;
45
- return ({
46
- id: name,
47
- label: (<div className="openapi-response-tab-content" key={"model-".concat(name)}>
48
- <span className="openapi-response-statuscode">{name}</span>
49
- </div>),
50
- tabs: [
51
- {
52
- id: 'model',
53
- body: (<Section className="openapi-section-schemas">
54
- <SectionBody>
55
- <OpenAPIRootSchema schema={schema} context={context}/>
56
- </SectionBody>
57
- </Section>),
58
- },
59
- ],
60
- });
61
- })}/>);
56
+ return (<OpenAPIDisclosure className="openapi-schemas-disclosure" key={name} icon={context.icons.chevronRight} label={name}>
57
+ <Section className="openapi-section-schemas">
58
+ <SectionBody>
59
+ <OpenAPIRootSchema schema={schema} context={clientContext}/>
60
+ </SectionBody>
61
+ </Section>
62
+ </OpenAPIDisclosure>);
63
+ })}
64
+ </div>);
62
65
  }
@@ -1,9 +1,10 @@
1
- import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
2
- import type { OpenAPISchemasData } from '../types';
1
+ import type { Filesystem, OpenAPISchema, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
2
  /**
4
3
  * Resolve an OpenAPI schemas from a file and compile it to a more usable format.
5
4
  * Schemas are extracted from the OpenAPI components.schemas
6
5
  */
7
6
  export declare function resolveOpenAPISchemas(filesystem: Filesystem<OpenAPIV3xDocument>, options: {
8
7
  schemas: string[];
9
- }): Promise<OpenAPISchemasData | null>;
8
+ }): Promise<{
9
+ schemas: OpenAPISchema[];
10
+ } | null>;
@@ -36,7 +36,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import { filterSelectedOpenAPISchemas } from '@gitbook/openapi-parser';
38
38
  import { dereferenceFilesystem } from '../dereference';
39
- //!!TODO: We should return only the schemas that are used in the block. Still a WIP awaiting future work.
40
39
  /**
41
40
  * Resolve an OpenAPI schemas from a file and compile it to a more usable format.
42
41
  * Schemas are extracted from the OpenAPI components.schemas
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Stringify an OpenAPI object. Same API as JSON.stringify.
3
3
  */
4
- export declare function stringifyOpenAPI(body: unknown, _?: null, indent?: number): string;
4
+ export declare function stringifyOpenAPI(value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number): string;
@@ -1,12 +1,15 @@
1
1
  /**
2
2
  * Stringify an OpenAPI object. Same API as JSON.stringify.
3
3
  */
4
- export function stringifyOpenAPI(body, _, indent) {
5
- return JSON.stringify(body, function (key, value) {
4
+ export function stringifyOpenAPI(value, replacer, space) {
5
+ return JSON.stringify(value, function (key, value) {
6
6
  // Ignore internal keys
7
7
  if (key.startsWith('x-gitbook-')) {
8
8
  return undefined;
9
9
  }
10
+ if (replacer) {
11
+ return replacer(key, value);
12
+ }
10
13
  return value;
11
- }, indent);
14
+ }, space);
12
15
  }
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { Translation, TranslationKey } from './translations';
3
+ /**
4
+ * Translate a string.
5
+ */
6
+ export declare function t(translation: Translation, id: TranslationKey, ...args: React.ReactNode[]): React.ReactNode;
7
+ /**
8
+ * Version of `t` that returns a string.
9
+ */
10
+ export declare function tString(translation: Translation, id: TranslationKey, ...args: React.ReactNode[]): string;
@@ -0,0 +1,75 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import React from 'react';
11
+ /**
12
+ * Translate a string.
13
+ */
14
+ export function t(translation, id) {
15
+ var args = [];
16
+ for (var _i = 2; _i < arguments.length; _i++) {
17
+ args[_i - 2] = arguments[_i];
18
+ }
19
+ var string = translation[id];
20
+ if (!string) {
21
+ throw new Error("Translation not found for \"".concat(id, "\""));
22
+ }
23
+ // Now we are going to replace the arguments
24
+ // but we want to return a string as long as it's possible
25
+ // (eg. if there isn't any argument that is a ReactNode)
26
+ var parts = [];
27
+ var currentStringToReplace = string;
28
+ args.forEach(function (arg, i) {
29
+ if (typeof arg === 'string') {
30
+ currentStringToReplace = currentStringToReplace.replace("${".concat(i + 1, "}"), arg);
31
+ }
32
+ else {
33
+ var _a = currentStringToReplace.split("${".concat(i + 1, "}")), partToPush = _a[0], partToReplace = _a[1];
34
+ if (partToPush === undefined || partToReplace === undefined) {
35
+ throw new Error("Invalid translation \"".concat(id, "\""));
36
+ }
37
+ parts.push(<React.Fragment key={"string-".concat(i)}>{partToPush}</React.Fragment>);
38
+ parts.push(<React.Fragment key={"arg-".concat(i)}>{arg}</React.Fragment>);
39
+ currentStringToReplace = partToReplace;
40
+ }
41
+ });
42
+ if (!parts.length) {
43
+ return currentStringToReplace;
44
+ }
45
+ return (<>
46
+ {parts}
47
+ {currentStringToReplace}
48
+ </>);
49
+ }
50
+ /**
51
+ * Version of `t` that returns a string.
52
+ */
53
+ export function tString(translation, id) {
54
+ var args = [];
55
+ for (var _i = 2; _i < arguments.length; _i++) {
56
+ args[_i - 2] = arguments[_i];
57
+ }
58
+ var result = t.apply(void 0, __spreadArray([translation, id], args, false));
59
+ return reactToString(result);
60
+ }
61
+ function reactToString(el) {
62
+ if (typeof el === 'string' || typeof el === 'number' || typeof el === 'boolean') {
63
+ return "".concat(el);
64
+ }
65
+ if (el === null || el === undefined) {
66
+ return '';
67
+ }
68
+ if (Array.isArray(el)) {
69
+ return el.map(reactToString).join('');
70
+ }
71
+ if (typeof el === 'object' && 'props' in el) {
72
+ return el.props.children.map(reactToString).join('');
73
+ }
74
+ throw new Error("Unsupported type ".concat(typeof el));
75
+ }
@@ -0,0 +1,37 @@
1
+ export declare const de: {
2
+ required: string;
3
+ deprecated: string;
4
+ deprecated_and_sunset_on: string;
5
+ stability_experimental: string;
6
+ stability_alpha: string;
7
+ stability_beta: string;
8
+ copy_to_clipboard: string;
9
+ copied: string;
10
+ no_content: string;
11
+ unresolved_reference: string;
12
+ circular_reference: string;
13
+ read_only: string;
14
+ write_only: string;
15
+ optional: string;
16
+ min: string;
17
+ max: string;
18
+ nullable: string;
19
+ body: string;
20
+ payload: string;
21
+ headers: string;
22
+ authorizations: string;
23
+ responses: string;
24
+ path_parameters: string;
25
+ query_parameters: string;
26
+ header_parameters: string;
27
+ attributes: string;
28
+ test_it: string;
29
+ information: string;
30
+ success: string;
31
+ redirect: string;
32
+ error: string;
33
+ show: string;
34
+ hide: string;
35
+ available_items: string;
36
+ child_attributes: string;
37
+ };
@@ -0,0 +1,37 @@
1
+ export var de = {
2
+ required: 'Erforderlich',
3
+ deprecated: 'Veraltet',
4
+ deprecated_and_sunset_on: 'Diese Operation ist veraltet und wird am ${1} eingestellt.',
5
+ stability_experimental: 'Experimentell',
6
+ stability_alpha: 'Alpha',
7
+ stability_beta: 'Beta',
8
+ copy_to_clipboard: 'In die Zwischenablage kopieren',
9
+ copied: 'Kopiert',
10
+ no_content: 'Kein Inhalt',
11
+ unresolved_reference: 'Nicht aufgelöste Referenz',
12
+ circular_reference: 'Zirkuläre Referenz',
13
+ read_only: 'Nur lesen',
14
+ write_only: 'Nur schreiben',
15
+ optional: 'Optional',
16
+ min: 'Min',
17
+ max: 'Max',
18
+ nullable: 'Nullfähig',
19
+ body: 'Rumpf',
20
+ payload: 'Nutzlast',
21
+ headers: 'Kopfzeilen',
22
+ authorizations: 'Autorisierungen',
23
+ responses: 'Antworten',
24
+ path_parameters: 'Pfadparameter',
25
+ query_parameters: 'Abfrageparameter',
26
+ header_parameters: 'Header-Parameter',
27
+ attributes: 'Attribute',
28
+ test_it: 'Teste es',
29
+ information: 'Information',
30
+ success: 'Erfolg',
31
+ redirect: 'Umleitung',
32
+ error: 'Fehler',
33
+ show: 'Anzeigen',
34
+ hide: 'Verstecken',
35
+ available_items: 'Verfügbare Elemente',
36
+ child_attributes: 'Unterattribute',
37
+ };