@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
@@ -1,44 +0,0 @@
1
- /**
2
- * Get the default URL for the server.
3
- */
4
- export function getDefaultServerURL(servers) {
5
- var server = servers[0];
6
- if (!server) {
7
- // Return empty string if no server is found to display nothing
8
- return '';
9
- }
10
- return interpolateServerURL(server);
11
- }
12
- /**
13
- * Interpolate the server URL with the default values of the variables.
14
- */
15
- export function interpolateServerURL(server) {
16
- var _a;
17
- var parts = parseServerURL((_a = server === null || server === void 0 ? void 0 : server.url) !== null && _a !== void 0 ? _a : '');
18
- return parts
19
- .map(function (part) {
20
- var _a, _b, _c;
21
- if (part.kind === 'text') {
22
- return part.text;
23
- }
24
- return (_c = (_b = (_a = server.variables) === null || _a === void 0 ? void 0 : _a[part.name]) === null || _b === void 0 ? void 0 : _b.default) !== null && _c !== void 0 ? _c : "{".concat(part.name, "}");
25
- })
26
- .join('');
27
- }
28
- function parseServerURL(url) {
29
- var parts = url.split(/{([^}]+)}/g);
30
- var result = [];
31
- for (var i = 0; i < parts.length; i++) {
32
- var part = parts[i];
33
- if (!part) {
34
- continue;
35
- }
36
- if (i % 2 === 0) {
37
- result.push({ kind: 'text', text: part });
38
- }
39
- else {
40
- result.push({ kind: 'variable', name: part });
41
- }
42
- }
43
- return result;
44
- }
@@ -1,20 +0,0 @@
1
- import type { ApiClientConfiguration } from '@scalar/types';
2
- import type { PrefillInputContextData } from '../OpenAPIPrefillContextProvider';
3
- import type { OpenAPIOperationData } from '../types';
4
- export interface TryItPrefillConfiguration {
5
- authentication?: ApiClientConfiguration['authentication'];
6
- servers?: ApiClientConfiguration['servers'];
7
- }
8
- /**
9
- * Resolve the Scalar API client prefill configuration for a given OpenAPI operation.
10
- */
11
- export declare function resolveTryItPrefillForOperation(args: {
12
- /**
13
- * The parsed OpenAPI operation.
14
- */
15
- operation: Pick<OpenAPIOperationData, 'securities' | 'servers'>;
16
- /**
17
- * Prefill input context data.
18
- */
19
- prefillInputContext: PrefillInputContextData | null;
20
- }): TryItPrefillConfiguration;
@@ -1,129 +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 { ExpressionRuntime, parseTemplate } from '@gitbook/expr';
24
- /**
25
- * Resolve the Scalar API client prefill configuration for a given OpenAPI operation.
26
- */
27
- export function resolveTryItPrefillForOperation(args) {
28
- var _a = args.operation, securities = _a.securities, servers = _a.servers, prefillInputContext = args.prefillInputContext;
29
- if (!prefillInputContext) {
30
- return {};
31
- }
32
- var runtime = new ExpressionRuntime();
33
- var resolveTryItPrefillExpression = function (expr) {
34
- var parts = parseTemplate(expr);
35
- if (!parts.length) {
36
- return undefined;
37
- }
38
- return runtime.evaluateTemplate(expr, prefillInputContext);
39
- };
40
- var prefillAuth = securities
41
- ? resolveTryItPrefillAuthForOperationSecurities({
42
- securities: securities,
43
- resolveTryItPrefillExpression: resolveTryItPrefillExpression,
44
- })
45
- : undefined;
46
- var prefillServers = servers
47
- ? resolveTryItPrefillServersForOperationServers({ servers: servers, resolveTryItPrefillExpression: resolveTryItPrefillExpression })
48
- : [];
49
- return __assign(__assign({}, (prefillAuth ? { authentication: prefillAuth } : {})), (prefillServers ? { servers: prefillServers } : {}));
50
- }
51
- /**
52
- * Resolve prefill authentication configuration for the security schemes defined for an operation.
53
- */
54
- function resolveTryItPrefillAuthForOperationSecurities(args) {
55
- var _a, _b;
56
- var securities = args.securities, resolveTryItPrefillExpression = args.resolveTryItPrefillExpression;
57
- var prefillAuthConfig = {};
58
- for (var _i = 0, _c = Object.values(securities); _i < _c.length; _i++) {
59
- var _d = _c[_i], schemeName = _d[0], security = _d[1];
60
- var tryitPrefillAuthValue = security['x-gitbook-prefill']
61
- ? resolveTryItPrefillExpression(security['x-gitbook-prefill'])
62
- : undefined;
63
- if (!tryitPrefillAuthValue) {
64
- continue;
65
- }
66
- switch (security.type) {
67
- case 'http': {
68
- if ((_a = security.scheme) === null || _a === void 0 ? void 0 : _a.includes('bearer')) {
69
- prefillAuthConfig[schemeName] = { token: tryitPrefillAuthValue };
70
- }
71
- else if (((_b = security.scheme) === null || _b === void 0 ? void 0 : _b.includes('basic')) &&
72
- tryitPrefillAuthValue.includes(':')) {
73
- var _e = tryitPrefillAuthValue.split(':', 2), username = _e[0], password = _e[1];
74
- prefillAuthConfig[schemeName] = { username: username, password: password };
75
- }
76
- break;
77
- }
78
- case 'apiKey': {
79
- prefillAuthConfig[schemeName] = {
80
- name: security.name,
81
- in: security.in,
82
- value: tryitPrefillAuthValue,
83
- };
84
- break;
85
- }
86
- case 'oauth2':
87
- case 'openIdConnect': {
88
- break;
89
- }
90
- }
91
- }
92
- return Object.keys(prefillAuthConfig).length > 0
93
- ? { securitySchemes: prefillAuthConfig }
94
- : undefined;
95
- }
96
- /**
97
- * Resolve prefill server configuration for the servers defined for an operation.
98
- */
99
- function resolveTryItPrefillServersForOperationServers(args) {
100
- var servers = args.servers, resolveTryItPrefillExpression = args.resolveTryItPrefillExpression;
101
- var resolvedServers = [];
102
- for (var _i = 0, servers_1 = servers; _i < servers_1.length; _i++) {
103
- var server = servers_1[_i];
104
- // Url-level prefill
105
- var tryItPrefillServerUrlExpr = server['x-gitbook-prefill'];
106
- var tryItPrefillServerUrlValue = tryItPrefillServerUrlExpr
107
- ? resolveTryItPrefillExpression(tryItPrefillServerUrlExpr)
108
- : undefined;
109
- var variables = server.variables
110
- ? __assign({}, server.variables) : {};
111
- // Variable-level prefill
112
- if (server.variables) {
113
- for (var _a = 0, _b = Object.entries(server.variables); _a < _b.length; _a++) {
114
- var _c = _b[_a], varName = _c[0], variable = _c[1];
115
- var tryItPrefillVarExpr = variable["x-gitbook-prefill"], variableProps = __rest(variable, ['x-gitbook-prefill']);
116
- var tryItPrefillVarValue = tryItPrefillVarExpr
117
- ? resolveTryItPrefillExpression(tryItPrefillVarExpr)
118
- : undefined;
119
- variables[varName] = __assign(__assign({}, variableProps), (tryItPrefillVarValue ? { default: String(tryItPrefillVarValue) } : {}));
120
- }
121
- }
122
- var hasServerVariables = Object.keys(variables).length > 0;
123
- if (server.url && (tryItPrefillServerUrlValue || hasServerVariables)) {
124
- var resolvedServer = __assign(__assign({ url: tryItPrefillServerUrlValue !== null && tryItPrefillServerUrlValue !== void 0 ? tryItPrefillServerUrlValue : server.url }, (server.description ? { description: server.description } : {})), (hasServerVariables ? { variables: variables } : {}));
125
- resolvedServers.push(resolvedServer);
126
- }
127
- }
128
- return resolvedServers.length > 0 ? resolvedServers : undefined;
129
- }
package/dist/utils.d.ts DELETED
@@ -1,50 +0,0 @@
1
- import type { AnyObject, OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIUniversalContext } from './context';
3
- export declare function checkIsReference(input: unknown): input is OpenAPIV3.ReferenceObject;
4
- export declare function createStateKey(key: string, scope?: string): string;
5
- /**
6
- * Resolve the description of an object.
7
- */
8
- export declare function resolveDescription(object: OpenAPIV3.SchemaObject | AnyObject): string | undefined;
9
- /**
10
- * Extract descriptions from an object.
11
- */
12
- export declare function extractDescriptions(object: AnyObject): {
13
- description: any;
14
- 'x-gitbook-description-html': any;
15
- };
16
- /**
17
- * Resolve the first example from an object.
18
- */
19
- export declare function resolveFirstExample(object: AnyObject): string | undefined;
20
- /**
21
- * Resolve the schema of a parameter.
22
- * Extract the description, example and deprecated from parameter.
23
- */
24
- export declare function resolveParameterSchema(parameter: OpenAPIV3.ParameterBaseObject): OpenAPIV3.SchemaObject;
25
- /**
26
- * Transform a parameter object to a property object.
27
- */
28
- export declare function parameterToProperty(parameter: OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject): {
29
- propertyName: string | undefined;
30
- schema: OpenAPIV3.SchemaObject;
31
- required: boolean | undefined;
32
- };
33
- /**
34
- * Get the class name for a status code.
35
- * 1xx: informational
36
- * 2xx: success
37
- * 3xx: redirect
38
- * 4xx, 5xx: error
39
- */
40
- export declare function getStatusCodeClassName(statusCode: number | string): string;
41
- /**
42
- * Get a default label for a status code.
43
- * This is used when there is no label provided in the OpenAPI spec.
44
- * 1xx: Information
45
- * 2xx: Success
46
- * 3xx: Redirect
47
- * 4xx, 5xx: Error
48
- */
49
- export declare function getStatusCodeDefaultLabel(statusCode: number | string, context: OpenAPIUniversalContext): string;
50
- export declare function getSchemaTitle(schema: OpenAPIV3.SchemaObject): string;
package/dist/utils.js DELETED
@@ -1,224 +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 { stringifyOpenAPI } from './stringifyOpenAPI';
13
- import { tString } from './translate';
14
- export function checkIsReference(input) {
15
- return typeof input === 'object' && !!input && '$ref' in input;
16
- }
17
- export function createStateKey(key, scope) {
18
- return scope ? "".concat(scope, "_").concat(key) : key;
19
- }
20
- /**
21
- * Check if an object has a description. Either at the root level or in items.
22
- */
23
- function hasDescription(object) {
24
- return 'description' in object || 'x-gitbook-description-html' in object;
25
- }
26
- /**
27
- * Resolve the description of an object.
28
- */
29
- export function resolveDescription(object) {
30
- // Resolve description from the object first
31
- if (hasDescription(object)) {
32
- return 'x-gitbook-description-html' in object &&
33
- typeof object['x-gitbook-description-html'] === 'string'
34
- ? object['x-gitbook-description-html'].trim()
35
- : typeof object.description === 'string'
36
- ? object.description.trim()
37
- : undefined;
38
- }
39
- // If the object has no description, try to resolve it from the items
40
- if ('items' in object && typeof object.items === 'object' && hasDescription(object.items)) {
41
- return resolveDescription(object.items);
42
- }
43
- return undefined;
44
- }
45
- /**
46
- * Extract descriptions from an object.
47
- */
48
- export function extractDescriptions(object) {
49
- return {
50
- description: object.description,
51
- 'x-gitbook-description-html': 'x-gitbook-description-html' in object
52
- ? object['x-gitbook-description-html']
53
- : undefined,
54
- };
55
- }
56
- /**
57
- * Resolve the first example from an object.
58
- */
59
- export function resolveFirstExample(object) {
60
- if ('examples' in object && typeof object.examples === 'object' && object.examples) {
61
- var keys = Object.keys(object.examples);
62
- var firstKey = keys[0];
63
- if (firstKey && object.examples[firstKey]) {
64
- return formatExample(object.examples[firstKey]);
65
- }
66
- }
67
- // Resolve top level example first
68
- if (shouldDisplayExample(object)) {
69
- return formatExample(object.example);
70
- }
71
- // Resolve example from items if it exists
72
- if (object.items && typeof object.items === 'object') {
73
- return formatExample(object.items.example);
74
- }
75
- return undefined;
76
- }
77
- /**
78
- * Resolve the schema of a parameter.
79
- * Extract the description, example and deprecated from parameter.
80
- */
81
- export function resolveParameterSchema(parameter) {
82
- var schema = checkIsReference(parameter.schema) ? undefined : parameter.schema;
83
- return __assign(__assign(__assign({}, extractDescriptions(parameter)), { example: resolveFirstExample(parameter),
84
- // Deprecated can be defined at the parameter level
85
- deprecated: parameter.deprecated }), schema);
86
- }
87
- /**
88
- * Transform a parameter object to a property object.
89
- */
90
- export function parameterToProperty(parameter) {
91
- var _a;
92
- if (checkIsReference(parameter)) {
93
- return {
94
- propertyName: (_a = parameter.$ref) !== null && _a !== void 0 ? _a : 'Unknown ref',
95
- schema: {},
96
- required: undefined,
97
- };
98
- }
99
- return {
100
- propertyName: parameter.name,
101
- schema: resolveParameterSchema(parameter),
102
- required: parameter.required,
103
- };
104
- }
105
- /**
106
- * Format the example of a schema.
107
- */
108
- function formatExample(example) {
109
- if (typeof example === 'string') {
110
- return example
111
- .replace(/\n/g, ' ') // Replace newlines with spaces
112
- .replace(/\s+/g, ' ') // Collapse multiple spaces/newlines into a single space
113
- .replace(/([\{\}:,])\s+/g, '$1 ') // Ensure a space after {, }, :, and ,
114
- .replace(/\s+([\{\}:,])/g, ' $1') // Ensure a space before {, }, :, and ,
115
- .trim();
116
- }
117
- return stringifyOpenAPI(example);
118
- }
119
- /**
120
- * Check if an example should be displayed.
121
- */
122
- function shouldDisplayExample(schema) {
123
- return ((typeof schema.example === 'string' && !!schema.example) ||
124
- typeof schema.example === 'number' ||
125
- typeof schema.example === 'boolean' ||
126
- (Array.isArray(schema.example) && schema.example.length > 0) ||
127
- (typeof schema.example === 'object' &&
128
- schema.example !== null &&
129
- Object.keys(schema.example).length > 0));
130
- }
131
- /**
132
- * Get the class name for a status code.
133
- * 1xx: informational
134
- * 2xx: success
135
- * 3xx: redirect
136
- * 4xx, 5xx: error
137
- */
138
- export function getStatusCodeClassName(statusCode) {
139
- var category = getStatusCodeCategory(statusCode);
140
- switch (category) {
141
- case 1:
142
- return 'informational';
143
- case 2:
144
- return 'success';
145
- case 3:
146
- return 'redirect';
147
- case 4:
148
- case 5:
149
- return 'error';
150
- default:
151
- return 'unknown';
152
- }
153
- }
154
- /**
155
- * Get a default label for a status code.
156
- * This is used when there is no label provided in the OpenAPI spec.
157
- * 1xx: Information
158
- * 2xx: Success
159
- * 3xx: Redirect
160
- * 4xx, 5xx: Error
161
- */
162
- export function getStatusCodeDefaultLabel(statusCode, context) {
163
- var category = getStatusCodeCategory(statusCode);
164
- switch (category) {
165
- case 1:
166
- return tString(context.translation, 'information');
167
- case 2:
168
- return tString(context.translation, 'success');
169
- case 3:
170
- return tString(context.translation, 'redirect');
171
- case 4:
172
- case 5:
173
- return tString(context.translation, 'error');
174
- default:
175
- return '';
176
- }
177
- }
178
- function getStatusCodeCategory(statusCode) {
179
- var code = typeof statusCode === 'string' ? Number.parseInt(statusCode, 10) : statusCode;
180
- if (Number.isNaN(code) || code < 100 || code >= 600) {
181
- return 'unknown';
182
- }
183
- // Determine the category of the status code based on the first digit
184
- var category = Math.floor(code / 100);
185
- return category;
186
- }
187
- export function getSchemaTitle(schema) {
188
- var _a;
189
- // Otherwise try to infer a nice title
190
- var type = 'any';
191
- if (schema.enum || schema['x-enumDescriptions'] || schema['x-gitbook-enum']) {
192
- type = "".concat(schema.type, " \u00B7 enum");
193
- // check array AND schema.items as this is sometimes null despite what the type indicates
194
- }
195
- else if (schema.type === 'array' && !!schema.items) {
196
- type = "".concat(getSchemaTitle(schema.items), "[]");
197
- }
198
- else if (Array.isArray(schema.type)) {
199
- type = schema.type.join(' | ');
200
- }
201
- else if (schema.type || schema.properties) {
202
- type = (_a = schema.type) !== null && _a !== void 0 ? _a : 'object';
203
- if (schema.format) {
204
- type += " \u00B7 ".concat(schema.format);
205
- }
206
- // Only add the title if it's an object (no need for the title of a string, number, etc.)
207
- if (type === 'object' && schema.title) {
208
- type += " \u00B7 ".concat(schema.title.replaceAll(' ', ''));
209
- }
210
- }
211
- if ('anyOf' in schema) {
212
- type = 'any of';
213
- }
214
- else if ('oneOf' in schema) {
215
- type = 'one of';
216
- }
217
- else if ('allOf' in schema) {
218
- type = 'all of';
219
- }
220
- else if ('not' in schema) {
221
- type = 'not';
222
- }
223
- return type;
224
- }
@@ -1,147 +0,0 @@
1
- 'use client';
2
-
3
- import clsx from 'clsx';
4
- import { useRef } from 'react';
5
- import { mergeProps, useButton, useDisclosure, useFocusRing } from 'react-aria';
6
- import { useDisclosureState } from 'react-stately';
7
- import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
8
- import { Section, SectionBody, SectionHeader, SectionHeaderContent } from './StaticSection';
9
-
10
- interface InteractiveSectionTab {
11
- key: string;
12
- label: string;
13
- body: React.ReactNode;
14
- }
15
-
16
- /**
17
- * To optimize rendering, most of the components are server-components,
18
- * and the interactiveness is mainly handled by a few key components like this one.
19
- */
20
- export function InteractiveSection(props: {
21
- id?: string;
22
- /** Class name to be set on the section, sub-elements will use it as prefix */
23
- className: string;
24
- /** If true, the content can be toggeable */
25
- toggeable?: boolean;
26
- /** Default state of the toggle */
27
- defaultOpened?: boolean;
28
- /** Icon to display for the toggle */
29
- toggleIcon?: React.ReactNode;
30
- /** Tabs of content to display */
31
- tabs?: Array<InteractiveSectionTab>;
32
- /** Default tab to have opened */
33
- defaultTab?: string;
34
- /** Content of the header */
35
- header?: React.ReactNode;
36
- /** Children to display within the container */
37
- overlay?: React.ReactNode;
38
- /** State key to use with a store */
39
- stateKey?: string;
40
- /** Icon for the tabs select */
41
- selectIcon?: React.ReactNode;
42
- }) {
43
- const {
44
- id,
45
- className,
46
- toggeable = false,
47
- defaultOpened = true,
48
- tabs = [],
49
- defaultTab = tabs[0]?.key,
50
- header,
51
- overlay,
52
- toggleIcon = '▶',
53
- selectIcon,
54
- stateKey = 'interactive-section',
55
- } = props;
56
- const state = useDisclosureState({
57
- defaultExpanded: defaultOpened,
58
- });
59
- const panelRef = useRef<HTMLDivElement | null>(null);
60
- const triggerRef = useRef<HTMLButtonElement | null>(null);
61
- const { buttonProps: triggerProps, panelProps } = useDisclosure({}, state, panelRef);
62
- const { buttonProps } = useButton(triggerProps, triggerRef);
63
- const { isFocusVisible, focusProps } = useFocusRing();
64
- const store = useSelectState(stateKey, defaultTab);
65
-
66
- const selectedTab: InteractiveSectionTab | undefined =
67
- tabs.find((tab) => tab.key === store.key) ?? tabs[0];
68
-
69
- return (
70
- <Section
71
- id={id}
72
- className={clsx(
73
- 'openapi-section',
74
- toggeable ? 'openapi-section-toggeable' : null,
75
- className,
76
- toggeable ? `${className}-${state.isExpanded ? 'opened' : 'closed'}` : null
77
- )}
78
- >
79
- {header ? (
80
- <SectionHeader
81
- onClick={() => {
82
- if (toggeable) {
83
- state.toggle();
84
- }
85
- }}
86
- className={className}
87
- >
88
- <SectionHeaderContent className={className}>
89
- {selectedTab?.body && toggeable ? (
90
- <button
91
- {...mergeProps(buttonProps, focusProps)}
92
- ref={triggerRef}
93
- className={clsx('openapi-section-toggle', `${className}-toggle`)}
94
- style={{
95
- outline: isFocusVisible
96
- ? '2px solid rgb(var(--primary-color-500) / 0.4)'
97
- : 'none',
98
- }}
99
- >
100
- {toggleIcon}
101
- </button>
102
- ) : null}
103
- {header}
104
- </SectionHeaderContent>
105
- {/* biome-ignore lint/a11y/useKeyWithClickEvents: we prevent default here */}
106
- <div
107
- className={clsx(
108
- 'openapi-section-header-controls',
109
- `${className}-header-controls`
110
- )}
111
- onClick={(event) => {
112
- event.stopPropagation();
113
- }}
114
- >
115
- {tabs.length > 0 ? (
116
- <OpenAPISelect
117
- stateKey={stateKey}
118
- items={tabs}
119
- onSelectionChange={() => {
120
- state.expand();
121
- }}
122
- icon={selectIcon}
123
- placement="bottom end"
124
- >
125
- {tabs.map((tab) => (
126
- <OpenAPISelectItem key={tab.key} id={tab.key} value={tab}>
127
- {tab.label}
128
- </OpenAPISelectItem>
129
- ))}
130
- </OpenAPISelect>
131
- ) : null}
132
- </div>
133
- </SectionHeader>
134
- ) : null}
135
- {(!toggeable || state.isExpanded) && selectedTab?.body ? (
136
- <SectionBody ref={panelRef} {...panelProps} className={className}>
137
- {selectedTab?.body}
138
- </SectionBody>
139
- ) : null}
140
- {overlay ? (
141
- <div className={clsx('openapi-section-overlay', `${className}-overlay`)}>
142
- {overlay}
143
- </div>
144
- ) : null}
145
- </Section>
146
- );
147
- }
package/src/Markdown.tsx DELETED
@@ -1,12 +0,0 @@
1
- import clsx from 'clsx';
2
-
3
- export function Markdown(props: { source: string; className?: string }) {
4
- const { source, className } = props;
5
-
6
- return (
7
- <div
8
- className={clsx('openapi-markdown', className)}
9
- dangerouslySetInnerHTML={{ __html: source }}
10
- />
11
- );
12
- }