docusaurus-plugin-openapi-docs 1.0.5 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +6 -7
  2. package/lib/index.js +3 -3
  3. package/lib/markdown/createSchemaDetails.js +325 -132
  4. package/lib/markdown/index.js +1 -0
  5. package/lib/markdown/schema.js +25 -9
  6. package/lib/markdown/utils.d.ts +1 -1
  7. package/lib/markdown/utils.js +4 -1
  8. package/lib/openapi/openapi.d.ts +5 -5
  9. package/lib/openapi/openapi.js +27 -23
  10. package/lib/openapi/openapi.test.js +1 -1
  11. package/lib/openapi/types.d.ts +2 -1
  12. package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
  13. package/lib/openapi/utils/loadAndResolveSpec.js +112 -0
  14. package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
  15. package/lib/openapi/utils/services/OpenAPIParser.js +342 -0
  16. package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
  17. package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
  18. package/lib/openapi/utils/types/index.d.ts +2 -0
  19. package/lib/openapi/utils/types/index.js +23 -0
  20. package/lib/openapi/utils/types/open-api.d.ts +305 -0
  21. package/lib/openapi/utils/types/open-api.js +8 -0
  22. package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
  23. package/lib/openapi/utils/utils/JsonPointer.js +95 -0
  24. package/lib/openapi/utils/utils/helpers.d.ts +43 -0
  25. package/lib/openapi/utils/utils/helpers.js +230 -0
  26. package/lib/openapi/utils/utils/index.d.ts +3 -0
  27. package/lib/openapi/utils/utils/index.js +25 -0
  28. package/lib/openapi/utils/utils/openapi.d.ts +40 -0
  29. package/lib/openapi/utils/utils/openapi.js +605 -0
  30. package/lib/options.js +1 -1
  31. package/lib/sidebars/index.js +9 -5
  32. package/lib/types.d.ts +1 -1
  33. package/package.json +16 -11
  34. package/src/index.ts +3 -3
  35. package/src/markdown/createSchemaDetails.ts +405 -159
  36. package/src/markdown/index.ts +1 -0
  37. package/src/markdown/schema.ts +28 -8
  38. package/src/markdown/utils.ts +5 -2
  39. package/src/openapi/openapi.test.ts +1 -1
  40. package/src/openapi/openapi.ts +39 -29
  41. package/src/openapi/types.ts +2 -1
  42. package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
  43. package/src/openapi/utils/services/OpenAPIParser.ts +433 -0
  44. package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
  45. package/src/openapi/utils/types/index.ts +10 -0
  46. package/src/openapi/utils/types/open-api.ts +303 -0
  47. package/src/openapi/utils/utils/JsonPointer.ts +99 -0
  48. package/src/openapi/utils/utils/helpers.ts +239 -0
  49. package/src/openapi/utils/utils/index.ts +11 -0
  50. package/src/openapi/utils/utils/openapi.ts +771 -0
  51. package/src/options.ts +1 -1
  52. package/src/sidebars/index.ts +11 -6
  53. package/src/types.ts +1 -1
  54. package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
  55. package/lib/openapi/utils/loadAndBundleSpec.js +0 -44
  56. package/src/openapi/utils/loadAndBundleSpec.ts +0 -62
@@ -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;