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,99 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import JsonPointerLib from "json-pointer";
|
|
9
|
+
|
|
10
|
+
const origParse = JsonPointerLib.parse;
|
|
11
|
+
/**
|
|
12
|
+
* Wrapper for JsonPointer. Provides common operations
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export class JsonPointer {
|
|
16
|
+
/**
|
|
17
|
+
* returns last JsonPointer token
|
|
18
|
+
* if level > 1 returns levels last (second last/third last)
|
|
19
|
+
* @example
|
|
20
|
+
* // returns subpath
|
|
21
|
+
* JsonPointerHelper.baseName('/path/0/subpath')
|
|
22
|
+
* // returns foo
|
|
23
|
+
* JsonPointerHelper.baseName('/path/foo/subpath', 2)
|
|
24
|
+
*/
|
|
25
|
+
static baseName(pointer: any, level = 1) {
|
|
26
|
+
const tokens = JsonPointer.parse(pointer);
|
|
27
|
+
return tokens[tokens.length - level];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* returns dirname of pointer
|
|
32
|
+
* if level > 1 returns corresponding dirname in the hierarchy
|
|
33
|
+
* @example
|
|
34
|
+
* // returns /path/0
|
|
35
|
+
* JsonPointerHelper.dirName('/path/0/subpath')
|
|
36
|
+
* // returns /path
|
|
37
|
+
* JsonPointerHelper.dirName('/path/foo/subpath', 2)
|
|
38
|
+
*/
|
|
39
|
+
static dirName(pointer: any, level = 1) {
|
|
40
|
+
const tokens = JsonPointer.parse(pointer);
|
|
41
|
+
return JsonPointerLib.compile(tokens.slice(0, tokens.length - level));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* returns relative path tokens
|
|
46
|
+
* @example
|
|
47
|
+
* // returns ['subpath']
|
|
48
|
+
* JsonPointerHelper.relative('/path/0', '/path/0/subpath')
|
|
49
|
+
* // returns ['foo', 'subpath']
|
|
50
|
+
* JsonPointerHelper.relative('/path', '/path/foo/subpath')
|
|
51
|
+
*/
|
|
52
|
+
static relative(from: any, to: any): string[] {
|
|
53
|
+
const fromTokens = JsonPointer.parse(from);
|
|
54
|
+
const toTokens = JsonPointer.parse(to);
|
|
55
|
+
return toTokens.slice(fromTokens.length);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* overridden JsonPointer original parse to take care of prefixing '#' symbol
|
|
60
|
+
* that is not valid JsonPointer
|
|
61
|
+
*/
|
|
62
|
+
static parse(pointer: any) {
|
|
63
|
+
let ptr = pointer;
|
|
64
|
+
if (ptr.charAt(0) === "#") {
|
|
65
|
+
ptr = ptr.substring(1);
|
|
66
|
+
}
|
|
67
|
+
return origParse(ptr);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates a JSON pointer path, by joining one or more tokens to a base path.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} base - The base path
|
|
74
|
+
* @param {string|string[]} tokens - The token(s) to append (e.g. ["name", "first"])
|
|
75
|
+
* @returns {string}
|
|
76
|
+
*/
|
|
77
|
+
static join(base: any, tokens: any) {
|
|
78
|
+
// TODO: optimize
|
|
79
|
+
const baseTokens = JsonPointer.parse(base);
|
|
80
|
+
const resTokens = baseTokens.concat(tokens);
|
|
81
|
+
return JsonPointerLib.compile(resTokens);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static get(object: object, pointer: string) {
|
|
85
|
+
return JsonPointerLib.get(object, pointer);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static compile(tokens: string[]) {
|
|
89
|
+
return JsonPointerLib.compile(tokens);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static escape(pointer: string) {
|
|
93
|
+
return JsonPointerLib.escape(pointer);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
JsonPointerLib.parse = JsonPointer.parse;
|
|
98
|
+
Object.assign(JsonPointer, JsonPointerLib);
|
|
99
|
+
export default JsonPointer;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
// @ts-nocheck
|
|
9
|
+
|
|
10
|
+
import slugify from "slugify";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Maps over array passing `isLast` bool to iterator as the second argument
|
|
14
|
+
*/
|
|
15
|
+
export function mapWithLast<T, P>(
|
|
16
|
+
array: T[],
|
|
17
|
+
iteratee: (item: T, isLast: boolean) => P
|
|
18
|
+
) {
|
|
19
|
+
const res: P[] = [];
|
|
20
|
+
for (let i = 0; i < array.length - 1; i++) {
|
|
21
|
+
res.push(iteratee(array[i], false));
|
|
22
|
+
}
|
|
23
|
+
if (array.length !== 0) {
|
|
24
|
+
res.push(iteratee(array[array.length - 1], true));
|
|
25
|
+
}
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates an object with the same keys as object and values generated by running each
|
|
31
|
+
* own enumerable string keyed property of object thru iteratee.
|
|
32
|
+
* The iteratee is invoked with three arguments: (value, key, object).
|
|
33
|
+
*
|
|
34
|
+
* @param object the object to iterate over
|
|
35
|
+
* @param iteratee the function invoked per iteration.
|
|
36
|
+
*/
|
|
37
|
+
export function mapValues<T, P>(
|
|
38
|
+
object: Record<string, T>,
|
|
39
|
+
iteratee: (val: T, key: string, obj: Record<string, T>) => P
|
|
40
|
+
): Record<string, P> {
|
|
41
|
+
const res: { [key: string]: P } = {};
|
|
42
|
+
for (const key in object) {
|
|
43
|
+
if (object.hasOwnProperty(key)) {
|
|
44
|
+
res[key] = iteratee(object[key], key, object);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* flattens collection using `prop` field as a children
|
|
52
|
+
* @param collectionItems collection items
|
|
53
|
+
* @param prop item property with child elements
|
|
54
|
+
*/
|
|
55
|
+
export function flattenByProp<T extends object, P extends keyof T>(
|
|
56
|
+
collectionItems: T[],
|
|
57
|
+
prop: P
|
|
58
|
+
): T[] {
|
|
59
|
+
const res: T[] = [];
|
|
60
|
+
const iterate = (items: T[]) => {
|
|
61
|
+
for (const item of items) {
|
|
62
|
+
res.push(item);
|
|
63
|
+
if (item[prop]) {
|
|
64
|
+
iterate(item[prop] as any as T[]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
iterate(collectionItems);
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function stripTrailingSlash(path: string): string {
|
|
73
|
+
if (path.endsWith("/")) {
|
|
74
|
+
return path.substring(0, path.length - 1);
|
|
75
|
+
}
|
|
76
|
+
return path;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function isNumeric(n: any): n is number {
|
|
80
|
+
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function appendToMdHeading(
|
|
84
|
+
md: string,
|
|
85
|
+
heading: string,
|
|
86
|
+
content: string
|
|
87
|
+
) {
|
|
88
|
+
// if heading is already in md and append to the end of it
|
|
89
|
+
const testRegex = new RegExp(`(^|\\n)#\\s?${heading}\\s*\\n`, "i");
|
|
90
|
+
const replaceRegex = new RegExp(
|
|
91
|
+
`((\\n|^)#\\s*${heading}\\s*(\\n|$)(?:.|\\n)*?)(\\n#|$)`,
|
|
92
|
+
"i"
|
|
93
|
+
);
|
|
94
|
+
if (testRegex.test(md)) {
|
|
95
|
+
return md.replace(replaceRegex, `$1\n\n${content}\n$4`);
|
|
96
|
+
} else {
|
|
97
|
+
// else append heading itself
|
|
98
|
+
const br =
|
|
99
|
+
md === "" || md.endsWith("\n\n") ? "" : md.endsWith("\n") ? "\n" : "\n\n";
|
|
100
|
+
return `${md}${br}# ${heading}\n\n${content}`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// credits https://stackoverflow.com/a/46973278/1749888
|
|
105
|
+
export const mergeObjects = (target: any, ...sources: any[]): any => {
|
|
106
|
+
if (!sources.length) {
|
|
107
|
+
return target;
|
|
108
|
+
}
|
|
109
|
+
const source = sources.shift();
|
|
110
|
+
if (source === undefined) {
|
|
111
|
+
return target;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (isMergebleObject(target) && isMergebleObject(source)) {
|
|
115
|
+
Object.keys(source).forEach((key: string) => {
|
|
116
|
+
if (isMergebleObject(source[key])) {
|
|
117
|
+
if (!target[key]) {
|
|
118
|
+
target[key] = {};
|
|
119
|
+
}
|
|
120
|
+
mergeObjects(target[key], source[key]);
|
|
121
|
+
} else {
|
|
122
|
+
target[key] = source[key];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return mergeObjects(target, ...sources);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const isObject = (item: unknown): item is Record<string, unknown> => {
|
|
131
|
+
return item !== null && typeof item === "object";
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const isMergebleObject = (item): boolean => {
|
|
135
|
+
return isObject(item) && !isArray(item);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* slugify() returns empty string when failed to slugify.
|
|
140
|
+
* so try to return minimum slugified-string with failed one which keeps original value
|
|
141
|
+
* the regex codes are referenced with https://gist.github.com/mathewbyrne/1280286
|
|
142
|
+
*/
|
|
143
|
+
export function safeSlugify(value: string): string {
|
|
144
|
+
return (
|
|
145
|
+
slugify(value) ||
|
|
146
|
+
value
|
|
147
|
+
.toString()
|
|
148
|
+
.toLowerCase()
|
|
149
|
+
.replace(/\s+/g, "-") // Replace spaces with -
|
|
150
|
+
.replace(/&/g, "-and-") // Replace & with 'and'
|
|
151
|
+
.replace(/--+/g, "-") // Replace multiple - with single -
|
|
152
|
+
.replace(/^-+/, "") // Trim - from start of text
|
|
153
|
+
.replace(/-+$/, "")
|
|
154
|
+
); // Trim - from end of text
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function isAbsoluteUrl(url: string) {
|
|
158
|
+
return /(?:^[a-z][a-z0-9+.-]*:|\/\/)/i.test(url);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* simple resolve URL which doesn't break on strings with url fragments
|
|
163
|
+
* e.g. resolveUrl('http://test.com:{port}', 'path') results in http://test.com:{port}/path
|
|
164
|
+
*/
|
|
165
|
+
export function resolveUrl(url: string, to: string) {
|
|
166
|
+
let res;
|
|
167
|
+
if (to.startsWith("//")) {
|
|
168
|
+
try {
|
|
169
|
+
res = `${new URL(url).protocol || "https:"}${to}`;
|
|
170
|
+
} catch {
|
|
171
|
+
res = `https:${to}`;
|
|
172
|
+
}
|
|
173
|
+
} else if (isAbsoluteUrl(to)) {
|
|
174
|
+
res = to;
|
|
175
|
+
} else if (!to.startsWith("/")) {
|
|
176
|
+
res = stripTrailingSlash(url) + "/" + to;
|
|
177
|
+
} else {
|
|
178
|
+
try {
|
|
179
|
+
const urlObj = new URL(url);
|
|
180
|
+
urlObj.pathname = to;
|
|
181
|
+
res = urlObj.href;
|
|
182
|
+
} catch {
|
|
183
|
+
res = to;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return stripTrailingSlash(res);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function getBasePath(serverUrl: string): string {
|
|
190
|
+
try {
|
|
191
|
+
return parseURL(serverUrl).pathname;
|
|
192
|
+
} catch (e) {
|
|
193
|
+
// when using with redoc-cli serverUrl can be empty resulting in crash
|
|
194
|
+
return serverUrl;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function titleize(text: string) {
|
|
199
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function removeQueryString(serverUrl: string): string {
|
|
203
|
+
try {
|
|
204
|
+
const url = parseURL(serverUrl);
|
|
205
|
+
url.search = "";
|
|
206
|
+
return url.toString();
|
|
207
|
+
} catch (e) {
|
|
208
|
+
// when using with redoc-cli serverUrl can be empty resulting in crash
|
|
209
|
+
return serverUrl;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function parseURL(url: string) {
|
|
214
|
+
if (typeof URL === "undefined") {
|
|
215
|
+
// node
|
|
216
|
+
return new (require("url").URL)(url);
|
|
217
|
+
} else {
|
|
218
|
+
return new URL(url);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function escapeHTMLAttrChars(str: string): string {
|
|
223
|
+
return str.replace(/["\\]/g, "\\$&");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function unescapeHTMLChars(str: string): string {
|
|
227
|
+
return str
|
|
228
|
+
.replace(/&#(\d+);/g, (_m, code) => String.fromCharCode(parseInt(code, 10)))
|
|
229
|
+
.replace(/&/g, "&")
|
|
230
|
+
.replace(/"/g, '"');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function isArray(value: unknown): value is any[] {
|
|
234
|
+
return Array.isArray(value);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function isBoolean(value: unknown): value is boolean {
|
|
238
|
+
return typeof value === "boolean";
|
|
239
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
export * from "./JsonPointer";
|
|
9
|
+
|
|
10
|
+
export * from "./openapi";
|
|
11
|
+
export * from "./helpers";
|