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,68 @@
|
|
|
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 });
|
|
9
|
+
exports.codeBlock = exports.curlyBrackets = exports.codeFence = exports.greaterThan = exports.lessThan = void 0;
|
|
10
|
+
exports.create = create;
|
|
11
|
+
exports.guard = guard;
|
|
12
|
+
exports.render = render;
|
|
13
|
+
exports.clean = clean;
|
|
14
|
+
function create(tag, props, options = {}) {
|
|
15
|
+
const { children, ...rest } = props;
|
|
16
|
+
let propString = "";
|
|
17
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
18
|
+
propString += `\n ${key}={${JSON.stringify(value)}}`;
|
|
19
|
+
}
|
|
20
|
+
let indentedChildren = render(children).replace(/^/gm, " ");
|
|
21
|
+
if (options.inline) {
|
|
22
|
+
propString += `\n children={${JSON.stringify(children)}}`;
|
|
23
|
+
indentedChildren = "";
|
|
24
|
+
}
|
|
25
|
+
propString += propString ? "\n" : "";
|
|
26
|
+
indentedChildren += indentedChildren ? "\n" : "";
|
|
27
|
+
return `<${tag}${propString}>\n${indentedChildren}</${tag}>`;
|
|
28
|
+
}
|
|
29
|
+
function guard(value, cb) {
|
|
30
|
+
if (!!value || value === 0) {
|
|
31
|
+
const children = cb(value);
|
|
32
|
+
return render(children);
|
|
33
|
+
}
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
function render(children) {
|
|
37
|
+
if (Array.isArray(children)) {
|
|
38
|
+
const filteredChildren = children.filter((c) => c !== undefined);
|
|
39
|
+
return filteredChildren
|
|
40
|
+
.map((i) => (Array.isArray(i) ? i.join("") : i))
|
|
41
|
+
.join("");
|
|
42
|
+
}
|
|
43
|
+
return children !== null && children !== void 0 ? children : "";
|
|
44
|
+
}
|
|
45
|
+
// Regex to selectively URL-encode '>' and '<' chars
|
|
46
|
+
exports.lessThan = /<=?(?!(=|button|\s?\/button|code|\s?\/code|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|thead|\s?\/thead|tbody|\s?\/tbody|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|bold|\s?\/bold|a|\s?\/a|table|\s?\/table|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|svg|\s?\/svg|div|\s?\/div|center|\s?\/center))/gu;
|
|
47
|
+
exports.greaterThan = /(?<!(button|code|details|summary|hr|br|span|strong|small|table|thead|tbody|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|bold|a|li|ol|ul|img|svg|div|center|\/|\s|"|'))>/gu;
|
|
48
|
+
exports.codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
49
|
+
exports.curlyBrackets = /([{}])/g;
|
|
50
|
+
exports.codeBlock = /(^```.*[\s\S]*?```$|`[^`].+?`)/gm;
|
|
51
|
+
function clean(value) {
|
|
52
|
+
if (!value) {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
let sections = value.split(exports.codeBlock);
|
|
56
|
+
for (let sectionIndex in sections) {
|
|
57
|
+
if (!sections[sectionIndex].startsWith("`")) {
|
|
58
|
+
sections[sectionIndex] = sections[sectionIndex]
|
|
59
|
+
.replace(exports.lessThan, "<")
|
|
60
|
+
.replace(exports.greaterThan, ">")
|
|
61
|
+
.replace(exports.codeFence, function (match) {
|
|
62
|
+
return match.replace(/\\>/g, ">");
|
|
63
|
+
})
|
|
64
|
+
.replace(exports.curlyBrackets, "\\$1");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return sections.join("");
|
|
68
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
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.sampleRequestFromSchema = void 0;
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
15
|
+
const createSchema_1 = require("../markdown/createSchema");
|
|
16
|
+
const primitives = {
|
|
17
|
+
string: {
|
|
18
|
+
default: () => "string",
|
|
19
|
+
email: () => "user@example.com",
|
|
20
|
+
date: () => "2024-07-29",
|
|
21
|
+
"date-time": () => "2024-07-29T15:51:28.071Z",
|
|
22
|
+
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
23
|
+
hostname: () => "example.com",
|
|
24
|
+
ipv4: () => "198.51.100.42",
|
|
25
|
+
ipv6: () => "2001:0db8:5b96:0000:0000:426f:8e17:642a",
|
|
26
|
+
},
|
|
27
|
+
number: {
|
|
28
|
+
default: () => 0,
|
|
29
|
+
float: () => 0.0,
|
|
30
|
+
},
|
|
31
|
+
integer: {
|
|
32
|
+
default: () => 0,
|
|
33
|
+
},
|
|
34
|
+
boolean: {
|
|
35
|
+
default: (schema) => typeof schema.default === "boolean" ? schema.default : true,
|
|
36
|
+
},
|
|
37
|
+
object: {},
|
|
38
|
+
array: {},
|
|
39
|
+
};
|
|
40
|
+
function sampleRequestFromProp(name, prop, obj) {
|
|
41
|
+
// Handle resolved circular props
|
|
42
|
+
if (typeof prop === "object" && Object.keys(prop).length === 0) {
|
|
43
|
+
obj[name] = prop;
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
// TODO: handle discriminators
|
|
47
|
+
if (prop.oneOf) {
|
|
48
|
+
obj[name] = (0, exports.sampleRequestFromSchema)(prop.oneOf[0]);
|
|
49
|
+
}
|
|
50
|
+
else if (prop.anyOf) {
|
|
51
|
+
obj[name] = (0, exports.sampleRequestFromSchema)(prop.anyOf[0]);
|
|
52
|
+
}
|
|
53
|
+
else if (prop.allOf) {
|
|
54
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(prop);
|
|
55
|
+
sampleRequestFromProp(name, mergedSchemas, obj);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
obj[name] = (0, exports.sampleRequestFromSchema)(prop);
|
|
59
|
+
}
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
const sampleRequestFromSchema = (schema = {}) => {
|
|
63
|
+
try {
|
|
64
|
+
// deep copy schema before processing
|
|
65
|
+
let schemaCopy = JSON.parse(JSON.stringify(schema));
|
|
66
|
+
let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
|
|
67
|
+
if (example !== undefined) {
|
|
68
|
+
return example;
|
|
69
|
+
}
|
|
70
|
+
if (oneOf) {
|
|
71
|
+
if (properties) {
|
|
72
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, oneOf[0]);
|
|
73
|
+
delete combinedSchemas.oneOf;
|
|
74
|
+
return (0, exports.sampleRequestFromSchema)(combinedSchemas);
|
|
75
|
+
}
|
|
76
|
+
// Just go with first schema
|
|
77
|
+
return (0, exports.sampleRequestFromSchema)(oneOf[0]);
|
|
78
|
+
}
|
|
79
|
+
if (anyOf) {
|
|
80
|
+
if (properties) {
|
|
81
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, anyOf[0]);
|
|
82
|
+
delete combinedSchemas.anyOf;
|
|
83
|
+
return (0, exports.sampleRequestFromSchema)(combinedSchemas);
|
|
84
|
+
}
|
|
85
|
+
// Just go with first schema
|
|
86
|
+
return (0, exports.sampleRequestFromSchema)(anyOf[0]);
|
|
87
|
+
}
|
|
88
|
+
if (allOf) {
|
|
89
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(schemaCopy);
|
|
90
|
+
if (mergedSchemas.properties) {
|
|
91
|
+
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
92
|
+
if ((value.readOnly && value.readOnly === true) || value.deprecated) {
|
|
93
|
+
delete mergedSchemas.properties[key];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (properties) {
|
|
98
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, mergedSchemas);
|
|
99
|
+
delete combinedSchemas.allOf;
|
|
100
|
+
return (0, exports.sampleRequestFromSchema)(combinedSchemas);
|
|
101
|
+
}
|
|
102
|
+
return (0, exports.sampleRequestFromSchema)(mergedSchemas);
|
|
103
|
+
}
|
|
104
|
+
if (!type) {
|
|
105
|
+
if (properties) {
|
|
106
|
+
type = "object";
|
|
107
|
+
}
|
|
108
|
+
else if (items) {
|
|
109
|
+
type = "array";
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (type === "object") {
|
|
116
|
+
let obj = {};
|
|
117
|
+
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
118
|
+
if (prop.properties) {
|
|
119
|
+
for (const [key, value] of Object.entries(prop.properties)) {
|
|
120
|
+
if ((value.readOnly && value.readOnly === true) ||
|
|
121
|
+
value.deprecated) {
|
|
122
|
+
delete prop.properties[key];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (prop.items && prop.items.properties) {
|
|
127
|
+
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
128
|
+
if ((value.readOnly && value.readOnly === true) ||
|
|
129
|
+
value.deprecated) {
|
|
130
|
+
delete prop.items.properties[key];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (prop.readOnly && prop.readOnly === true) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (prop.deprecated) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
// Resolve schema from prop recursively
|
|
141
|
+
obj = sampleRequestFromProp(name, prop, obj);
|
|
142
|
+
}
|
|
143
|
+
return obj;
|
|
144
|
+
}
|
|
145
|
+
if (type === "array") {
|
|
146
|
+
if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
|
|
147
|
+
return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleRequestFromSchema)(item));
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
|
|
150
|
+
return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleRequestFromSchema)(item));
|
|
151
|
+
}
|
|
152
|
+
return normalizeArray((0, exports.sampleRequestFromSchema)(items));
|
|
153
|
+
}
|
|
154
|
+
if (schemaCopy.enum) {
|
|
155
|
+
if (schemaCopy.default) {
|
|
156
|
+
return schemaCopy.default;
|
|
157
|
+
}
|
|
158
|
+
return normalizeArray(schemaCopy.enum)[0];
|
|
159
|
+
}
|
|
160
|
+
if ((schema.readOnly && schema.readOnly === true) ||
|
|
161
|
+
schemaCopy.deprecated) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
return primitive(schemaCopy);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
console.error(chalk_1.default.yellow("WARNING: failed to create example from schema object:", err));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
exports.sampleRequestFromSchema = sampleRequestFromSchema;
|
|
172
|
+
function primitive(schema = {}) {
|
|
173
|
+
let { type, format } = schema;
|
|
174
|
+
if (type === undefined) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
let fn = schema.default ? () => schema.default : primitives[type].default;
|
|
178
|
+
if (format !== undefined) {
|
|
179
|
+
fn = primitives[type][format] || fn;
|
|
180
|
+
}
|
|
181
|
+
if (fn) {
|
|
182
|
+
return fn(schema);
|
|
183
|
+
}
|
|
184
|
+
return "Unknown Type: " + schema.type;
|
|
185
|
+
}
|
|
186
|
+
function normalizeArray(arr) {
|
|
187
|
+
if (Array.isArray(arr)) {
|
|
188
|
+
return arr;
|
|
189
|
+
}
|
|
190
|
+
return [arr];
|
|
191
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
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.sampleResponseFromSchema = void 0;
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
15
|
+
const createSchema_1 = require("../markdown/createSchema");
|
|
16
|
+
const primitives = {
|
|
17
|
+
string: {
|
|
18
|
+
default: () => "string",
|
|
19
|
+
email: () => "user@example.com",
|
|
20
|
+
date: () => "2024-07-29",
|
|
21
|
+
"date-time": () => "2024-07-29T15:51:28.071Z",
|
|
22
|
+
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
23
|
+
hostname: () => "example.com",
|
|
24
|
+
ipv4: () => "198.51.100.42",
|
|
25
|
+
ipv6: () => "2001:0db8:5b96:0000:0000:426f:8e17:642a",
|
|
26
|
+
},
|
|
27
|
+
number: {
|
|
28
|
+
default: () => 0,
|
|
29
|
+
float: () => 0.0,
|
|
30
|
+
},
|
|
31
|
+
integer: {
|
|
32
|
+
default: () => 0,
|
|
33
|
+
},
|
|
34
|
+
boolean: {
|
|
35
|
+
default: (schema) => typeof schema.default === "boolean" ? schema.default : true,
|
|
36
|
+
},
|
|
37
|
+
object: {},
|
|
38
|
+
array: {},
|
|
39
|
+
};
|
|
40
|
+
function sampleResponseFromProp(name, prop, obj) {
|
|
41
|
+
// Handle resolved circular props
|
|
42
|
+
if (typeof prop === "object" && Object.keys(prop).length === 0) {
|
|
43
|
+
obj[name] = prop;
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
// TODO: handle discriminators
|
|
47
|
+
if (prop.oneOf) {
|
|
48
|
+
obj[name] = (0, exports.sampleResponseFromSchema)(prop.oneOf[0]);
|
|
49
|
+
}
|
|
50
|
+
else if (prop.anyOf) {
|
|
51
|
+
obj[name] = (0, exports.sampleResponseFromSchema)(prop.anyOf[0]);
|
|
52
|
+
}
|
|
53
|
+
else if (prop.allOf) {
|
|
54
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(prop);
|
|
55
|
+
sampleResponseFromProp(name, mergedSchemas, obj);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
obj[name] = (0, exports.sampleResponseFromSchema)(prop);
|
|
59
|
+
}
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
const sampleResponseFromSchema = (schema = {}) => {
|
|
63
|
+
try {
|
|
64
|
+
// deep copy schema before processing
|
|
65
|
+
let schemaCopy = JSON.parse(JSON.stringify(schema));
|
|
66
|
+
let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
|
|
67
|
+
if (example !== undefined) {
|
|
68
|
+
return example;
|
|
69
|
+
}
|
|
70
|
+
if (allOf) {
|
|
71
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(schemaCopy);
|
|
72
|
+
if (mergedSchemas.properties) {
|
|
73
|
+
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
74
|
+
if ((value.writeOnly && value.writeOnly === true) ||
|
|
75
|
+
value.deprecated) {
|
|
76
|
+
delete mergedSchemas.properties[key];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (properties) {
|
|
81
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, mergedSchemas);
|
|
82
|
+
delete combinedSchemas.allOf;
|
|
83
|
+
return (0, exports.sampleResponseFromSchema)(combinedSchemas);
|
|
84
|
+
}
|
|
85
|
+
return (0, exports.sampleResponseFromSchema)(mergedSchemas);
|
|
86
|
+
}
|
|
87
|
+
if (oneOf) {
|
|
88
|
+
if (properties) {
|
|
89
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, oneOf[0]);
|
|
90
|
+
delete combinedSchemas.oneOf;
|
|
91
|
+
return (0, exports.sampleResponseFromSchema)(combinedSchemas);
|
|
92
|
+
}
|
|
93
|
+
// Just go with first schema
|
|
94
|
+
return (0, exports.sampleResponseFromSchema)(oneOf[0]);
|
|
95
|
+
}
|
|
96
|
+
if (anyOf) {
|
|
97
|
+
if (properties) {
|
|
98
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, anyOf[0]);
|
|
99
|
+
delete combinedSchemas.anyOf;
|
|
100
|
+
return (0, exports.sampleResponseFromSchema)(combinedSchemas);
|
|
101
|
+
}
|
|
102
|
+
// Just go with first schema
|
|
103
|
+
return (0, exports.sampleResponseFromSchema)(anyOf[0]);
|
|
104
|
+
}
|
|
105
|
+
if (!type) {
|
|
106
|
+
if (properties) {
|
|
107
|
+
type = "object";
|
|
108
|
+
}
|
|
109
|
+
else if (items) {
|
|
110
|
+
type = "array";
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (type === "object") {
|
|
117
|
+
let obj = {};
|
|
118
|
+
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
119
|
+
if (prop.properties) {
|
|
120
|
+
for (const [key, value] of Object.entries(prop.properties)) {
|
|
121
|
+
if ((value.writeOnly && value.writeOnly === true) ||
|
|
122
|
+
value.deprecated) {
|
|
123
|
+
delete prop.properties[key];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (prop.items && prop.items.properties) {
|
|
128
|
+
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
129
|
+
if ((value.writeOnly && value.writeOnly === true) ||
|
|
130
|
+
value.deprecated) {
|
|
131
|
+
delete prop.items.properties[key];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (prop.writeOnly && prop.writeOnly === true) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (prop.deprecated) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// Resolve schema from prop recursively
|
|
142
|
+
obj = sampleResponseFromProp(name, prop, obj);
|
|
143
|
+
}
|
|
144
|
+
return obj;
|
|
145
|
+
}
|
|
146
|
+
if (type === "array") {
|
|
147
|
+
if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
|
|
148
|
+
return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleResponseFromSchema)(item));
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
|
|
151
|
+
return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleResponseFromSchema)(item));
|
|
152
|
+
}
|
|
153
|
+
return [(0, exports.sampleResponseFromSchema)(items)];
|
|
154
|
+
}
|
|
155
|
+
if (schemaCopy.enum) {
|
|
156
|
+
if (schemaCopy.default) {
|
|
157
|
+
return schemaCopy.default;
|
|
158
|
+
}
|
|
159
|
+
return normalizeArray(schemaCopy.enum)[0];
|
|
160
|
+
}
|
|
161
|
+
if ((schemaCopy.writeOnly && schemaCopy.writeOnly === true) ||
|
|
162
|
+
schemaCopy.deprecated) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
return primitive(schemaCopy);
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
console.error(chalk_1.default.yellow("WARNING: failed to create example from schema object:", err));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
exports.sampleResponseFromSchema = sampleResponseFromSchema;
|
|
173
|
+
function primitive(schema = {}) {
|
|
174
|
+
let { type, format } = schema;
|
|
175
|
+
if (type === undefined) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
let fn = schema.default ? () => schema.default : primitives[type].default;
|
|
179
|
+
if (format !== undefined) {
|
|
180
|
+
fn = primitives[type][format] || fn;
|
|
181
|
+
}
|
|
182
|
+
if (fn) {
|
|
183
|
+
return fn(schema);
|
|
184
|
+
}
|
|
185
|
+
return "Unknown Type: " + schema.type;
|
|
186
|
+
}
|
|
187
|
+
function normalizeArray(arr) {
|
|
188
|
+
if (Array.isArray(arr)) {
|
|
189
|
+
return arr;
|
|
190
|
+
}
|
|
191
|
+
return [arr];
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { readOpenapiFiles, processOpenapiFiles } from "./openapi";
|
|
@@ -0,0 +1,12 @@
|
|
|
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 });
|
|
9
|
+
exports.processOpenapiFiles = exports.readOpenapiFiles = void 0;
|
|
10
|
+
var openapi_1 = require("./openapi");
|
|
11
|
+
Object.defineProperty(exports, "readOpenapiFiles", { enumerable: true, get: function () { return openapi_1.readOpenapiFiles; } });
|
|
12
|
+
Object.defineProperty(exports, "processOpenapiFiles", { enumerable: true, get: function () { return openapi_1.processOpenapiFiles; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OpenApiObject, TagGroupObject, TagObject } from "./types";
|
|
2
|
+
import { ApiMetadata, APIOptions, SidebarOptions } from "../types";
|
|
3
|
+
interface OpenApiFiles {
|
|
4
|
+
source: string;
|
|
5
|
+
sourceDirName: string;
|
|
6
|
+
data: OpenApiObject;
|
|
7
|
+
}
|
|
8
|
+
export declare function readOpenapiFiles(openapiPath: string): Promise<OpenApiFiles[]>;
|
|
9
|
+
export declare function processOpenapiFiles(files: OpenApiFiles[], options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][], TagGroupObject[]]>;
|
|
10
|
+
export declare function processOpenapiFile(openapiData: OpenApiObject, options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[], TagGroupObject[]]>;
|
|
11
|
+
export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
|
|
12
|
+
export {};
|