docusaurus-plugin-openapi-docs 0.0.0-1000
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/LICENSE +21 -0
- package/README.md +361 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +709 -0
- package/lib/markdown/createArrayBracket.d.ts +2 -0
- package/lib/markdown/createArrayBracket.js +36 -0
- package/lib/markdown/createAuthentication.d.ts +2 -0
- package/lib/markdown/createAuthentication.js +171 -0
- package/lib/markdown/createAuthorization.d.ts +1 -0
- package/lib/markdown/createAuthorization.js +15 -0
- package/lib/markdown/createCallbackMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createCallbackMethodEndpoint.js +20 -0
- package/lib/markdown/createCallbacks.d.ts +6 -0
- package/lib/markdown/createCallbacks.js +77 -0
- package/lib/markdown/createContactInfo.d.ts +2 -0
- package/lib/markdown/createContactInfo.js +39 -0
- package/lib/markdown/createDeprecationNotice.d.ts +6 -0
- package/lib/markdown/createDeprecationNotice.js +20 -0
- package/lib/markdown/createDescription.d.ts +1 -0
- package/lib/markdown/createDescription.js +13 -0
- package/lib/markdown/createDetails.d.ts +2 -0
- package/lib/markdown/createDetails.js +17 -0
- package/lib/markdown/createDetailsSummary.d.ts +2 -0
- package/lib/markdown/createDetailsSummary.js +17 -0
- package/lib/markdown/createDownload.d.ts +1 -0
- package/lib/markdown/createDownload.js +16 -0
- package/lib/markdown/createHeading.d.ts +1 -0
- package/lib/markdown/createHeading.js +20 -0
- package/lib/markdown/createLicense.d.ts +2 -0
- package/lib/markdown/createLicense.js +32 -0
- package/lib/markdown/createLogo.d.ts +2 -0
- package/lib/markdown/createLogo.js +18 -0
- package/lib/markdown/createMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createMethodEndpoint.js +20 -0
- package/lib/markdown/createParamsDetails.d.ts +6 -0
- package/lib/markdown/createParamsDetails.js +18 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +13 -0
- package/lib/markdown/createRequestBodyDetails.js +13 -0
- package/lib/markdown/createRequestHeader.d.ts +1 -0
- package/lib/markdown/createRequestHeader.js +21 -0
- package/lib/markdown/createRequestSchema.d.ts +14 -0
- package/lib/markdown/createRequestSchema.js +20 -0
- package/lib/markdown/createResponseSchema.d.ts +14 -0
- package/lib/markdown/createResponseSchema.js +20 -0
- package/lib/markdown/createSchema.d.ts +9 -0
- package/lib/markdown/createSchema.js +668 -0
- package/lib/markdown/createSchema.test.d.ts +1 -0
- package/lib/markdown/createSchema.test.js +913 -0
- package/lib/markdown/createStatusCodes.d.ts +9 -0
- package/lib/markdown/createStatusCodes.js +63 -0
- package/lib/markdown/createTermsOfService.d.ts +1 -0
- package/lib/markdown/createTermsOfService.js +31 -0
- package/lib/markdown/createVendorExtensions.d.ts +1 -0
- package/lib/markdown/createVendorExtensions.js +24 -0
- package/lib/markdown/createVersionBadge.d.ts +1 -0
- package/lib/markdown/createVersionBadge.js +19 -0
- package/lib/markdown/index.d.ts +5 -0
- package/lib/markdown/index.js +92 -0
- package/lib/markdown/schema.d.ts +3 -0
- package/lib/markdown/schema.js +154 -0
- package/lib/markdown/schema.test.d.ts +1 -0
- package/lib/markdown/schema.test.js +181 -0
- package/lib/markdown/utils.d.ts +20 -0
- package/lib/markdown/utils.js +68 -0
- package/lib/openapi/createRequestExample.d.ts +2 -0
- package/lib/openapi/createRequestExample.js +191 -0
- package/lib/openapi/createResponseExample.d.ts +2 -0
- package/lib/openapi/createResponseExample.js +192 -0
- package/lib/openapi/index.d.ts +1 -0
- package/lib/openapi/index.js +12 -0
- package/lib/openapi/openapi.d.ts +12 -0
- package/lib/openapi/openapi.js +544 -0
- package/lib/openapi/openapi.test.d.ts +1 -0
- package/lib/openapi/openapi.test.js +33 -0
- package/lib/openapi/types.d.ts +354 -0
- package/lib/openapi/types.js +8 -0
- package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
- package/lib/openapi/utils/loadAndResolveSpec.js +153 -0
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
- package/lib/openapi/utils/services/OpenAPIParser.js +343 -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/types.d.ts +306 -0
- package/lib/openapi/utils/types.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/options.d.ts +2 -0
- package/lib/options.js +69 -0
- package/lib/sidebars/index.d.ts +4 -0
- package/lib/sidebars/index.js +226 -0
- package/lib/sidebars/utils.d.ts +2 -0
- package/lib/sidebars/utils.js +30 -0
- package/lib/types.d.ts +135 -0
- package/lib/types.js +8 -0
- package/package.json +69 -0
- package/src/index.ts +945 -0
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +1605 -0
- package/src/markdown/createArrayBracket.ts +35 -0
- package/src/markdown/createAuthentication.ts +201 -0
- package/src/markdown/createAuthorization.ts +13 -0
- package/src/markdown/createCallbackMethodEndpoint.ts +19 -0
- package/src/markdown/createCallbacks.ts +101 -0
- package/src/markdown/createContactInfo.ts +41 -0
- package/src/markdown/createDeprecationNotice.ts +31 -0
- package/src/markdown/createDescription.ts +12 -0
- package/src/markdown/createDetails.ts +16 -0
- package/src/markdown/createDetailsSummary.ts +16 -0
- package/src/markdown/createDownload.ts +15 -0
- package/src/markdown/createHeading.ts +23 -0
- package/src/markdown/createLicense.ts +34 -0
- package/src/markdown/createLogo.ts +21 -0
- package/src/markdown/createMethodEndpoint.ts +19 -0
- package/src/markdown/createParamsDetails.ts +22 -0
- package/src/markdown/createRequestBodyDetails.ts +24 -0
- package/src/markdown/createRequestHeader.ts +24 -0
- package/src/markdown/createRequestSchema.ts +32 -0
- package/src/markdown/createResponseSchema.ts +32 -0
- package/src/markdown/createSchema.test.ts +1075 -0
- package/src/markdown/createSchema.ts +862 -0
- package/src/markdown/createStatusCodes.ts +63 -0
- package/src/markdown/createTermsOfService.ts +30 -0
- package/src/markdown/createVendorExtensions.ts +22 -0
- package/src/markdown/createVersionBadge.ts +22 -0
- package/src/markdown/index.ts +144 -0
- package/src/markdown/schema.test.ts +208 -0
- package/src/markdown/schema.ts +185 -0
- package/src/markdown/utils.ts +89 -0
- package/src/openapi/__fixtures__/examples/openapi.yaml +49 -0
- package/src/openapi/createRequestExample.ts +235 -0
- package/src/openapi/createResponseExample.ts +238 -0
- package/src/openapi/index.ts +8 -0
- package/src/openapi/openapi.test.ts +40 -0
- package/src/openapi/openapi.ts +697 -0
- package/src/openapi/types.ts +455 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +171 -0
- package/src/openapi/utils/services/OpenAPIParser.ts +434 -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/types.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/openapi-to-postmanv2.d.ts +10 -0
- package/src/options.ts +77 -0
- package/src/plugin-content-docs-types.d.ts +42 -0
- package/src/plugin-openapi.d.ts +87 -0
- package/src/postman-collection.d.ts +10 -0
- package/src/sidebars/index.ts +322 -0
- package/src/sidebars/utils.ts +29 -0
- package/src/types.ts +176 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,63 @@
|
|
|
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 { create } from "./utils";
|
|
9
|
+
import { ApiItem } from "../types";
|
|
10
|
+
|
|
11
|
+
export default function json2xml(o: any, tab: any) {
|
|
12
|
+
var toXml = function (v: any, name: string, ind: any) {
|
|
13
|
+
var xml = "";
|
|
14
|
+
if (v instanceof Array) {
|
|
15
|
+
for (var i = 0, n = v.length; i < n; i++)
|
|
16
|
+
xml += ind + toXml(v[i], name, ind + "\t") + "\n";
|
|
17
|
+
} else if (typeof v == "object") {
|
|
18
|
+
var hasChild = false;
|
|
19
|
+
xml += ind + "<" + name;
|
|
20
|
+
for (var m in v) {
|
|
21
|
+
if (m.charAt(0) === "@")
|
|
22
|
+
xml += " " + m.substr(1) + '="' + v[m].toString() + '"';
|
|
23
|
+
else hasChild = true;
|
|
24
|
+
}
|
|
25
|
+
xml += hasChild ? ">" : "/>";
|
|
26
|
+
if (hasChild) {
|
|
27
|
+
for (var m2 in v) {
|
|
28
|
+
if (m2 === "#text") xml += v[m2];
|
|
29
|
+
else if (m2 === "#cdata") xml += "<![CDATA[" + v[m2] + "]]>";
|
|
30
|
+
else if (m2.charAt(0) !== "@") xml += toXml(v[m2], m2, ind + "\t");
|
|
31
|
+
}
|
|
32
|
+
xml +=
|
|
33
|
+
(xml.charAt(xml.length - 1) === "\n" ? ind : "") +
|
|
34
|
+
"</" +
|
|
35
|
+
name +
|
|
36
|
+
">";
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
|
|
40
|
+
}
|
|
41
|
+
return xml;
|
|
42
|
+
},
|
|
43
|
+
xml = "";
|
|
44
|
+
for (var m3 in o) xml += toXml(o[m3], m3, "");
|
|
45
|
+
return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface Props {
|
|
49
|
+
id?: string;
|
|
50
|
+
label?: string;
|
|
51
|
+
responses: ApiItem["responses"];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createStatusCodes({ id, label, responses }: Props) {
|
|
55
|
+
return [
|
|
56
|
+
create("StatusCodes", {
|
|
57
|
+
id: id,
|
|
58
|
+
label: label,
|
|
59
|
+
responses: responses,
|
|
60
|
+
}),
|
|
61
|
+
"\n\n",
|
|
62
|
+
];
|
|
63
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { create } from "./utils";
|
|
9
|
+
|
|
10
|
+
export function createTermsOfService(termsOfService: string | undefined) {
|
|
11
|
+
if (!termsOfService) return "";
|
|
12
|
+
|
|
13
|
+
return create("div", {
|
|
14
|
+
style: {
|
|
15
|
+
marginBottom: "var(--ifm-paragraph-margin-bottom)",
|
|
16
|
+
},
|
|
17
|
+
children: [
|
|
18
|
+
create("h3", {
|
|
19
|
+
style: {
|
|
20
|
+
marginBottom: "0.25rem",
|
|
21
|
+
},
|
|
22
|
+
children: "Terms of Service",
|
|
23
|
+
}),
|
|
24
|
+
create("a", {
|
|
25
|
+
href: `${termsOfService}`,
|
|
26
|
+
children: `{'${termsOfService}'}`,
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
import { create, guard } from "./utils";
|
|
9
|
+
|
|
10
|
+
export function createVersionBadge(version: string | undefined) {
|
|
11
|
+
return guard(version, (version) => [
|
|
12
|
+
create(
|
|
13
|
+
"span",
|
|
14
|
+
{
|
|
15
|
+
className: "theme-doc-version-badge badge badge--secondary",
|
|
16
|
+
children: `Version: ${escape(version)}`,
|
|
17
|
+
},
|
|
18
|
+
{ inline: true }
|
|
19
|
+
),
|
|
20
|
+
`\n\n`,
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
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 { createAuthentication } from "./createAuthentication";
|
|
9
|
+
import { createAuthorization } from "./createAuthorization";
|
|
10
|
+
import { createCallbacks } from "./createCallbacks";
|
|
11
|
+
import { createContactInfo } from "./createContactInfo";
|
|
12
|
+
import { createDeprecationNotice } from "./createDeprecationNotice";
|
|
13
|
+
import { createDescription } from "./createDescription";
|
|
14
|
+
import { createDownload } from "./createDownload";
|
|
15
|
+
import { createHeading } from "./createHeading";
|
|
16
|
+
import { createLicense } from "./createLicense";
|
|
17
|
+
import { createLogo } from "./createLogo";
|
|
18
|
+
import { createMethodEndpoint } from "./createMethodEndpoint";
|
|
19
|
+
import { createParamsDetails } from "./createParamsDetails";
|
|
20
|
+
import { createRequestBodyDetails } from "./createRequestBodyDetails";
|
|
21
|
+
import { createRequestHeader } from "./createRequestHeader";
|
|
22
|
+
import { createStatusCodes } from "./createStatusCodes";
|
|
23
|
+
import { createTermsOfService } from "./createTermsOfService";
|
|
24
|
+
import { createVendorExtensions } from "./createVendorExtensions";
|
|
25
|
+
import { createVersionBadge } from "./createVersionBadge";
|
|
26
|
+
import { create, greaterThan, lessThan, render } from "./utils";
|
|
27
|
+
import {
|
|
28
|
+
ContactObject,
|
|
29
|
+
LicenseObject,
|
|
30
|
+
MediaTypeObject,
|
|
31
|
+
SecuritySchemeObject,
|
|
32
|
+
} from "../openapi/types";
|
|
33
|
+
import {
|
|
34
|
+
ApiPageMetadata,
|
|
35
|
+
InfoPageMetadata,
|
|
36
|
+
SchemaPageMetadata,
|
|
37
|
+
TagPageMetadata,
|
|
38
|
+
} from "../types";
|
|
39
|
+
|
|
40
|
+
interface RequestBodyProps {
|
|
41
|
+
title: string;
|
|
42
|
+
body: {
|
|
43
|
+
content?: {
|
|
44
|
+
[key: string]: MediaTypeObject;
|
|
45
|
+
};
|
|
46
|
+
description?: string;
|
|
47
|
+
required?: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createApiPageMD({
|
|
52
|
+
title,
|
|
53
|
+
api: {
|
|
54
|
+
deprecated,
|
|
55
|
+
"x-deprecated-description": deprecatedDescription,
|
|
56
|
+
description,
|
|
57
|
+
method,
|
|
58
|
+
path,
|
|
59
|
+
extensions,
|
|
60
|
+
parameters,
|
|
61
|
+
requestBody,
|
|
62
|
+
responses,
|
|
63
|
+
callbacks,
|
|
64
|
+
},
|
|
65
|
+
infoPath,
|
|
66
|
+
frontMatter,
|
|
67
|
+
}: ApiPageMetadata) {
|
|
68
|
+
return render([
|
|
69
|
+
`import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";\n`,
|
|
70
|
+
`import ParamsDetails from "@theme/ParamsDetails";\n`,
|
|
71
|
+
`import RequestSchema from "@theme/RequestSchema";\n`,
|
|
72
|
+
`import StatusCodes from "@theme/StatusCodes";\n`,
|
|
73
|
+
`import OperationTabs from "@theme/OperationTabs";\n`,
|
|
74
|
+
`import TabItem from "@theme/TabItem";\n`,
|
|
75
|
+
`import Heading from "@theme/Heading";\n\n`,
|
|
76
|
+
createHeading(title),
|
|
77
|
+
createMethodEndpoint(method, path),
|
|
78
|
+
infoPath && createAuthorization(infoPath),
|
|
79
|
+
frontMatter.show_extensions
|
|
80
|
+
? createVendorExtensions(extensions)
|
|
81
|
+
: undefined,
|
|
82
|
+
createDeprecationNotice({ deprecated, description: deprecatedDescription }),
|
|
83
|
+
createDescription(description),
|
|
84
|
+
requestBody || parameters ? createRequestHeader("Request") : undefined,
|
|
85
|
+
createParamsDetails({ parameters }),
|
|
86
|
+
createRequestBodyDetails({
|
|
87
|
+
title: "Body",
|
|
88
|
+
body: requestBody,
|
|
89
|
+
} as RequestBodyProps),
|
|
90
|
+
createStatusCodes({ responses }),
|
|
91
|
+
createCallbacks({ callbacks }),
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function createInfoPageMD({
|
|
96
|
+
info: {
|
|
97
|
+
title,
|
|
98
|
+
version,
|
|
99
|
+
description,
|
|
100
|
+
contact,
|
|
101
|
+
license,
|
|
102
|
+
termsOfService,
|
|
103
|
+
logo,
|
|
104
|
+
darkLogo,
|
|
105
|
+
},
|
|
106
|
+
securitySchemes,
|
|
107
|
+
downloadUrl,
|
|
108
|
+
}: InfoPageMetadata) {
|
|
109
|
+
return render([
|
|
110
|
+
`import ApiLogo from "@theme/ApiLogo";\n`,
|
|
111
|
+
`import Heading from "@theme/Heading";\n`,
|
|
112
|
+
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
113
|
+
`import TabItem from "@theme/TabItem";\n`,
|
|
114
|
+
`import Export from "@theme/ApiExplorer/Export";\n\n`,
|
|
115
|
+
|
|
116
|
+
createVersionBadge(version),
|
|
117
|
+
createDownload(downloadUrl),
|
|
118
|
+
createHeading(title),
|
|
119
|
+
createLogo(logo, darkLogo),
|
|
120
|
+
createDescription(description),
|
|
121
|
+
createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
|
|
122
|
+
createContactInfo(contact as ContactObject),
|
|
123
|
+
createTermsOfService(termsOfService),
|
|
124
|
+
createLicense(license as LicenseObject),
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function createTagPageMD({ tag: { description } }: TagPageMetadata) {
|
|
129
|
+
return render([createDescription(description)]);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function createSchemaPageMD({ schema }: SchemaPageMetadata) {
|
|
133
|
+
const { title = "", description } = schema;
|
|
134
|
+
return render([
|
|
135
|
+
`import Schema from "@theme/Schema";\n`,
|
|
136
|
+
`import Heading from "@theme/Heading";\n\n`,
|
|
137
|
+
createHeading(title.replace(lessThan, "<").replace(greaterThan, ">")),
|
|
138
|
+
createDescription(description),
|
|
139
|
+
create("Schema", {
|
|
140
|
+
schema: schema,
|
|
141
|
+
schemaType: "response",
|
|
142
|
+
}),
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
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 { getQualifierMessage } from "./schema";
|
|
9
|
+
|
|
10
|
+
describe("getQualifierMessage", () => {
|
|
11
|
+
it("should render nothing", () => {
|
|
12
|
+
const actual = getQualifierMessage({});
|
|
13
|
+
expect(actual).toBeUndefined();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
//
|
|
17
|
+
// minLength + maxLength
|
|
18
|
+
//
|
|
19
|
+
it("should render minLength", () => {
|
|
20
|
+
const expected = "**Possible values:** `non-empty`";
|
|
21
|
+
const actual = getQualifierMessage({ minLength: 1 });
|
|
22
|
+
expect(actual).toBe(expected);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should render maxLength", () => {
|
|
26
|
+
const expected = "**Possible values:** `<= 40 characters`";
|
|
27
|
+
const actual = getQualifierMessage({ maxLength: 40 });
|
|
28
|
+
expect(actual).toBe(expected);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should render minLength and maxLength", () => {
|
|
32
|
+
const expected = "**Possible values:** `non-empty` and `<= 40 characters`";
|
|
33
|
+
const actual = getQualifierMessage({ minLength: 1, maxLength: 40 });
|
|
34
|
+
expect(actual).toBe(expected);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
// pattern
|
|
39
|
+
//
|
|
40
|
+
it("should render pattern", () => {
|
|
41
|
+
const expected =
|
|
42
|
+
"**Possible values:** Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
43
|
+
const actual = getQualifierMessage({ pattern: "^[a-zA-Z0-9_-]*$" });
|
|
44
|
+
expect(actual).toBe(expected);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should render multiple string qualifiers", () => {
|
|
48
|
+
const expected =
|
|
49
|
+
"**Possible values:** `non-empty` and `<= 40 characters`, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
50
|
+
const actual = getQualifierMessage({
|
|
51
|
+
minLength: 1,
|
|
52
|
+
maxLength: 40,
|
|
53
|
+
pattern: "^[a-zA-Z0-9_-]*$",
|
|
54
|
+
});
|
|
55
|
+
expect(actual).toBe(expected);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
//
|
|
59
|
+
// enum
|
|
60
|
+
//
|
|
61
|
+
it("should render enum", () => {
|
|
62
|
+
const expected = "**Possible values:** [`cat`, `dog`, `mouse`]";
|
|
63
|
+
const actual = getQualifierMessage({ enum: ["cat", "dog", "mouse"] });
|
|
64
|
+
expect(actual).toBe(expected);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//
|
|
68
|
+
// minimum + maximum + exclusiveMinimum + exclusiveMaximum
|
|
69
|
+
//
|
|
70
|
+
it("should render minimum", () => {
|
|
71
|
+
const expected = "**Possible values:** `>= 1`";
|
|
72
|
+
const actual = getQualifierMessage({ minimum: 1 });
|
|
73
|
+
expect(actual).toBe(expected);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should render maximum", () => {
|
|
77
|
+
const expected = "**Possible values:** `<= 40`";
|
|
78
|
+
const actual = getQualifierMessage({ maximum: 40 });
|
|
79
|
+
expect(actual).toBe(expected);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should render numeric exclusiveMinimum", () => {
|
|
83
|
+
const expected = "**Possible values:** `> 1`";
|
|
84
|
+
const actual = getQualifierMessage({ exclusiveMinimum: 1 });
|
|
85
|
+
expect(actual).toBe(expected);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should render numeric exclusiveMaximum", () => {
|
|
89
|
+
const expected = "**Possible values:** `< 40`";
|
|
90
|
+
const actual = getQualifierMessage({ exclusiveMaximum: 40 });
|
|
91
|
+
expect(actual).toBe(expected);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should render boolean exclusiveMinimum", () => {
|
|
95
|
+
const expected = "**Possible values:** `> 1`";
|
|
96
|
+
const actual = getQualifierMessage({ minimum: 1, exclusiveMinimum: true });
|
|
97
|
+
expect(actual).toBe(expected);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("should render boolean exclusiveMaximum", () => {
|
|
101
|
+
const expected = "**Possible values:** `< 40`";
|
|
102
|
+
const actual = getQualifierMessage({ maximum: 40, exclusiveMaximum: true });
|
|
103
|
+
expect(actual).toBe(expected);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should render minimum when exclusiveMinimum is false", () => {
|
|
107
|
+
const expected = "**Possible values:** `>= 1`";
|
|
108
|
+
const actual = getQualifierMessage({ minimum: 1, exclusiveMinimum: false });
|
|
109
|
+
expect(actual).toBe(expected);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should render maximum when exclusiveMaximum is false", () => {
|
|
113
|
+
const expected = "**Possible values:** `<= 40`";
|
|
114
|
+
const actual = getQualifierMessage({
|
|
115
|
+
maximum: 40,
|
|
116
|
+
exclusiveMaximum: false,
|
|
117
|
+
});
|
|
118
|
+
expect(actual).toBe(expected);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should render minimum and maximum", () => {
|
|
122
|
+
const expected = "**Possible values:** `>= 1` and `<= 40`";
|
|
123
|
+
const actual = getQualifierMessage({ minimum: 1, maximum: 40 });
|
|
124
|
+
expect(actual).toBe(expected);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should render 0 minimum and maximum", () => {
|
|
128
|
+
const expected = "**Possible values:** `>= 0` and `<= 40`";
|
|
129
|
+
const actual = getQualifierMessage({ minimum: 0, maximum: 40 });
|
|
130
|
+
expect(actual).toBe(expected);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should render minimum and 0 maximum", () => {
|
|
134
|
+
const expected = "**Possible values:** `>= -10` and `<= 0`";
|
|
135
|
+
const actual = getQualifierMessage({ minimum: -10, maximum: 0 });
|
|
136
|
+
expect(actual).toBe(expected);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should render boolean exclusiveMinimum and maximum", () => {
|
|
140
|
+
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
141
|
+
const actual = getQualifierMessage({
|
|
142
|
+
minimum: 1,
|
|
143
|
+
maximum: 40,
|
|
144
|
+
exclusiveMinimum: true,
|
|
145
|
+
});
|
|
146
|
+
expect(actual).toBe(expected);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should render minimum and boolean exclusiveMaximum", () => {
|
|
150
|
+
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
151
|
+
const actual = getQualifierMessage({
|
|
152
|
+
minimum: 1,
|
|
153
|
+
maximum: 40,
|
|
154
|
+
exclusiveMaximum: true,
|
|
155
|
+
});
|
|
156
|
+
expect(actual).toBe(expected);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("should render numeric exclusiveMinimum and maximum", () => {
|
|
160
|
+
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
161
|
+
const actual = getQualifierMessage({
|
|
162
|
+
exclusiveMinimum: 1,
|
|
163
|
+
maximum: 40,
|
|
164
|
+
});
|
|
165
|
+
expect(actual).toBe(expected);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("should render minimum and numeric exclusiveMaximum", () => {
|
|
169
|
+
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
170
|
+
const actual = getQualifierMessage({
|
|
171
|
+
minimum: 1,
|
|
172
|
+
exclusiveMaximum: 40,
|
|
173
|
+
});
|
|
174
|
+
expect(actual).toBe(expected);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
|
|
178
|
+
const expected = "**Possible values:** `> 1` and `< 40`";
|
|
179
|
+
const actual = getQualifierMessage({
|
|
180
|
+
exclusiveMinimum: 1,
|
|
181
|
+
maximum: 40,
|
|
182
|
+
exclusiveMaximum: true,
|
|
183
|
+
});
|
|
184
|
+
expect(actual).toBe(expected);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("should render nothing with empty boolean exclusiveMinimum", () => {
|
|
188
|
+
const actual = getQualifierMessage({
|
|
189
|
+
exclusiveMinimum: true,
|
|
190
|
+
});
|
|
191
|
+
expect(actual).toBeUndefined();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should render nothing with empty boolean exclusiveMaximum", () => {
|
|
195
|
+
const actual = getQualifierMessage({
|
|
196
|
+
exclusiveMaximum: true,
|
|
197
|
+
});
|
|
198
|
+
expect(actual).toBeUndefined();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("should render nothing with empty boolean exclusiveMinimum and exclusiveMaximum", () => {
|
|
202
|
+
const actual = getQualifierMessage({
|
|
203
|
+
exclusiveMinimum: true,
|
|
204
|
+
exclusiveMaximum: true,
|
|
205
|
+
});
|
|
206
|
+
expect(actual).toBeUndefined();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
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 { SchemaObject } from "../openapi/types";
|
|
9
|
+
|
|
10
|
+
function prettyName(schema: SchemaObject, circular?: boolean) {
|
|
11
|
+
if (schema.format) {
|
|
12
|
+
return schema.format;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (schema.allOf) {
|
|
16
|
+
if (typeof schema.allOf[0] === "string") {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
if (schema.allOf[0].includes("circular")) {
|
|
19
|
+
return schema.allOf[0];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return "object";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (schema.oneOf) {
|
|
26
|
+
return "object";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (schema.anyOf) {
|
|
30
|
+
return "object";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (schema.type === "object") {
|
|
34
|
+
return schema.xml?.name ?? schema.type;
|
|
35
|
+
// return schema.type;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (schema.type === "array") {
|
|
39
|
+
return schema.xml?.name ?? schema.type;
|
|
40
|
+
// return schema.type;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (schema.title && schema.type) {
|
|
44
|
+
return `${schema.title} (${schema.type})`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return schema.title ?? schema.type;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getSchemaName(
|
|
51
|
+
schema: SchemaObject,
|
|
52
|
+
circular?: boolean
|
|
53
|
+
): string {
|
|
54
|
+
if (schema.items) {
|
|
55
|
+
return prettyName(schema.items, circular) + "[]";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return prettyName(schema, circular) ?? "";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function getQualifierMessage(schema?: SchemaObject): string | undefined {
|
|
62
|
+
// TODO:
|
|
63
|
+
// - uniqueItems
|
|
64
|
+
// - maxProperties
|
|
65
|
+
// - minProperties
|
|
66
|
+
// - multipleOf
|
|
67
|
+
if (!schema) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (
|
|
72
|
+
schema.items &&
|
|
73
|
+
schema.minItems === undefined &&
|
|
74
|
+
schema.maxItems === undefined
|
|
75
|
+
) {
|
|
76
|
+
return getQualifierMessage(schema.items);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let message = "**Possible values:** ";
|
|
80
|
+
|
|
81
|
+
let qualifierGroups = [];
|
|
82
|
+
|
|
83
|
+
if (schema.items && schema.items.enum) {
|
|
84
|
+
if (schema.items.enum) {
|
|
85
|
+
qualifierGroups.push(
|
|
86
|
+
`[${schema.items.enum.map((e) => `\`${e}\``).join(", ")}]`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (schema.minLength || schema.maxLength) {
|
|
92
|
+
let lengthQualifier = "";
|
|
93
|
+
let minLength;
|
|
94
|
+
let maxLength;
|
|
95
|
+
if (schema.minLength && schema.minLength > 1) {
|
|
96
|
+
minLength = `\`>= ${schema.minLength} characters\``;
|
|
97
|
+
}
|
|
98
|
+
if (schema.minLength && schema.minLength === 1) {
|
|
99
|
+
minLength = `\`non-empty\``;
|
|
100
|
+
}
|
|
101
|
+
if (schema.maxLength) {
|
|
102
|
+
maxLength = `\`<= ${schema.maxLength} characters\``;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (minLength && !maxLength) {
|
|
106
|
+
lengthQualifier += minLength;
|
|
107
|
+
}
|
|
108
|
+
if (maxLength && !minLength) {
|
|
109
|
+
lengthQualifier += maxLength;
|
|
110
|
+
}
|
|
111
|
+
if (minLength && maxLength) {
|
|
112
|
+
lengthQualifier += `${minLength} and ${maxLength}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
qualifierGroups.push(lengthQualifier);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (
|
|
119
|
+
schema.minimum != null ||
|
|
120
|
+
schema.maximum != null ||
|
|
121
|
+
typeof schema.exclusiveMinimum === "number" ||
|
|
122
|
+
typeof schema.exclusiveMaximum === "number"
|
|
123
|
+
) {
|
|
124
|
+
let minmaxQualifier = "";
|
|
125
|
+
let minimum;
|
|
126
|
+
let maximum;
|
|
127
|
+
if (typeof schema.exclusiveMinimum === "number") {
|
|
128
|
+
minimum = `\`> ${schema.exclusiveMinimum}\``;
|
|
129
|
+
} else if (schema.minimum != null && !schema.exclusiveMinimum) {
|
|
130
|
+
minimum = `\`>= ${schema.minimum}\``;
|
|
131
|
+
} else if (schema.minimum != null && schema.exclusiveMinimum === true) {
|
|
132
|
+
minimum = `\`> ${schema.minimum}\``;
|
|
133
|
+
}
|
|
134
|
+
if (typeof schema.exclusiveMaximum === "number") {
|
|
135
|
+
maximum = `\`< ${schema.exclusiveMaximum}\``;
|
|
136
|
+
} else if (schema.maximum != null && !schema.exclusiveMaximum) {
|
|
137
|
+
maximum = `\`<= ${schema.maximum}\``;
|
|
138
|
+
} else if (schema.maximum != null && schema.exclusiveMaximum === true) {
|
|
139
|
+
maximum = `\`< ${schema.maximum}\``;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (minimum && !maximum) {
|
|
143
|
+
minmaxQualifier += minimum;
|
|
144
|
+
}
|
|
145
|
+
if (maximum && !minimum) {
|
|
146
|
+
minmaxQualifier += maximum;
|
|
147
|
+
}
|
|
148
|
+
if (minimum && maximum) {
|
|
149
|
+
minmaxQualifier += `${minimum} and ${maximum}`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
qualifierGroups.push(minmaxQualifier);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (schema.pattern) {
|
|
156
|
+
qualifierGroups.push(
|
|
157
|
+
`Value must match regular expression \`${schema.pattern}\``
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Check if discriminator mapping
|
|
162
|
+
const discriminator = schema as any;
|
|
163
|
+
if (discriminator.mapping) {
|
|
164
|
+
const values = Object.keys(discriminator.mapping);
|
|
165
|
+
qualifierGroups.push(`[${values.map((e) => `\`${e}\``).join(", ")}]`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (schema.enum) {
|
|
169
|
+
qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (schema.minItems) {
|
|
173
|
+
qualifierGroups.push(`\`>= ${schema.minItems}\``);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (schema.maxItems) {
|
|
177
|
+
qualifierGroups.push(`\`<= ${schema.maxItems}\``);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (qualifierGroups.length === 0) {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return message + qualifierGroups.join(", ");
|
|
185
|
+
}
|