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.
Files changed (47) hide show
  1. package/README.md +1 -2
  2. package/lib/markdown/createSchemaDetails.js +325 -132
  3. package/lib/markdown/index.js +1 -0
  4. package/lib/markdown/schema.js +25 -9
  5. package/lib/markdown/utils.d.ts +1 -1
  6. package/lib/markdown/utils.js +4 -1
  7. package/lib/openapi/openapi.d.ts +3 -3
  8. package/lib/openapi/openapi.js +30 -26
  9. package/lib/openapi/types.d.ts +2 -1
  10. package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
  11. package/lib/openapi/utils/{loadAndBundleSpec.js → loadAndResolveSpec.js} +61 -28
  12. package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
  13. package/lib/openapi/utils/services/OpenAPIParser.js +342 -0
  14. package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
  15. package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
  16. package/lib/openapi/utils/types/index.d.ts +2 -0
  17. package/lib/openapi/utils/types/index.js +23 -0
  18. package/lib/openapi/utils/types/open-api.d.ts +305 -0
  19. package/lib/openapi/utils/types/open-api.js +8 -0
  20. package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
  21. package/lib/openapi/utils/utils/JsonPointer.js +95 -0
  22. package/lib/openapi/utils/utils/helpers.d.ts +43 -0
  23. package/lib/openapi/utils/utils/helpers.js +230 -0
  24. package/lib/openapi/utils/utils/index.d.ts +3 -0
  25. package/lib/openapi/utils/utils/index.js +25 -0
  26. package/lib/openapi/utils/utils/openapi.d.ts +40 -0
  27. package/lib/openapi/utils/utils/openapi.js +605 -0
  28. package/lib/sidebars/index.js +5 -3
  29. package/package.json +15 -11
  30. package/src/markdown/createSchemaDetails.ts +405 -159
  31. package/src/markdown/index.ts +1 -0
  32. package/src/markdown/schema.ts +28 -8
  33. package/src/markdown/utils.ts +5 -2
  34. package/src/openapi/openapi.ts +42 -38
  35. package/src/openapi/types.ts +2 -1
  36. package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
  37. package/src/openapi/utils/services/OpenAPIParser.ts +433 -0
  38. package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
  39. package/src/openapi/utils/types/index.ts +10 -0
  40. package/src/openapi/utils/types/open-api.ts +303 -0
  41. package/src/openapi/utils/utils/JsonPointer.ts +99 -0
  42. package/src/openapi/utils/utils/helpers.ts +239 -0
  43. package/src/openapi/utils/utils/index.ts +11 -0
  44. package/src/openapi/utils/utils/openapi.ts +771 -0
  45. package/src/sidebars/index.ts +7 -4
  46. package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
  47. package/src/openapi/utils/loadAndBundleSpec.ts +0 -93
