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