docusaurus-plugin-openapi-docs 0.0.0-1000

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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +361 -0
  3. package/lib/index.d.ts +9 -0
  4. package/lib/index.js +709 -0
  5. package/lib/markdown/createArrayBracket.d.ts +2 -0
  6. package/lib/markdown/createArrayBracket.js +36 -0
  7. package/lib/markdown/createAuthentication.d.ts +2 -0
  8. package/lib/markdown/createAuthentication.js +171 -0
  9. package/lib/markdown/createAuthorization.d.ts +1 -0
  10. package/lib/markdown/createAuthorization.js +15 -0
  11. package/lib/markdown/createCallbackMethodEndpoint.d.ts +1 -0
  12. package/lib/markdown/createCallbackMethodEndpoint.js +20 -0
  13. package/lib/markdown/createCallbacks.d.ts +6 -0
  14. package/lib/markdown/createCallbacks.js +77 -0
  15. package/lib/markdown/createContactInfo.d.ts +2 -0
  16. package/lib/markdown/createContactInfo.js +39 -0
  17. package/lib/markdown/createDeprecationNotice.d.ts +6 -0
  18. package/lib/markdown/createDeprecationNotice.js +20 -0
  19. package/lib/markdown/createDescription.d.ts +1 -0
  20. package/lib/markdown/createDescription.js +13 -0
  21. package/lib/markdown/createDetails.d.ts +2 -0
  22. package/lib/markdown/createDetails.js +17 -0
  23. package/lib/markdown/createDetailsSummary.d.ts +2 -0
  24. package/lib/markdown/createDetailsSummary.js +17 -0
  25. package/lib/markdown/createDownload.d.ts +1 -0
  26. package/lib/markdown/createDownload.js +16 -0
  27. package/lib/markdown/createHeading.d.ts +1 -0
  28. package/lib/markdown/createHeading.js +20 -0
  29. package/lib/markdown/createLicense.d.ts +2 -0
  30. package/lib/markdown/createLicense.js +32 -0
  31. package/lib/markdown/createLogo.d.ts +2 -0
  32. package/lib/markdown/createLogo.js +18 -0
  33. package/lib/markdown/createMethodEndpoint.d.ts +1 -0
  34. package/lib/markdown/createMethodEndpoint.js +20 -0
  35. package/lib/markdown/createParamsDetails.d.ts +6 -0
  36. package/lib/markdown/createParamsDetails.js +18 -0
  37. package/lib/markdown/createRequestBodyDetails.d.ts +13 -0
  38. package/lib/markdown/createRequestBodyDetails.js +13 -0
  39. package/lib/markdown/createRequestHeader.d.ts +1 -0
  40. package/lib/markdown/createRequestHeader.js +21 -0
  41. package/lib/markdown/createRequestSchema.d.ts +14 -0
  42. package/lib/markdown/createRequestSchema.js +20 -0
  43. package/lib/markdown/createResponseSchema.d.ts +14 -0
  44. package/lib/markdown/createResponseSchema.js +20 -0
  45. package/lib/markdown/createSchema.d.ts +9 -0
  46. package/lib/markdown/createSchema.js +668 -0
  47. package/lib/markdown/createSchema.test.d.ts +1 -0
  48. package/lib/markdown/createSchema.test.js +913 -0
  49. package/lib/markdown/createStatusCodes.d.ts +9 -0
  50. package/lib/markdown/createStatusCodes.js +63 -0
  51. package/lib/markdown/createTermsOfService.d.ts +1 -0
  52. package/lib/markdown/createTermsOfService.js +31 -0
  53. package/lib/markdown/createVendorExtensions.d.ts +1 -0
  54. package/lib/markdown/createVendorExtensions.js +24 -0
  55. package/lib/markdown/createVersionBadge.d.ts +1 -0
  56. package/lib/markdown/createVersionBadge.js +19 -0
  57. package/lib/markdown/index.d.ts +5 -0
  58. package/lib/markdown/index.js +92 -0
  59. package/lib/markdown/schema.d.ts +3 -0
  60. package/lib/markdown/schema.js +154 -0
  61. package/lib/markdown/schema.test.d.ts +1 -0
  62. package/lib/markdown/schema.test.js +181 -0
  63. package/lib/markdown/utils.d.ts +20 -0
  64. package/lib/markdown/utils.js +68 -0
  65. package/lib/openapi/createRequestExample.d.ts +2 -0
  66. package/lib/openapi/createRequestExample.js +191 -0
  67. package/lib/openapi/createResponseExample.d.ts +2 -0
  68. package/lib/openapi/createResponseExample.js +192 -0
  69. package/lib/openapi/index.d.ts +1 -0
  70. package/lib/openapi/index.js +12 -0
  71. package/lib/openapi/openapi.d.ts +12 -0
  72. package/lib/openapi/openapi.js +544 -0
  73. package/lib/openapi/openapi.test.d.ts +1 -0
  74. package/lib/openapi/openapi.test.js +33 -0
  75. package/lib/openapi/types.d.ts +354 -0
  76. package/lib/openapi/types.js +8 -0
  77. package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
  78. package/lib/openapi/utils/loadAndResolveSpec.js +153 -0
  79. package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
  80. package/lib/openapi/utils/services/OpenAPIParser.js +343 -0
  81. package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
  82. package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
  83. package/lib/openapi/utils/types/index.d.ts +2 -0
  84. package/lib/openapi/utils/types/index.js +23 -0
  85. package/lib/openapi/utils/types/open-api.d.ts +305 -0
  86. package/lib/openapi/utils/types/open-api.js +8 -0
  87. package/lib/openapi/utils/types.d.ts +306 -0
  88. package/lib/openapi/utils/types.js +8 -0
  89. package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
  90. package/lib/openapi/utils/utils/JsonPointer.js +95 -0
  91. package/lib/openapi/utils/utils/helpers.d.ts +43 -0
  92. package/lib/openapi/utils/utils/helpers.js +230 -0
  93. package/lib/openapi/utils/utils/index.d.ts +3 -0
  94. package/lib/openapi/utils/utils/index.js +25 -0
  95. package/lib/openapi/utils/utils/openapi.d.ts +40 -0
  96. package/lib/openapi/utils/utils/openapi.js +605 -0
  97. package/lib/options.d.ts +2 -0
  98. package/lib/options.js +69 -0
  99. package/lib/sidebars/index.d.ts +4 -0
  100. package/lib/sidebars/index.js +226 -0
  101. package/lib/sidebars/utils.d.ts +2 -0
  102. package/lib/sidebars/utils.js +30 -0
  103. package/lib/types.d.ts +135 -0
  104. package/lib/types.js +8 -0
  105. package/package.json +69 -0
  106. package/src/index.ts +945 -0
  107. package/src/markdown/__snapshots__/createSchema.test.ts.snap +1605 -0
  108. package/src/markdown/createArrayBracket.ts +35 -0
  109. package/src/markdown/createAuthentication.ts +201 -0
  110. package/src/markdown/createAuthorization.ts +13 -0
  111. package/src/markdown/createCallbackMethodEndpoint.ts +19 -0
  112. package/src/markdown/createCallbacks.ts +101 -0
  113. package/src/markdown/createContactInfo.ts +41 -0
  114. package/src/markdown/createDeprecationNotice.ts +31 -0
  115. package/src/markdown/createDescription.ts +12 -0
  116. package/src/markdown/createDetails.ts +16 -0
  117. package/src/markdown/createDetailsSummary.ts +16 -0
  118. package/src/markdown/createDownload.ts +15 -0
  119. package/src/markdown/createHeading.ts +23 -0
  120. package/src/markdown/createLicense.ts +34 -0
  121. package/src/markdown/createLogo.ts +21 -0
  122. package/src/markdown/createMethodEndpoint.ts +19 -0
  123. package/src/markdown/createParamsDetails.ts +22 -0
  124. package/src/markdown/createRequestBodyDetails.ts +24 -0
  125. package/src/markdown/createRequestHeader.ts +24 -0
  126. package/src/markdown/createRequestSchema.ts +32 -0
  127. package/src/markdown/createResponseSchema.ts +32 -0
  128. package/src/markdown/createSchema.test.ts +1075 -0
  129. package/src/markdown/createSchema.ts +862 -0
  130. package/src/markdown/createStatusCodes.ts +63 -0
  131. package/src/markdown/createTermsOfService.ts +30 -0
  132. package/src/markdown/createVendorExtensions.ts +22 -0
  133. package/src/markdown/createVersionBadge.ts +22 -0
  134. package/src/markdown/index.ts +144 -0
  135. package/src/markdown/schema.test.ts +208 -0
  136. package/src/markdown/schema.ts +185 -0
  137. package/src/markdown/utils.ts +89 -0
  138. package/src/openapi/__fixtures__/examples/openapi.yaml +49 -0
  139. package/src/openapi/createRequestExample.ts +235 -0
  140. package/src/openapi/createResponseExample.ts +238 -0
  141. package/src/openapi/index.ts +8 -0
  142. package/src/openapi/openapi.test.ts +40 -0
  143. package/src/openapi/openapi.ts +697 -0
  144. package/src/openapi/types.ts +455 -0
  145. package/src/openapi/utils/loadAndResolveSpec.ts +171 -0
  146. package/src/openapi/utils/services/OpenAPIParser.ts +434 -0
  147. package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
  148. package/src/openapi/utils/types/index.ts +10 -0
  149. package/src/openapi/utils/types/open-api.ts +303 -0
  150. package/src/openapi/utils/types.ts +303 -0
  151. package/src/openapi/utils/utils/JsonPointer.ts +99 -0
  152. package/src/openapi/utils/utils/helpers.ts +239 -0
  153. package/src/openapi/utils/utils/index.ts +11 -0
  154. package/src/openapi/utils/utils/openapi.ts +771 -0
  155. package/src/openapi-to-postmanv2.d.ts +10 -0
  156. package/src/options.ts +77 -0
  157. package/src/plugin-content-docs-types.d.ts +42 -0
  158. package/src/plugin-openapi.d.ts +87 -0
  159. package/src/postman-collection.d.ts +10 -0
  160. package/src/sidebars/index.ts +322 -0
  161. package/src/sidebars/utils.ts +29 -0
  162. package/src/types.ts +176 -0
  163. package/tsconfig.json +7 -0