@@ -0,0 +1,95 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.JsonPointer = void 0;
13
+ const json_pointer_1 = __importDefault(require("json-pointer"));
14
+ const origParse = json_pointer_1.default.parse;
15
+ /**
16
+ * Wrapper for JsonPointer. Provides common operations
17
+ */
18
+ class JsonPointer {
19
+ /**
20
+ * returns last JsonPointer token
21
+ * if level > 1 returns levels last (second last/third last)
22
+ * @example
23
+ * // returns subpath
24
+ * JsonPointerHelper.baseName('/path/0/subpath')
25
+ * // returns foo
26
+ * JsonPointerHelper.baseName('/path/foo/subpath', 2)
27
+ */
28
+ static baseName(pointer, level = 1) {
29
+ const tokens = JsonPointer.parse(pointer);
30
+ return tokens[tokens.length - level];
31
+ }
32
+ /**
33
+ * returns dirname of pointer
34
+ * if level > 1 returns corresponding dirname in the hierarchy
35
+ * @example
36
+ * // returns /path/0
37
+ * JsonPointerHelper.dirName('/path/0/subpath')
38
+ * // returns /path
39
+ * JsonPointerHelper.dirName('/path/foo/subpath', 2)
40
+ */
41
+ static dirName(pointer, level = 1) {
42
+ const tokens = JsonPointer.parse(pointer);
43
+ return json_pointer_1.default.compile(tokens.slice(0, tokens.length - level));
44
+ }
45
+ /**
46
+ * returns relative path tokens
47
+ * @example
48
+ * // returns ['subpath']
49
+ * JsonPointerHelper.relative('/path/0', '/path/0/subpath')
50
+ * // returns ['foo', 'subpath']
51
+ * JsonPointerHelper.relative('/path', '/path/foo/subpath')
52
+ */
53
+ static relative(from, to) {
54
+ const fromTokens = JsonPointer.parse(from);
55
+ const toTokens = JsonPointer.parse(to);
56
+ return toTokens.slice(fromTokens.length);
57
+ }
58
+ /**
59
+ * overridden JsonPointer original parse to take care of prefixing '#' symbol
60
+ * that is not valid JsonPointer
61
+ */
62
+ static parse(pointer) {
63
+ let ptr = pointer;
64
+ if (ptr.charAt(0) === "#") {
65
+ ptr = ptr.substring(1);
66
+ }
67
+ return origParse(ptr);
68
+ }
69
+ /**
70
+ * Creates a JSON pointer path, by joining one or more tokens to a base path.
71
+ *
72
+ * @param {string} base - The base path
73
+ * @param {string|string[]} tokens - The token(s) to append (e.g. ["name", "first"])
74
+ * @returns {string}
75
+ */
76
+ static join(base, tokens) {
77
+ // TODO: optimize
78
+ const baseTokens = JsonPointer.parse(base);
79
+ const resTokens = baseTokens.concat(tokens);
80
+ return json_pointer_1.default.compile(resTokens);
81
+ }
82
+ static get(object, pointer) {
83
+ return json_pointer_1.default.get(object, pointer);
84
+ }
85
+ static compile(tokens) {
86
+ return json_pointer_1.default.compile(tokens);
87
+ }
88
+ static escape(pointer) {
89
+ return json_pointer_1.default.escape(pointer);
90
+ }
91
+ }
92
+ exports.JsonPointer = JsonPointer;
93
+ json_pointer_1.default.parse = JsonPointer.parse;
94
+ Object.assign(JsonPointer, json_pointer_1.default);
95
+ exports.default = JsonPointer;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Maps over array passing `isLast` bool to iterator as the second argument
3
+ */
4
+ export declare function mapWithLast<T, P>(array: T[], iteratee: (item: T, isLast: boolean) => P): P[];
5
+ /**
6
+ * Creates an object with the same keys as object and values generated by running each
7
+ * own enumerable string keyed property of object thru iteratee.
8
+ * The iteratee is invoked with three arguments: (value, key, object).
9
+ *
10
+ * @param object the object to iterate over
11
+ * @param iteratee the function invoked per iteration.
12
+ */
13
+ export declare function mapValues<T, P>(object: Record<string, T>, iteratee: (val: T, key: string, obj: Record<string, T>) => P): Record<string, P>;
14
+ /**
15
+ * flattens collection using `prop` field as a children
16
+ * @param collectionItems collection items
17
+ * @param prop item property with child elements
18
+ */
19
+ export declare function flattenByProp<T extends object, P extends keyof T>(collectionItems: T[], prop: P): T[];
20
+ export declare function stripTrailingSlash(path: string): string;
21
+ export declare function isNumeric(n: any): n is number;
22
+ export declare function appendToMdHeading(md: string, heading: string, content: string): string;
23
+ export declare const mergeObjects: (target: any, ...sources: any[]) => any;
24
+ export declare const isObject: (item: unknown) => item is Record<string, unknown>;
25
+ /**
26
+ * slugify() returns empty string when failed to slugify.
27
+ * so try to return minimum slugified-string with failed one which keeps original value
28
+ * the regex codes are referenced with https://gist.github.com/mathewbyrne/1280286
29
+ */
30
+ export declare function safeSlugify(value: string): string;
31
+ export declare function isAbsoluteUrl(url: string): boolean;
32
+ /**
33
+ * simple resolve URL which doesn't break on strings with url fragments
34
+ * e.g. resolveUrl('http://test.com:{port}', 'path') results in http://test.com:{port}/path
35
+ */
36
+ export declare function resolveUrl(url: string, to: string): string;
37
+ export declare function getBasePath(serverUrl: string): string;
38
+ export declare function titleize(text: string): string;
39
+ export declare function removeQueryString(serverUrl: string): string;
40
+ export declare function escapeHTMLAttrChars(str: string): string;
41
+ export declare function unescapeHTMLChars(str: string): string;
42
+ export declare function isArray(value: unknown): value is any[];
43
+ export declare function isBoolean(value: unknown): value is boolean;
@@ -0,0 +1,230 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isBoolean = exports.isArray = exports.unescapeHTMLChars = exports.escapeHTMLAttrChars = exports.removeQueryString = exports.titleize = exports.getBasePath = exports.resolveUrl = exports.isAbsoluteUrl = exports.safeSlugify = exports.isObject = exports.mergeObjects = exports.appendToMdHeading = exports.isNumeric = exports.stripTrailingSlash = exports.flattenByProp = exports.mapValues = exports.mapWithLast = void 0;
13
+ // @ts-nocheck
14
+ const slugify_1 = __importDefault(require("slugify"));
15
+ /**
16
+ * Maps over array passing `isLast` bool to iterator as the second argument
17
+ */
18
+ function mapWithLast(array, iteratee) {
19
+ const res = [];
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
+ exports.mapWithLast = mapWithLast;
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
+ function mapValues(object, iteratee) {
38
+ const res = {};
39
+ for (const key in object) {
40
+ if (object.hasOwnProperty(key)) {
41
+ res[key] = iteratee(object[key], key, object);
42
+ }
43
+ }
44
+ return res;
45
+ }
46
+ exports.mapValues = mapValues;
47
+ /**
48
+ * flattens collection using `prop` field as a children
49
+ * @param collectionItems collection items
50
+ * @param prop item property with child elements
51
+ */
52
+ function flattenByProp(collectionItems, prop) {
53
+ const res = [];
54
+ const iterate = (items) => {
55
+ for (const item of items) {
56
+ res.push(item);
57
+ if (item[prop]) {
58
+ iterate(item[prop]);
59
+ }
60
+ }
61
+ };
62
+ iterate(collectionItems);
63
+ return res;
64
+ }
65
+ exports.flattenByProp = flattenByProp;
66
+ function stripTrailingSlash(path) {
67
+ if (path.endsWith("/")) {
68
+ return path.substring(0, path.length - 1);
69
+ }
70
+ return path;
71
+ }
72
+ exports.stripTrailingSlash = stripTrailingSlash;
73
+ function isNumeric(n) {
74
+ return !isNaN(parseFloat(n)) && isFinite(n);
75
+ }
76
+ exports.isNumeric = isNumeric;
77
+ function appendToMdHeading(md, heading, content) {
78
+ // if heading is already in md and append to the end of it
79
+ const testRegex = new RegExp(`(^|\\n)#\\s?${heading}\\s*\\n`, "i");
80
+ const replaceRegex = new RegExp(`((\\n|^)#\\s*${heading}\\s*(\\n|$)(?:.|\\n)*?)(\\n#|$)`, "i");
81
+ if (testRegex.test(md)) {
82
+ return md.replace(replaceRegex, `$1\n\n${content}\n$4`);
83
+ }
84
+ else {
85
+ // else append heading itself
86
+ const br = md === "" || md.endsWith("\n\n") ? "" : md.endsWith("\n") ? "\n" : "\n\n";
87
+ return `${md}${br}# ${heading}\n\n${content}`;
88
+ }
89
+ }
90
+ exports.appendToMdHeading = appendToMdHeading;
91
+ // credits https://stackoverflow.com/a/46973278/1749888
92
+ const mergeObjects = (target, ...sources) => {
93
+ if (!sources.length) {
94
+ return target;
95
+ }
96
+ const source = sources.shift();
97
+ if (source === undefined) {
98
+ return target;
99
+ }
100
+ if (isMergebleObject(target) && isMergebleObject(source)) {
101
+ Object.keys(source).forEach((key) => {
102
+ if (isMergebleObject(source[key])) {
103
+ if (!target[key]) {
104
+ target[key] = {};
105
+ }
106
+ (0, exports.mergeObjects)(target[key], source[key]);
107
+ }
108
+ else {
109
+ target[key] = source[key];
110
+ }
111
+ });
112
+ }
113
+ return (0, exports.mergeObjects)(target, ...sources);
114
+ };
115
+ exports.mergeObjects = mergeObjects;
116
+ const isObject = (item) => {
117
+ return item !== null && typeof item === "object";
118
+ };
119
+ exports.isObject = isObject;
120
+ const isMergebleObject = (item) => {
121
+ return (0, exports.isObject)(item) && !isArray(item);
122
+ };
123
+ /**
124
+ * slugify() returns empty string when failed to slugify.
125
+ * so try to return minimum slugified-string with failed one which keeps original value
126
+ * the regex codes are referenced with https://gist.github.com/mathewbyrne/1280286
127
+ */
128
+ function safeSlugify(value) {
129
+ return ((0, slugify_1.default)(value) ||
130
+ value
131
+ .toString()
132
+ .toLowerCase()
133
+ .replace(/\s+/g, "-") // Replace spaces with -
134
+ .replace(/&/g, "-and-") // Replace & with 'and'
135
+ .replace(/--+/g, "-") // Replace multiple - with single -
136
+ .replace(/^-+/, "") // Trim - from start of text
137
+ .replace(/-+$/, "")); // Trim - from end of text
138
+ }
139
+ exports.safeSlugify = safeSlugify;
140
+ function isAbsoluteUrl(url) {
141
+ return /(?:^[a-z][a-z0-9+.-]*:|\/\/)/i.test(url);
142
+ }
143
+ exports.isAbsoluteUrl = isAbsoluteUrl;
144
+ /**
145
+ * simple resolve URL which doesn't break on strings with url fragments
146
+ * e.g. resolveUrl('http://test.com:{port}', 'path') results in http://test.com:{port}/path
147
+ */
148
+ function resolveUrl(url, to) {
149
+ let res;
150
+ if (to.startsWith("//")) {
151
+ try {
152
+ res = `${new URL(url).protocol || "https:"}${to}`;
153
+ }
154
+ catch {
155
+ res = `https:${to}`;
156
+ }
157
+ }
158
+ else if (isAbsoluteUrl(to)) {
159
+ res = to;
160
+ }
161
+ else if (!to.startsWith("/")) {
162
+ res = stripTrailingSlash(url) + "/" + to;
163
+ }
164
+ else {
165
+ try {
166
+ const urlObj = new URL(url);
167
+ urlObj.pathname = to;
168
+ res = urlObj.href;
169
+ }
170
+ catch {
171
+ res = to;
172
+ }
173
+ }
174
+ return stripTrailingSlash(res);
175
+ }
176
+ exports.resolveUrl = resolveUrl;
177
+ function getBasePath(serverUrl) {
178
+ try {
179
+ return parseURL(serverUrl).pathname;
180
+ }
181
+ catch (e) {
182
+ // when using with redoc-cli serverUrl can be empty resulting in crash
183
+ return serverUrl;
184
+ }
185
+ }
186
+ exports.getBasePath = getBasePath;
187
+ function titleize(text) {
188
+ return text.charAt(0).toUpperCase() + text.slice(1);
189
+ }
190
+ exports.titleize = titleize;
191
+ function removeQueryString(serverUrl) {
192
+ try {
193
+ const url = parseURL(serverUrl);
194
+ url.search = "";
195
+ return url.toString();
196
+ }
197
+ catch (e) {
198
+ // when using with redoc-cli serverUrl can be empty resulting in crash
199
+ return serverUrl;
200
+ }
201
+ }
202
+ exports.removeQueryString = removeQueryString;
203
+ function parseURL(url) {
204
+ if (typeof URL === "undefined") {
205
+ // node
206
+ return new (require("url").URL)(url);
207
+ }
208
+ else {
209
+ return new URL(url);
210
+ }
211
+ }
212
+ function escapeHTMLAttrChars(str) {
213
+ return str.replace(/["\\]/g, "\\$&");
214
+ }
215
+ exports.escapeHTMLAttrChars = escapeHTMLAttrChars;
216
+ function unescapeHTMLChars(str) {
217
+ return str
218
+ .replace(/&#(\d+);/g, (_m, code) => String.fromCharCode(parseInt(code, 10)))
219
+ .replace(/&amp;/g, "&")
220
+ .replace(/&quot;/g, '"');
221
+ }
222
+ exports.unescapeHTMLChars = unescapeHTMLChars;
223
+ function isArray(value) {
224
+ return Array.isArray(value);
225
+ }
226
+ exports.isArray = isArray;
227
+ function isBoolean(value) {
228
+ return typeof value === "boolean";
229
+ }
230
+ exports.isBoolean = isBoolean;
@@ -0,0 +1,3 @@
1
+ export * from "./JsonPointer";
2
+ export * from "./openapi";
3
+ export * from "./helpers";
@@ -0,0 +1,25 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./JsonPointer"), exports);
24
+ __exportStar(require("./openapi"), exports);
25
+ __exportStar(require("./helpers"), exports);
@@ -0,0 +1,40 @@
1
+ import { OpenAPIParser } from "../services/OpenAPIParser";
2
+ import { OpenAPIEncoding, OpenAPIMediaType, OpenAPIParameter, OpenAPIRequestBody, OpenAPIResponse, OpenAPISchema, OpenAPIServer, Referenced } from "../types";
3
+ export declare function isStatusCode(statusCode: string): boolean;
4
+ export declare function getStatusCodeType(statusCode: string | number, defaultAsError?: boolean): string;
5
+ export declare function isOperationName(key: string): boolean;
6
+ export declare function getOperationSummary(operation: any): string;
7
+ export declare function detectType(schema: OpenAPISchema): string;
8
+ export declare function isPrimitiveType(schema: OpenAPISchema, type?: string | string[] | undefined): any;
9
+ export declare function isJsonLike(contentType: string): boolean;
10
+ export declare function isFormUrlEncoded(contentType: string): boolean;
11
+ export declare function urlFormEncodePayload(payload: object, encoding?: {
12
+ [field: string]: OpenAPIEncoding;
13
+ }): string;
14
+ export declare function serializeParameterValueWithMime(value: any, mime: string): string;
15
+ export declare function serializeParameterValue(parameter: OpenAPIParameter & {
16
+ serializationMime?: string;
17
+ }, value: any): string;
18
+ export declare function getSerializedValue(field: any, example: any): any;
19
+ export declare function langFromMime(contentType: string): string;
20
+ export declare function isNamedDefinition(pointer?: string): boolean;
21
+ export declare function getDefinitionName(pointer?: string): string | undefined;
22
+ export declare function humanizeNumberRange(schema: OpenAPISchema): string | undefined;
23
+ export declare function humanizeConstraints(schema: OpenAPISchema): string[];
24
+ export declare function sortByRequired(fields: any[], order?: string[]): any[];
25
+ export declare function sortByField(fields: any[], param: "name" | "description" | "kind"): any[];
26
+ export declare function mergeParams(parser: OpenAPIParser, pathParams?: Array<Referenced<OpenAPIParameter>>, operationParams?: Array<Referenced<OpenAPIParameter>>): Array<Referenced<OpenAPIParameter>>;
27
+ export declare function mergeSimilarMediaTypes(types: Record<string, OpenAPIMediaType>): Record<string, OpenAPIMediaType>;
28
+ export declare function expandDefaultServerVariables(url: string, variables?: object): string;
29
+ export declare function normalizeServers(specUrl: string | undefined, servers: OpenAPIServer[]): OpenAPIServer[];
30
+ export declare const SECURITY_DEFINITIONS_JSX_NAME = "SecurityDefinitions";
31
+ export declare const SCHEMA_DEFINITION_JSX_NAME = "SchemaDefinition";
32
+ export declare let SECURITY_SCHEMES_SECTION_PREFIX: string;
33
+ export declare function setSecuritySchemePrefix(prefix: string): void;
34
+ export declare const shortenHTTPVerb: (verb: any) => any;
35
+ export declare function isRedocExtension(key: string): boolean;
36
+ export declare function extractExtensions(obj: object, showExtensions: string[] | true): Record<string, any>;
37
+ export declare function pluralizeType(displayType: string): string;
38
+ export declare function getContentWithLegacyExamples(info: OpenAPIRequestBody | OpenAPIResponse): {
39
+ [mime: string]: OpenAPIMediaType;
40
+ } | undefined;