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,305 @@
1
+ import { Omit } from "./index";
2
+ export interface OpenAPISpec {
3
+ openapi: string;
4
+ info: OpenAPIInfo;
5
+ servers?: OpenAPIServer[];
6
+ paths: OpenAPIPaths;
7
+ components?: OpenAPIComponents;
8
+ security?: OpenAPISecurityRequirement[];
9
+ tags?: OpenAPITag[];
10
+ externalDocs?: OpenAPIExternalDocumentation;
11
+ "x-webhooks"?: OpenAPIPaths;
12
+ webhooks?: OpenAPIPaths;
13
+ }
14
+ export interface OpenAPIInfo {
15
+ title: string;
16
+ version: string;
17
+ description?: string;
18
+ summary?: string;
19
+ termsOfService?: string;
20
+ contact?: OpenAPIContact;
21
+ license?: OpenAPILicense;
22
+ }
23
+ export interface OpenAPIServer {
24
+ url: string;
25
+ description?: string;
26
+ variables?: {
27
+ [name: string]: OpenAPIServerVariable;
28
+ };
29
+ }
30
+ export interface OpenAPIServerVariable {
31
+ enum?: string[];
32
+ default: string;
33
+ description?: string;
34
+ }
35
+ export interface OpenAPIPaths {
36
+ [path: string]: OpenAPIPath;
37
+ }
38
+ export interface OpenAPIRef {
39
+ $ref: string;
40
+ }
41
+ export declare type Referenced<T> = OpenAPIRef | T;
42
+ export interface OpenAPIPath {
43
+ summary?: string;
44
+ description?: string;
45
+ get?: OpenAPIOperation;
46
+ put?: OpenAPIOperation;
47
+ post?: OpenAPIOperation;
48
+ delete?: OpenAPIOperation;
49
+ options?: OpenAPIOperation;
50
+ head?: OpenAPIOperation;
51
+ patch?: OpenAPIOperation;
52
+ trace?: OpenAPIOperation;
53
+ servers?: OpenAPIServer[];
54
+ parameters?: Array<Referenced<OpenAPIParameter>>;
55
+ $ref?: string;
56
+ }
57
+ export interface OpenAPIXCodeSample {
58
+ lang: string;
59
+ label?: string;
60
+ source: string;
61
+ }
62
+ export interface OpenAPIOperation {
63
+ tags?: string[];
64
+ summary?: string;
65
+ description?: string;
66
+ externalDocs?: OpenAPIExternalDocumentation;
67
+ operationId?: string;
68
+ parameters?: Array<Referenced<OpenAPIParameter>>;
69
+ requestBody?: Referenced<OpenAPIRequestBody>;
70
+ responses: OpenAPIResponses;
71
+ callbacks?: {
72
+ [name: string]: Referenced<OpenAPICallback>;
73
+ };
74
+ deprecated?: boolean;
75
+ security?: OpenAPISecurityRequirement[];
76
+ servers?: OpenAPIServer[];
77
+ "x-codeSamples"?: OpenAPIXCodeSample[];
78
+ "x-code-samples"?: OpenAPIXCodeSample[];
79
+ }
80
+ export interface OpenAPIParameter {
81
+ name: string;
82
+ in?: OpenAPIParameterLocation;
83
+ description?: string;
84
+ required?: boolean;
85
+ deprecated?: boolean;
86
+ allowEmptyValue?: boolean;
87
+ style?: OpenAPIParameterStyle;
88
+ explode?: boolean;
89
+ allowReserved?: boolean;
90
+ schema?: Referenced<OpenAPISchema>;
91
+ example?: any;
92
+ examples?: {
93
+ [media: string]: Referenced<OpenAPIExample>;
94
+ };
95
+ content?: {
96
+ [media: string]: OpenAPIMediaType;
97
+ };
98
+ encoding?: Record<string, OpenAPIEncoding>;
99
+ const?: any;
100
+ }
101
+ export interface OpenAPIExample {
102
+ value: any;
103
+ summary?: string;
104
+ description?: string;
105
+ externalValue?: string;
106
+ }
107
+ export interface OpenAPISchema {
108
+ $ref?: string;
109
+ type?: string | string[];
110
+ properties?: {
111
+ [name: string]: OpenAPISchema;
112
+ };
113
+ patternProperties?: {
114
+ [name: string]: OpenAPISchema;
115
+ };
116
+ additionalProperties?: boolean | OpenAPISchema;
117
+ unevaluatedProperties?: boolean | OpenAPISchema;
118
+ description?: string;
119
+ default?: any;
120
+ items?: OpenAPISchema | OpenAPISchema[] | boolean;
121
+ required?: string[];
122
+ readOnly?: boolean;
123
+ writeOnly?: boolean;
124
+ deprecated?: boolean;
125
+ format?: string;
126
+ externalDocs?: OpenAPIExternalDocumentation;
127
+ discriminator?: OpenAPIDiscriminator;
128
+ nullable?: boolean;
129
+ oneOf?: OpenAPISchema[];
130
+ anyOf?: OpenAPISchema[];
131
+ allOf?: OpenAPISchema[];
132
+ not?: OpenAPISchema;
133
+ title?: string;
134
+ multipleOf?: number;
135
+ maximum?: number;
136
+ exclusiveMaximum?: boolean | number;
137
+ minimum?: number;
138
+ exclusiveMinimum?: boolean | number;
139
+ maxLength?: number;
140
+ minLength?: number;
141
+ pattern?: string;
142
+ maxItems?: number;
143
+ minItems?: number;
144
+ uniqueItems?: boolean;
145
+ maxProperties?: number;
146
+ minProperties?: number;
147
+ enum?: any[];
148
+ example?: any;
149
+ if?: OpenAPISchema;
150
+ else?: OpenAPISchema;
151
+ then?: OpenAPISchema;
152
+ examples?: any[];
153
+ const?: string;
154
+ contentEncoding?: string;
155
+ contentMediaType?: string;
156
+ prefixItems?: OpenAPISchema[];
157
+ additionalItems?: OpenAPISchema | boolean;
158
+ }
159
+ export interface OpenAPIDiscriminator {
160
+ propertyName: string;
161
+ mapping?: {
162
+ [name: string]: string;
163
+ };
164
+ "x-explicitMappingOnly"?: boolean;
165
+ }
166
+ export interface OpenAPIMediaType {
167
+ schema?: Referenced<OpenAPISchema>;
168
+ example?: any;
169
+ examples?: {
170
+ [name: string]: Referenced<OpenAPIExample>;
171
+ };
172
+ encoding?: {
173
+ [field: string]: OpenAPIEncoding;
174
+ };
175
+ }
176
+ export interface OpenAPIEncoding {
177
+ contentType: string;
178
+ headers?: {
179
+ [name: string]: Referenced<OpenAPIHeader>;
180
+ };
181
+ style: OpenAPIParameterStyle;
182
+ explode: boolean;
183
+ allowReserved: boolean;
184
+ }
185
+ export declare type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
186
+ export declare type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
187
+ export interface OpenAPIRequestBody {
188
+ description?: string;
189
+ required?: boolean;
190
+ content: {
191
+ [mime: string]: OpenAPIMediaType;
192
+ };
193
+ "x-examples"?: {
194
+ [mime: string]: {
195
+ [name: string]: Referenced<OpenAPIExample>;
196
+ };
197
+ };
198
+ "x-example"?: {
199
+ [mime: string]: any;
200
+ };
201
+ }
202
+ export interface OpenAPIResponses {
203
+ [code: string]: Referenced<OpenAPIResponse>;
204
+ }
205
+ export interface OpenAPIResponse extends Pick<OpenAPIRequestBody, "description" | "x-examples" | "x-example"> {
206
+ headers?: {
207
+ [name: string]: Referenced<OpenAPIHeader>;
208
+ };
209
+ links?: {
210
+ [name: string]: Referenced<OpenAPILink>;
211
+ };
212
+ content?: {
213
+ [mime: string]: OpenAPIMediaType;
214
+ };
215
+ }
216
+ export interface OpenAPILink {
217
+ $ref?: string;
218
+ }
219
+ export declare type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
220
+ export interface OpenAPICallback {
221
+ [name: string]: OpenAPIPath;
222
+ }
223
+ export interface OpenAPIComponents {
224
+ schemas?: {
225
+ [name: string]: Referenced<OpenAPISchema>;
226
+ };
227
+ responses?: {
228
+ [name: string]: Referenced<OpenAPIResponse>;
229
+ };
230
+ parameters?: {
231
+ [name: string]: Referenced<OpenAPIParameter>;
232
+ };
233
+ examples?: {
234
+ [name: string]: Referenced<OpenAPIExample>;
235
+ };
236
+ requestBodies?: {
237
+ [name: string]: Referenced<OpenAPIRequestBody>;
238
+ };
239
+ headers?: {
240
+ [name: string]: Referenced<OpenAPIHeader>;
241
+ };
242
+ securitySchemes?: {
243
+ [name: string]: Referenced<OpenAPISecurityScheme>;
244
+ };
245
+ links?: {
246
+ [name: string]: Referenced<OpenAPILink>;
247
+ };
248
+ callbacks?: {
249
+ [name: string]: Referenced<OpenAPICallback>;
250
+ };
251
+ }
252
+ export interface OpenAPISecurityRequirement {
253
+ [name: string]: string[];
254
+ }
255
+ export interface OpenAPISecurityScheme {
256
+ type: "apiKey" | "http" | "oauth2" | "openIdConnect";
257
+ description?: string;
258
+ name?: string;
259
+ in?: "query" | "header" | "cookie";
260
+ scheme?: string;
261
+ bearerFormat: string;
262
+ flows: {
263
+ implicit?: {
264
+ refreshUrl?: string;
265
+ scopes: Record<string, string>;
266
+ authorizationUrl: string;
267
+ };
268
+ password?: {
269
+ refreshUrl?: string;
270
+ scopes: Record<string, string>;
271
+ tokenUrl: string;
272
+ };
273
+ clientCredentials?: {
274
+ refreshUrl?: string;
275
+ scopes: Record<string, string>;
276
+ tokenUrl: string;
277
+ };
278
+ authorizationCode?: {
279
+ refreshUrl?: string;
280
+ scopes: Record<string, string>;
281
+ tokenUrl: string;
282
+ };
283
+ };
284
+ openIdConnectUrl?: string;
285
+ }
286
+ export interface OpenAPITag {
287
+ name: string;
288
+ description?: string;
289
+ externalDocs?: OpenAPIExternalDocumentation;
290
+ "x-displayName"?: string;
291
+ }
292
+ export interface OpenAPIExternalDocumentation {
293
+ description?: string;
294
+ url: string;
295
+ }
296
+ export interface OpenAPIContact {
297
+ name?: string;
298
+ url?: string;
299
+ email?: string;
300
+ }
301
+ export interface OpenAPILicense {
302
+ name: string;
303
+ url?: string;
304
+ identifier?: string;
305
+ }
@@ -0,0 +1,8 @@
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 });
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Wrapper for JsonPointer. Provides common operations
3
+ */
4
+ export declare class JsonPointer {
5
+ /**
6
+ * returns last JsonPointer token
7
+ * if level > 1 returns levels last (second last/third last)
8
+ * @example
9
+ * // returns subpath
10
+ * JsonPointerHelper.baseName('/path/0/subpath')
11
+ * // returns foo
12
+ * JsonPointerHelper.baseName('/path/foo/subpath', 2)
13
+ */
14
+ static baseName(pointer: any, level?: number): string;
15
+ /**
16
+ * returns dirname of pointer
17
+ * if level > 1 returns corresponding dirname in the hierarchy
18
+ * @example
19
+ * // returns /path/0
20
+ * JsonPointerHelper.dirName('/path/0/subpath')
21
+ * // returns /path
22
+ * JsonPointerHelper.dirName('/path/foo/subpath', 2)
23
+ */
24
+ static dirName(pointer: any, level?: number): string;
25
+ /**
26
+ * returns relative path tokens
27
+ * @example
28
+ * // returns ['subpath']
29
+ * JsonPointerHelper.relative('/path/0', '/path/0/subpath')
30
+ * // returns ['foo', 'subpath']
31
+ * JsonPointerHelper.relative('/path', '/path/foo/subpath')
32
+ */
33
+ static relative(from: any, to: any): string[];
34
+ /**
35
+ * overridden JsonPointer original parse to take care of prefixing '#' symbol
36
+ * that is not valid JsonPointer
37
+ */
38
+ static parse(pointer: any): string[];
39
+ /**
40
+ * Creates a JSON pointer path, by joining one or more tokens to a base path.
41
+ *
42
+ * @param {string} base - The base path
43
+ * @param {string|string[]} tokens - The token(s) to append (e.g. ["name", "first"])
44
+ * @returns {string}
45
+ */
46
+ static join(base: any, tokens: any): string;
47
+ static get(object: object, pointer: string): any;
48
+ static compile(tokens: string[]): string;
49
+ static escape(pointer: string): string;
50
+ }
51
+ export default JsonPointer;
@@ -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;