@@ -0,0 +1,605 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.shortenHTTPVerb = exports.SECURITY_SCHEMES_SECTION_PREFIX = exports.SCHEMA_DEFINITION_JSX_NAME = exports.SECURITY_DEFINITIONS_JSX_NAME = void 0;
10
+ exports.isStatusCode = isStatusCode;
11
+ exports.getStatusCodeType = getStatusCodeType;
12
+ exports.isOperationName = isOperationName;
13
+ exports.getOperationSummary = getOperationSummary;
14
+ exports.detectType = detectType;
15
+ exports.isPrimitiveType = isPrimitiveType;
16
+ exports.isJsonLike = isJsonLike;
17
+ exports.isFormUrlEncoded = isFormUrlEncoded;
18
+ exports.urlFormEncodePayload = urlFormEncodePayload;
19
+ exports.serializeParameterValueWithMime = serializeParameterValueWithMime;
20
+ exports.serializeParameterValue = serializeParameterValue;
21
+ exports.getSerializedValue = getSerializedValue;
22
+ exports.langFromMime = langFromMime;
23
+ exports.isNamedDefinition = isNamedDefinition;
24
+ exports.getDefinitionName = getDefinitionName;
25
+ exports.humanizeNumberRange = humanizeNumberRange;
26
+ exports.humanizeConstraints = humanizeConstraints;
27
+ exports.sortByRequired = sortByRequired;
28
+ exports.sortByField = sortByField;
29
+ exports.mergeParams = mergeParams;
30
+ exports.mergeSimilarMediaTypes = mergeSimilarMediaTypes;
31
+ exports.expandDefaultServerVariables = expandDefaultServerVariables;
32
+ exports.normalizeServers = normalizeServers;
33
+ exports.setSecuritySchemePrefix = setSecuritySchemePrefix;
34
+ exports.isRedocExtension = isRedocExtension;
35
+ exports.extractExtensions = extractExtensions;
36
+ exports.pluralizeType = pluralizeType;
37
+ exports.getContentWithLegacyExamples = getContentWithLegacyExamples;
38
+ // @ts-nocheck
39
+ const path_1 = require("path");
40
+ const helpers_1 = require("./helpers");
41
+ function isWildcardStatusCode(statusCode) {
42
+ return typeof statusCode === "string" && /\dxx/i.test(statusCode);
43
+ }
44
+ function isStatusCode(statusCode) {
45
+ return (statusCode === "default" ||
46
+ (0, helpers_1.isNumeric)(statusCode) ||
47
+ isWildcardStatusCode(statusCode));
48
+ }
49
+ function getStatusCodeType(statusCode, defaultAsError = false) {
50
+ if (statusCode === "default") {
51
+ return defaultAsError ? "error" : "success";
52
+ }
53
+ let code = typeof statusCode === "string" ? parseInt(statusCode, 10) : statusCode;
54
+ if (isWildcardStatusCode(statusCode)) {
55
+ code *= 100; // parseInt('2xx') parses to 2
56
+ }
57
+ if (code < 100 || code > 599) {
58
+ throw new Error("invalid HTTP code");
59
+ }
60
+ let res = "success";
61
+ if (code >= 300 && code < 400) {
62
+ res = "redirect";
63
+ }
64
+ else if (code >= 400) {
65
+ res = "error";
66
+ }
67
+ else if (code < 200) {
68
+ res = "info";
69
+ }
70
+ return res;
71
+ }
72
+ const operationNames = {
73
+ get: true,
74
+ post: true,
75
+ put: true,
76
+ head: true,
77
+ patch: true,
78
+ delete: true,
79
+ options: true,
80
+ $ref: true,
81
+ };
82
+ function isOperationName(key) {
83
+ return key in operationNames;
84
+ }
85
+ function getOperationSummary(operation) {
86
+ return (operation.summary ||
87
+ operation.operationId ||
88
+ (operation.description && operation.description.substring(0, 50)) ||
89
+ operation.pathName ||
90
+ "<no summary>");
91
+ }
92
+ const schemaKeywordTypes = {
93
+ multipleOf: "number",
94
+ maximum: "number",
95
+ exclusiveMaximum: "number",
96
+ minimum: "number",
97
+ exclusiveMinimum: "number",
98
+ maxLength: "string",
99
+ minLength: "string",
100
+ pattern: "string",
101
+ contentEncoding: "string",
102
+ contentMediaType: "string",
103
+ items: "array",
104
+ maxItems: "array",
105
+ minItems: "array",
106
+ uniqueItems: "array",
107
+ maxProperties: "object",
108
+ minProperties: "object",
109
+ required: "object",
110
+ additionalProperties: "object",
111
+ unevaluatedProperties: "object",
112
+ properties: "object",
113
+ patternProperties: "object",
114
+ };
115
+ function detectType(schema) {
116
+ if (schema.type !== undefined && !(0, helpers_1.isArray)(schema.type)) {
117
+ return schema.type;
118
+ }
119
+ const keywords = Object.keys(schemaKeywordTypes);
120
+ for (const keyword of keywords) {
121
+ const type = schemaKeywordTypes[keyword];
122
+ if (schema[keyword] !== undefined) {
123
+ return type;
124
+ }
125
+ }
126
+ return "any";
127
+ }
128
+ function isPrimitiveType(schema, type = schema.type) {
129
+ if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
130
+ return false;
131
+ }
132
+ if ((schema.if && schema.then) || (schema.if && schema.else)) {
133
+ return false;
134
+ }
135
+ let isPrimitive = true;
136
+ const isArrayType = (0, helpers_1.isArray)(type);
137
+ if (type === "object" || (isArrayType && (type === null || type === void 0 ? void 0 : type.includes("object")))) {
138
+ isPrimitive =
139
+ schema.properties !== undefined
140
+ ? Object.keys(schema.properties).length === 0
141
+ : schema.additionalProperties === undefined &&
142
+ schema.unevaluatedProperties === undefined;
143
+ }
144
+ if ((0, helpers_1.isArray)(schema.items) || (0, helpers_1.isArray)(schema.prefixItems)) {
145
+ return false;
146
+ }
147
+ if (schema.items !== undefined &&
148
+ !(0, helpers_1.isBoolean)(schema.items) &&
149
+ (type === "array" || (isArrayType && (type === null || type === void 0 ? void 0 : type.includes("array"))))) {
150
+ isPrimitive = isPrimitiveType(schema.items, schema.items.type);
151
+ }
152
+ return isPrimitive;
153
+ }
154
+ function isJsonLike(contentType) {
155
+ return contentType.search(/json/i) !== -1;
156
+ }
157
+ function isFormUrlEncoded(contentType) {
158
+ return contentType === "application/x-www-form-urlencoded";
159
+ }
160
+ function delimitedEncodeField(fieldVal, fieldName, delimiter) {
161
+ if ((0, helpers_1.isArray)(fieldVal)) {
162
+ return fieldVal.map((v) => v.toString()).join(delimiter);
163
+ }
164
+ else if (typeof fieldVal === "object") {
165
+ return Object.keys(fieldVal)
166
+ .map((k) => `${k}${delimiter}${fieldVal[k]}`)
167
+ .join(delimiter);
168
+ }
169
+ else {
170
+ return fieldName + "=" + fieldVal.toString();
171
+ }
172
+ }
173
+ function deepObjectEncodeField(fieldVal, fieldName) {
174
+ if ((0, helpers_1.isArray)(fieldVal)) {
175
+ console.warn("deepObject style cannot be used with array value:" + fieldVal.toString());
176
+ return "";
177
+ }
178
+ else if (typeof fieldVal === "object") {
179
+ return Object.keys(fieldVal)
180
+ .map((k) => `${fieldName}[${k}]=${fieldVal[k]}`)
181
+ .join("&");
182
+ }
183
+ else {
184
+ console.warn("deepObject style cannot be used with non-object value:" +
185
+ fieldVal.toString());
186
+ return "";
187
+ }
188
+ }
189
+ function serializeFormValue(name, explode, value) {
190
+ // Use RFC6570 safe name ([a-zA-Z0-9_]) and replace with our name later
191
+ // e.g. URI.template doesn't parse names with hyphen (-) which are valid query param names
192
+ const safeName = "__redoc_param_name__";
193
+ const suffix = explode ? "*" : "";
194
+ const template = `{?${safeName}${suffix}}`;
195
+ return template
196
+ .expand({ [safeName]: value })
197
+ .substring(1)
198
+ .replace(/__redoc_param_name__/g, name);
199
+ }
200
+ /*
201
+ * Should be used only for url-form-encoded body payloads
202
+ * To be used for parameters should be extended with other style values
203
+ */
204
+ function urlFormEncodePayload(payload, encoding = {}) {
205
+ if ((0, helpers_1.isArray)(payload)) {
206
+ throw new Error("Payload must have fields: " + payload.toString());
207
+ }
208
+ else {
209
+ return Object.keys(payload)
210
+ .map((fieldName) => {
211
+ const fieldVal = payload[fieldName];
212
+ const { style = "form", explode = true } = encoding[fieldName] || {};
213
+ switch (style) {
214
+ case "form":
215
+ return serializeFormValue(fieldName, explode, fieldVal);
216
+ case "spaceDelimited":
217
+ return delimitedEncodeField(fieldVal, fieldName, "%20");
218
+ case "pipeDelimited":
219
+ return delimitedEncodeField(fieldVal, fieldName, "|");
220
+ case "deepObject":
221
+ return deepObjectEncodeField(fieldVal, fieldName);
222
+ default:
223
+ // TODO implement rest of styles for path parameters
224
+ console.warn("Incorrect or unsupported encoding style: " + style);
225
+ return "";
226
+ }
227
+ })
228
+ .join("&");
229
+ }
230
+ }
231
+ function serializePathParameter(name, style, explode, value) {
232
+ const suffix = explode ? "*" : "";
233
+ let prefix = "";
234
+ if (style === "label") {
235
+ prefix = ".";
236
+ }
237
+ else if (style === "matrix") {
238
+ prefix = ";";
239
+ }
240
+ // Use RFC6570 safe name ([a-zA-Z0-9_]) and replace with our name later
241
+ // e.g. URI.template doesn't parse names with hyphen (-) which are valid query param names
242
+ const safeName = "__redoc_param_name__";
243
+ const template = `{${prefix}${safeName}${suffix}}`;
244
+ return template
245
+ .expand({ [safeName]: value })
246
+ .replace(/__redoc_param_name__/g, name);
247
+ }
248
+ function serializeQueryParameter(name, style, explode, value) {
249
+ switch (style) {
250
+ case "form":
251
+ return serializeFormValue(name, explode, value);
252
+ case "spaceDelimited":
253
+ if (!(0, helpers_1.isArray)(value)) {
254
+ console.warn("The style spaceDelimited is only applicable to arrays");
255
+ return "";
256
+ }
257
+ if (explode) {
258
+ return serializeFormValue(name, explode, value);
259
+ }
260
+ return `${name}=${value.join("%20")}`;
261
+ case "pipeDelimited":
262
+ if (!(0, helpers_1.isArray)(value)) {
263
+ console.warn("The style pipeDelimited is only applicable to arrays");
264
+ return "";
265
+ }
266
+ if (explode) {
267
+ return serializeFormValue(name, explode, value);
268
+ }
269
+ return `${name}=${value.join("|")}`;
270
+ case "deepObject":
271
+ if (!explode || (0, helpers_1.isArray)(value) || typeof value !== "object") {
272
+ console.warn("The style deepObject is only applicable for objects with explode=true");
273
+ return "";
274
+ }
275
+ return deepObjectEncodeField(value, name);
276
+ default:
277
+ console.warn("Unexpected style for query: " + style);
278
+ return "";
279
+ }
280
+ }
281
+ function serializeHeaderParameter(style, explode, value) {
282
+ switch (style) {
283
+ case "simple":
284
+ const suffix = explode ? "*" : "";
285
+ // name is not important here, so use RFC6570 safe name ([a-zA-Z0-9_])
286
+ const name = "__redoc_param_name__";
287
+ const template = `{${name}${suffix}}`;
288
+ return decodeURIComponent(template.expand({ [name]: value }));
289
+ default:
290
+ console.warn("Unexpected style for header: " + style);
291
+ return "";
292
+ }
293
+ }
294
+ function serializeCookieParameter(name, style, explode, value) {
295
+ switch (style) {
296
+ case "form":
297
+ return serializeFormValue(name, explode, value);
298
+ default:
299
+ console.warn("Unexpected style for cookie: " + style);
300
+ return "";
301
+ }
302
+ }
303
+ function serializeParameterValueWithMime(value, mime) {
304
+ if (isJsonLike(mime)) {
305
+ return JSON.stringify(value);
306
+ }
307
+ else {
308
+ console.warn(`Parameter serialization as ${mime} is not supported`);
309
+ return "";
310
+ }
311
+ }
312
+ function serializeParameterValue(parameter, value) {
313
+ const { name, style, explode = false, serializationMime } = parameter;
314
+ if (serializationMime) {
315
+ switch (parameter.in) {
316
+ case "path":
317
+ case "header":
318
+ return serializeParameterValueWithMime(value, serializationMime);
319
+ case "cookie":
320
+ case "query":
321
+ return `${name}=${serializeParameterValueWithMime(value, serializationMime)}`;
322
+ default:
323
+ console.warn("Unexpected parameter location: " + parameter.in);
324
+ return "";
325
+ }
326
+ }
327
+ if (!style) {
328
+ console.warn(`Missing style attribute or content for parameter ${name}`);
329
+ return "";
330
+ }
331
+ switch (parameter.in) {
332
+ case "path":
333
+ return serializePathParameter(name, style, explode, value);
334
+ case "query":
335
+ return serializeQueryParameter(name, style, explode, value);
336
+ case "header":
337
+ return serializeHeaderParameter(style, explode, value);
338
+ case "cookie":
339
+ return serializeCookieParameter(name, style, explode, value);
340
+ default:
341
+ console.warn("Unexpected parameter location: " + parameter.in);
342
+ return "";
343
+ }
344
+ }
345
+ function getSerializedValue(field, example) {
346
+ if (field.in) {
347
+ // decode for better readability in examples: see https://github.com/Redocly/redoc/issues/1138
348
+ return decodeURIComponent(serializeParameterValue(field, example));
349
+ }
350
+ else {
351
+ return example;
352
+ }
353
+ }
354
+ function langFromMime(contentType) {
355
+ if (contentType.search(/xml/i) !== -1) {
356
+ return "xml";
357
+ }
358
+ return "clike";
359
+ }
360
+ const DEFINITION_NAME_REGEX = /^#\/components\/(schemas|pathItems)\/([^/]+)$/;
361
+ function isNamedDefinition(pointer) {
362
+ return DEFINITION_NAME_REGEX.test(pointer || "");
363
+ }
364
+ function getDefinitionName(pointer) {
365
+ var _a;
366
+ const [name] = ((_a = pointer === null || pointer === void 0 ? void 0 : pointer.match(DEFINITION_NAME_REGEX)) === null || _a === void 0 ? void 0 : _a.reverse()) || [];
367
+ return name;
368
+ }
369
+ function humanizeMultipleOfConstraint(multipleOf) {
370
+ if (multipleOf === undefined) {
371
+ return;
372
+ }
373
+ const strigifiedMultipleOf = multipleOf.toString(10);
374
+ if (!/^0\.0*1$/.test(strigifiedMultipleOf)) {
375
+ return `multiple of ${strigifiedMultipleOf}`;
376
+ }
377
+ return `decimal places <= ${strigifiedMultipleOf.split(".")[1].length}`;
378
+ }
379
+ function humanizeRangeConstraint(description, min, max) {
380
+ let stringRange;
381
+ if (min !== undefined && max !== undefined) {
382
+ if (min === max) {
383
+ stringRange = `= ${min} ${description}`;
384
+ }
385
+ else {
386
+ stringRange = `[ ${min} .. ${max} ] ${description}`;
387
+ }
388
+ }
389
+ else if (max !== undefined) {
390
+ stringRange = `<= ${max} ${description}`;
391
+ }
392
+ else if (min !== undefined) {
393
+ if (min === 1) {
394
+ stringRange = "non-empty";
395
+ }
396
+ else {
397
+ stringRange = `>= ${min} ${description}`;
398
+ }
399
+ }
400
+ return stringRange;
401
+ }
402
+ function humanizeNumberRange(schema) {
403
+ var _a, _b;
404
+ const minimum = typeof schema.exclusiveMinimum === "number"
405
+ ? Math.min(schema.exclusiveMinimum, (_a = schema.minimum) !== null && _a !== void 0 ? _a : Infinity)
406
+ : schema.minimum;
407
+ const maximum = typeof schema.exclusiveMaximum === "number"
408
+ ? Math.max(schema.exclusiveMaximum, (_b = schema.maximum) !== null && _b !== void 0 ? _b : -Infinity)
409
+ : schema.maximum;
410
+ const exclusiveMinimum = typeof schema.exclusiveMinimum === "number" || schema.exclusiveMinimum;
411
+ const exclusiveMaximum = typeof schema.exclusiveMaximum === "number" || schema.exclusiveMaximum;
412
+ if (minimum !== undefined && maximum !== undefined) {
413
+ return `${exclusiveMinimum ? "( " : "[ "}${minimum} .. ${maximum}${exclusiveMaximum ? " )" : " ]"}`;
414
+ }
415
+ else if (maximum !== undefined) {
416
+ return `${exclusiveMaximum ? "< " : "<= "}${maximum}`;
417
+ }
418
+ else if (minimum !== undefined) {
419
+ return `${exclusiveMinimum ? "> " : ">= "}${minimum}`;
420
+ }
421
+ }
422
+ function humanizeConstraints(schema) {
423
+ const res = [];
424
+ const stringRange = humanizeRangeConstraint("characters", schema.minLength, schema.maxLength);
425
+ if (stringRange !== undefined) {
426
+ res.push(stringRange);
427
+ }
428
+ const arrayRange = humanizeRangeConstraint("items", schema.minItems, schema.maxItems);
429
+ if (arrayRange !== undefined) {
430
+ res.push(arrayRange);
431
+ }
432
+ const propertiesRange = humanizeRangeConstraint("properties", schema.minProperties, schema.maxProperties);
433
+ if (propertiesRange !== undefined) {
434
+ res.push(propertiesRange);
435
+ }
436
+ const multipleOfConstraint = humanizeMultipleOfConstraint(schema.multipleOf);
437
+ if (multipleOfConstraint !== undefined) {
438
+ res.push(multipleOfConstraint);
439
+ }
440
+ const numberRange = humanizeNumberRange(schema);
441
+ if (numberRange !== undefined) {
442
+ res.push(numberRange);
443
+ }
444
+ if (schema.uniqueItems) {
445
+ res.push("unique");
446
+ }
447
+ return res;
448
+ }
449
+ function sortByRequired(fields, order = []) {
450
+ const unrequiredFields = [];
451
+ const orderedFields = [];
452
+ const unorderedFields = [];
453
+ fields.forEach((field) => {
454
+ if (field.required) {
455
+ order.includes(field.name)
456
+ ? orderedFields.push(field)
457
+ : unorderedFields.push(field);
458
+ }
459
+ else {
460
+ unrequiredFields.push(field);
461
+ }
462
+ });
463
+ orderedFields.sort((a, b) => order.indexOf(a.name) - order.indexOf(b.name));
464
+ return [...orderedFields, ...unorderedFields, ...unrequiredFields];
465
+ }
466
+ function sortByField(fields, param) {
467
+ return [...fields].sort((a, b) => {
468
+ return a[param].localeCompare(b[param]);
469
+ });
470
+ }
471
+ function mergeParams(parser, pathParams = [], operationParams = []) {
472
+ const operationParamNames = {};
473
+ operationParams.forEach((param) => {
474
+ param = parser.shallowDeref(param);
475
+ operationParamNames[param.name + "_" + param.in] = true;
476
+ });
477
+ // filter out path params overridden by operation ones with the same name
478
+ pathParams = pathParams.filter((param) => {
479
+ param = parser.shallowDeref(param);
480
+ return !operationParamNames[param.name + "_" + param.in];
481
+ });
482
+ return pathParams.concat(operationParams);
483
+ }
484
+ function mergeSimilarMediaTypes(types) {
485
+ const mergedTypes = {};
486
+ Object.keys(types).forEach((name) => {
487
+ const mime = types[name];
488
+ // ignore content type parameters (e.g. charset) and merge
489
+ const normalizedMimeName = name.split(";")[0].trim();
490
+ if (!mergedTypes[normalizedMimeName]) {
491
+ mergedTypes[normalizedMimeName] = mime;
492
+ return;
493
+ }
494
+ mergedTypes[normalizedMimeName] = {
495
+ ...mergedTypes[normalizedMimeName],
496
+ ...mime,
497
+ };
498
+ });
499
+ return mergedTypes;
500
+ }
501
+ function expandDefaultServerVariables(url, variables = {}) {
502
+ return url.replace(/(?:{)([\w-.]+)(?:})/g, (match, name) => (variables[name] && variables[name].default) || match);
503
+ }
504
+ function normalizeServers(specUrl, servers) {
505
+ const getHref = () => {
506
+ if (!false) {
507
+ return "";
508
+ }
509
+ const href = window.location.href;
510
+ return href.endsWith(".html") ? (0, path_1.dirname)(href) : href;
511
+ };
512
+ const baseUrl = specUrl === undefined ? (0, helpers_1.removeQueryString)(getHref()) : (0, path_1.dirname)(specUrl);
513
+ if (servers.length === 0) {
514
+ // Behaviour defined in OpenAPI spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#openapi-object
515
+ servers = [
516
+ {
517
+ url: "/",
518
+ },
519
+ ];
520
+ }
521
+ function normalizeUrl(url) {
522
+ return (0, helpers_1.resolveUrl)(baseUrl, url);
523
+ }
524
+ return servers.map((server) => {
525
+ return {
526
+ ...server,
527
+ url: normalizeUrl(server.url),
528
+ description: server.description || "",
529
+ };
530
+ });
531
+ }
532
+ exports.SECURITY_DEFINITIONS_JSX_NAME = "SecurityDefinitions";
533
+ exports.SCHEMA_DEFINITION_JSX_NAME = "SchemaDefinition";
534
+ exports.SECURITY_SCHEMES_SECTION_PREFIX = "section/Authentication/";
535
+ function setSecuritySchemePrefix(prefix) {
536
+ exports.SECURITY_SCHEMES_SECTION_PREFIX = prefix;
537
+ }
538
+ const shortenHTTPVerb = (verb) => ({
539
+ delete: "del",
540
+ options: "opts",
541
+ })[verb] || verb;
542
+ exports.shortenHTTPVerb = shortenHTTPVerb;
543
+ function isRedocExtension(key) {
544
+ const redocExtensions = {
545
+ "x-circular-ref": true,
546
+ "x-code-samples": true, // deprecated
547
+ "x-codeSamples": true,
548
+ "x-displayName": true,
549
+ "x-examples": true,
550
+ "x-ignoredHeaderParameters": true,
551
+ "x-logo": true,
552
+ "x-nullable": true,
553
+ "x-servers": true,
554
+ "x-tagGroups": true,
555
+ "x-traitTag": true,
556
+ "x-additionalPropertiesName": true,
557
+ "x-explicitMappingOnly": true,
558
+ };
559
+ return key in redocExtensions;
560
+ }
561
+ function extractExtensions(obj, showExtensions) {
562
+ return Object.keys(obj)
563
+ .filter((key) => {
564
+ if (showExtensions === true) {
565
+ return key.startsWith("x-") && !isRedocExtension(key);
566
+ }
567
+ return key.startsWith("x-") && showExtensions.indexOf(key) > -1;
568
+ })
569
+ .reduce((acc, key) => {
570
+ acc[key] = obj[key];
571
+ return acc;
572
+ }, {});
573
+ }
574
+ function pluralizeType(displayType) {
575
+ return displayType
576
+ .split(" or ")
577
+ .map((type) => type.replace(/^(string|object|number|integer|array|boolean)s?( ?.*)/, "$1s$2"))
578
+ .join(" or ");
579
+ }
580
+ function getContentWithLegacyExamples(info) {
581
+ let mediaContent = info.content;
582
+ const xExamples = info["x-examples"]; // converted from OAS2 body param
583
+ const xExample = info["x-example"]; // converted from OAS2 body param
584
+ if (xExamples) {
585
+ mediaContent = { ...mediaContent };
586
+ for (const mime of Object.keys(xExamples)) {
587
+ const examples = xExamples[mime];
588
+ mediaContent[mime] = {
589
+ ...mediaContent[mime],
590
+ examples,
591
+ };
592
+ }
593
+ }
594
+ else if (xExample) {
595
+ mediaContent = { ...mediaContent };
596
+ for (const mime of Object.keys(xExample)) {
597
+ const example = xExample[mime];
598
+ mediaContent[mime] = {
599
+ ...mediaContent[mime],
600
+ example,
601
+ };
602
+ }
603
+ }
604
+ return mediaContent;
605
+ }
@@ -0,0 +1,2 @@
1
+ import { Joi } from "@docusaurus/utils-validation";
2
+ export declare const OptionsSchema: Joi.ObjectSchema<any>;
package/lib/options.js ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.OptionsSchema = void 0;
10
+ const utils_validation_1 = require("@docusaurus/utils-validation");
11
+ const sidebarGenerators = utils_validation_1.Joi.object({
12
+ createDocItem: utils_validation_1.Joi.function(),
13
+ });
14
+ const sidebarOptions = utils_validation_1.Joi.object({
15
+ groupPathsBy: utils_validation_1.Joi.string().valid("tag", "tagGroup"),
16
+ categoryLinkSource: utils_validation_1.Joi.string().valid("tag", "info", "auto"),
17
+ customProps: utils_validation_1.Joi.object(),
18
+ sidebarCollapsible: utils_validation_1.Joi.boolean(),
19
+ sidebarCollapsed: utils_validation_1.Joi.boolean(),
20
+ sidebarGenerators: sidebarGenerators,
21
+ });
22
+ const markdownGenerators = utils_validation_1.Joi.object({
23
+ createApiPageMD: utils_validation_1.Joi.function(),
24
+ createInfoPageMD: utils_validation_1.Joi.function(),
25
+ createTagPageMD: utils_validation_1.Joi.function(),
26
+ createSchemaPageMD: utils_validation_1.Joi.function(),
27
+ });
28
+ exports.OptionsSchema = utils_validation_1.Joi.object({
29
+ id: utils_validation_1.Joi.string().required(),
30
+ docsPlugin: utils_validation_1.Joi.string(),
31
+ docsPluginId: utils_validation_1.Joi.string().required(),
32
+ config: utils_validation_1.Joi.object()
33
+ .pattern(/^/, utils_validation_1.Joi.object({
34
+ specPath: utils_validation_1.Joi.string().required(),
35
+ proxy: utils_validation_1.Joi.string(),
36
+ outputDir: utils_validation_1.Joi.string().required(),
37
+ template: utils_validation_1.Joi.string(),
38
+ infoTemplate: utils_validation_1.Joi.string(),
39
+ tagTemplate: utils_validation_1.Joi.string(),
40
+ schemaTemplate: utils_validation_1.Joi.string(),
41
+ downloadUrl: utils_validation_1.Joi.string(),
42
+ hideSendButton: utils_validation_1.Joi.boolean(),
43
+ showExtensions: utils_validation_1.Joi.boolean(),
44
+ sidebarOptions: sidebarOptions,
45
+ markdownGenerators: markdownGenerators,
46
+ showSchemas: utils_validation_1.Joi.boolean(),
47
+ disableCompression: utils_validation_1.Joi.boolean(),
48
+ version: utils_validation_1.Joi.string().when("versions", {
49
+ is: utils_validation_1.Joi.exist(),
50
+ then: utils_validation_1.Joi.required(),
51
+ }),
52
+ label: utils_validation_1.Joi.string().when("versions", {
53
+ is: utils_validation_1.Joi.exist(),
54
+ then: utils_validation_1.Joi.required(),
55
+ }),
56
+ baseUrl: utils_validation_1.Joi.string().when("versions", {
57
+ is: utils_validation_1.Joi.exist(),
58
+ then: utils_validation_1.Joi.required(),
59
+ }),
60
+ versions: utils_validation_1.Joi.object().pattern(/^/, utils_validation_1.Joi.object({
61
+ specPath: utils_validation_1.Joi.string().required(),
62
+ outputDir: utils_validation_1.Joi.string().required(),
63
+ label: utils_validation_1.Joi.string().required(),
64
+ baseUrl: utils_validation_1.Joi.string().required(),
65
+ downloadUrl: utils_validation_1.Joi.string(),
66
+ })),
67
+ }))
68
+ .required(),
69
+ });
@@ -0,0 +1,4 @@
1
+ import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
2
+ import { TagGroupObject, TagObject } from "../openapi/types";
3
+ import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
4
+ export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[][], docPath: string, tagGroups?: TagGroupObject[]): ProcessedSidebar;