docusaurus-plugin-openapi-docs 2.0.0-beta.2 → 2.0.0-beta.4
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 +2 -1
- package/lib/index.js +20 -7
- package/lib/markdown/createAuthorization.d.ts +1 -0
- package/lib/markdown/createAuthorization.js +16 -0
- package/lib/markdown/createParamsDetails.js +2 -1
- package/lib/markdown/createRequestHeader.d.ts +1 -0
- package/lib/markdown/createRequestHeader.js +13 -0
- package/lib/markdown/createRequestSchema.d.ts +1 -8
- package/lib/markdown/createRequestSchema.js +21 -633
- package/lib/markdown/createResponseSchema.d.ts +1 -8
- package/lib/markdown/createResponseSchema.js +8 -626
- package/lib/markdown/createSchema.d.ts +12 -0
- package/lib/markdown/createSchema.js +647 -0
- package/lib/markdown/createVendorExtensions.d.ts +1 -0
- package/lib/markdown/createVendorExtensions.js +25 -0
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/index.js +11 -4
- package/lib/openapi/createRequestExample.js +3 -3
- package/lib/openapi/createResponseExample.js +3 -3
- package/lib/openapi/openapi.js +22 -0
- package/lib/openapi/utils/loadAndResolveSpec.js +9 -2
- package/lib/options.js +1 -0
- package/lib/types.d.ts +2 -0
- package/package.json +9 -17
- package/src/index.ts +21 -8
- package/src/markdown/createAuthorization.ts +13 -0
- package/src/markdown/createParamsDetails.ts +2 -1
- package/src/markdown/createRequestHeader.ts +10 -0
- package/src/markdown/createRequestSchema.ts +20 -839
- package/src/markdown/createResponseSchema.ts +8 -834
- package/src/markdown/createSchema.ts +850 -0
- package/src/markdown/createVendorExtensions.ts +22 -0
- package/src/markdown/index.ts +13 -3
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
- package/src/openapi/openapi.ts +26 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +10 -1
- package/src/options.ts +1 -0
- package/src/types.ts +2 -0
|
@@ -0,0 +1,22 @@
|
|
|
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 function createVendorExtensions(extensions: any) {
|
|
9
|
+
if (!extensions || typeof extensions !== "object") {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const rows: Array<string> = [];
|
|
13
|
+
extensions.map((extension: any) => {
|
|
14
|
+
const extensionRow = () => {
|
|
15
|
+
return `${extension.key}: ${JSON.stringify(extension.value)}`;
|
|
16
|
+
};
|
|
17
|
+
return rows.push(extensionRow());
|
|
18
|
+
});
|
|
19
|
+
return `\n\n\`\`\`
|
|
20
|
+
${rows.join("\n")}
|
|
21
|
+
\`\`\`\n\n`;
|
|
22
|
+
}
|
package/src/markdown/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from "../openapi/types";
|
|
14
14
|
import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
|
|
15
15
|
import { createAuthentication } from "./createAuthentication";
|
|
16
|
+
import { createAuthorization } from "./createAuthorization";
|
|
16
17
|
import { createContactInfo } from "./createContactInfo";
|
|
17
18
|
import { createDeprecationNotice } from "./createDeprecationNotice";
|
|
18
19
|
import { createDescription } from "./createDescription";
|
|
@@ -23,8 +24,10 @@ import { createLogo } from "./createLogo";
|
|
|
23
24
|
import { createMethodEndpoint } from "./createMethodEndpoint";
|
|
24
25
|
import { createParamsDetails } from "./createParamsDetails";
|
|
25
26
|
import { createRequestBodyDetails } from "./createRequestBodyDetails";
|
|
27
|
+
import { createRequestHeader } from "./createRequestHeader";
|
|
26
28
|
import { createStatusCodes } from "./createStatusCodes";
|
|
27
29
|
import { createTermsOfService } from "./createTermsOfService";
|
|
30
|
+
import { createVendorExtensions } from "./createVendorExtensions";
|
|
28
31
|
import { createVersionBadge } from "./createVersionBadge";
|
|
29
32
|
import { greaterThan, lessThan, render } from "./utils";
|
|
30
33
|
|
|
@@ -47,15 +50,19 @@ export function createApiPageMD({
|
|
|
47
50
|
description,
|
|
48
51
|
method,
|
|
49
52
|
path,
|
|
53
|
+
extensions,
|
|
50
54
|
parameters,
|
|
51
55
|
requestBody,
|
|
52
56
|
responses,
|
|
53
57
|
},
|
|
58
|
+
infoPath,
|
|
59
|
+
frontMatter,
|
|
54
60
|
}: ApiPageMetadata) {
|
|
55
61
|
return render([
|
|
56
62
|
`import ApiTabs from "@theme/ApiTabs";\n`,
|
|
57
63
|
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
58
|
-
`import MethodEndpoint from "@theme/
|
|
64
|
+
`import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";\n`,
|
|
65
|
+
`import SecuritySchemes from "@theme/ApiExplorer/SecuritySchemes";\n`,
|
|
59
66
|
`import MimeTabs from "@theme/MimeTabs";\n`,
|
|
60
67
|
`import ParamsItem from "@theme/ParamsItem";\n`,
|
|
61
68
|
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
@@ -64,14 +71,17 @@ export function createApiPageMD({
|
|
|
64
71
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
65
72
|
createHeading(title.replace(lessThan, "<").replace(greaterThan, ">")),
|
|
66
73
|
createMethodEndpoint(method, path),
|
|
74
|
+
infoPath && createAuthorization(infoPath),
|
|
75
|
+
frontMatter.show_extensions && createVendorExtensions(extensions),
|
|
67
76
|
createDeprecationNotice({ deprecated, description: deprecatedDescription }),
|
|
68
77
|
createDescription(description),
|
|
78
|
+
createRequestHeader("Request"),
|
|
69
79
|
createParamsDetails({ parameters, type: "path" }),
|
|
70
80
|
createParamsDetails({ parameters, type: "query" }),
|
|
71
81
|
createParamsDetails({ parameters, type: "header" }),
|
|
72
82
|
createParamsDetails({ parameters, type: "cookie" }),
|
|
73
83
|
createRequestBodyDetails({
|
|
74
|
-
title: "
|
|
84
|
+
title: "Body",
|
|
75
85
|
body: requestBody,
|
|
76
86
|
} as Props),
|
|
77
87
|
createStatusCodes({ responses }),
|
|
@@ -96,7 +106,7 @@ export function createInfoPageMD({
|
|
|
96
106
|
`import ApiLogo from "@theme/ApiLogo";\n`,
|
|
97
107
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
98
108
|
`import TabItem from "@theme/TabItem";\n`,
|
|
99
|
-
`import Export from "@theme/
|
|
109
|
+
`import Export from "@theme/ApiExplorer/Export";\n\n`,
|
|
100
110
|
|
|
101
111
|
createVersionBadge(version),
|
|
102
112
|
createDownload(downloadUrl),
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import chalk from "chalk";
|
|
9
9
|
import merge from "lodash/merge";
|
|
10
10
|
|
|
11
|
-
import { mergeAllOf } from "../markdown/
|
|
11
|
+
import { mergeAllOf } from "../markdown/createSchema";
|
|
12
12
|
import { SchemaObject } from "./types";
|
|
13
13
|
|
|
14
14
|
interface OASTypeToTypeMap {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import chalk from "chalk";
|
|
9
9
|
import merge from "lodash/merge";
|
|
10
10
|
|
|
11
|
-
import { mergeAllOf } from "../markdown/
|
|
11
|
+
import { mergeAllOf } from "../markdown/createSchema";
|
|
12
12
|
import { SchemaObject } from "./types";
|
|
13
13
|
|
|
14
14
|
interface OASTypeToTypeMap {
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -144,6 +144,15 @@ function createItems(
|
|
|
144
144
|
? kebabCase(operationObject.operationId)
|
|
145
145
|
: kebabCase(operationObject.summary);
|
|
146
146
|
|
|
147
|
+
const extensions = [];
|
|
148
|
+
const commonExtensions = ["x-codeSamples"];
|
|
149
|
+
|
|
150
|
+
for (const [key, value] of Object.entries(operationObject)) {
|
|
151
|
+
if (key.startsWith("x-") && !commonExtensions.includes(key)) {
|
|
152
|
+
extensions.push({ key, value });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
147
156
|
const servers =
|
|
148
157
|
operationObject.servers ?? pathObject.servers ?? openapiData.servers;
|
|
149
158
|
|
|
@@ -224,9 +233,13 @@ function createItems(
|
|
|
224
233
|
...(options?.hideSendButton && {
|
|
225
234
|
hide_send_button: options.hideSendButton,
|
|
226
235
|
}),
|
|
236
|
+
...(options?.showExtensions && {
|
|
237
|
+
show_extensions: options.showExtensions,
|
|
238
|
+
}),
|
|
227
239
|
},
|
|
228
240
|
api: {
|
|
229
241
|
...defaults,
|
|
242
|
+
...(extensions.length > 0 && { extensions: extensions }),
|
|
230
243
|
tags: operationObject.tags,
|
|
231
244
|
method,
|
|
232
245
|
path,
|
|
@@ -264,6 +277,15 @@ function createItems(
|
|
|
264
277
|
? kebabCase(operationObject.operationId)
|
|
265
278
|
: kebabCase(operationObject.summary);
|
|
266
279
|
|
|
280
|
+
const extensions = [];
|
|
281
|
+
const commonExtensions = ["x-codeSamples"];
|
|
282
|
+
|
|
283
|
+
for (const [key, value] of Object.entries(operationObject)) {
|
|
284
|
+
if (key.startsWith("x-") && !commonExtensions.includes(key)) {
|
|
285
|
+
extensions.push({ key, value });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
267
289
|
const servers =
|
|
268
290
|
operationObject.servers ?? pathObject.servers ?? openapiData.servers;
|
|
269
291
|
|
|
@@ -344,9 +366,13 @@ function createItems(
|
|
|
344
366
|
...(options?.hideSendButton && {
|
|
345
367
|
hide_send_button: options.hideSendButton,
|
|
346
368
|
}),
|
|
369
|
+
...(options?.showExtensions && {
|
|
370
|
+
show_extensions: options.showExtensions,
|
|
371
|
+
}),
|
|
347
372
|
},
|
|
348
373
|
api: {
|
|
349
374
|
...defaults,
|
|
375
|
+
...(extensions.length > 0 && { extensions: extensions }),
|
|
350
376
|
tags: operationObject.tags,
|
|
351
377
|
method,
|
|
352
378
|
path,
|
|
@@ -101,7 +101,16 @@ async function resolveJsonRefs(specUrlOrObject: object | string) {
|
|
|
101
101
|
});
|
|
102
102
|
return schema as OpenApiObject;
|
|
103
103
|
} catch (err: any) {
|
|
104
|
-
|
|
104
|
+
let errorMsg = "";
|
|
105
|
+
|
|
106
|
+
if (err.errors[0] !== undefined) {
|
|
107
|
+
const error = err.errors[0];
|
|
108
|
+
errorMsg = `Error: [${error.message}] with footprint [${error.footprint}]`;
|
|
109
|
+
} else {
|
|
110
|
+
errorMsg = err;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.error(chalk.yellow(errorMsg));
|
|
105
114
|
return;
|
|
106
115
|
}
|
|
107
116
|
}
|
package/src/options.ts
CHANGED
|
@@ -28,6 +28,7 @@ export const OptionsSchema = Joi.object({
|
|
|
28
28
|
template: Joi.string(),
|
|
29
29
|
downloadUrl: Joi.string(),
|
|
30
30
|
hideSendButton: Joi.boolean(),
|
|
31
|
+
showExtensions: Joi.boolean(),
|
|
31
32
|
sidebarOptions: sidebarOptions,
|
|
32
33
|
version: Joi.string().when("versions", {
|
|
33
34
|
is: Joi.exist(),
|
package/src/types.ts
CHANGED
|
@@ -34,6 +34,7 @@ export interface APIOptions {
|
|
|
34
34
|
template?: string;
|
|
35
35
|
downloadUrl?: string;
|
|
36
36
|
hideSendButton?: boolean;
|
|
37
|
+
showExtensions?: boolean;
|
|
37
38
|
sidebarOptions?: SidebarOptions;
|
|
38
39
|
version?: string;
|
|
39
40
|
label?: string;
|
|
@@ -105,6 +106,7 @@ export interface ApiItem extends OperationObject {
|
|
|
105
106
|
postman?: Request;
|
|
106
107
|
proxy?: string;
|
|
107
108
|
info: InfoObject;
|
|
109
|
+
extensions?: object;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
export interface InfoPageMetadata extends ApiMetadataBase {
|