@camunda8/docusaurus-plugin-openapi-docs 4.5.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.
- package/README.md +386 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +714 -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 +173 -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 +23 -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 +93 -0
- package/lib/markdown/schema.d.ts +3 -0
- package/lib/markdown/schema.js +157 -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 +14 -0
- package/lib/openapi/createResponseExample.d.ts +2 -0
- package/lib/openapi/createResponseExample.js +14 -0
- package/lib/openapi/createSchemaExample.d.ts +7 -0
- package/lib/openapi/createSchemaExample.js +231 -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 +634 -0
- package/lib/openapi/openapi.test.d.ts +1 -0
- package/lib/openapi/openapi.test.js +33 -0
- package/lib/openapi/sdkExamples.d.ts +39 -0
- package/lib/openapi/sdkExamples.js +141 -0
- package/lib/openapi/types.d.ts +352 -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 +307 -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/openapi/webhooks.test.d.ts +1 -0
- package/lib/openapi/webhooks.test.js +23 -0
- package/lib/options.d.ts +2 -0
- package/lib/options.js +70 -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 +138 -0
- package/lib/types.js +8 -0
- package/package.json +68 -0
- package/src/index.ts +955 -0
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +1605 -0
- package/src/markdown/createArrayBracket.ts +35 -0
- package/src/markdown/createAuthentication.ts +209 -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 +22 -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 +864 -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 +145 -0
- package/src/markdown/schema.test.ts +208 -0
- package/src/markdown/schema.ts +188 -0
- package/src/markdown/utils.ts +89 -0
- package/src/openapi/__fixtures__/examples/openapi.yaml +49 -0
- package/src/openapi/__fixtures__/webhook/openapi.yaml +17 -0
- package/src/openapi/createRequestExample.ts +13 -0
- package/src/openapi/createResponseExample.ts +13 -0
- package/src/openapi/createSchemaExample.ts +292 -0
- package/src/openapi/index.ts +8 -0
- package/src/openapi/openapi.test.ts +40 -0
- package/src/openapi/openapi.ts +772 -0
- package/src/openapi/sdkExamples.ts +195 -0
- package/src/openapi/types.ts +458 -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 +304 -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/webhooks.test.ts +30 -0
- package/src/openapi-to-postmanv2.d.ts +10 -0
- package/src/options.ts +78 -0
- package/src/plugin-openapi.d.ts +88 -0
- package/src/sidebars/index.ts +322 -0
- package/src/sidebars/utils.ts +29 -0
- package/src/types.ts +180 -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,14 @@
|
|
|
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.sampleRequestFromSchema = void 0;
|
|
10
|
+
const createSchemaExample_1 = require("./createSchemaExample");
|
|
11
|
+
const sampleRequestFromSchema = (schema = {}) => {
|
|
12
|
+
return (0, createSchemaExample_1.sampleFromSchema)(schema, { type: "request" });
|
|
13
|
+
};
|
|
14
|
+
exports.sampleRequestFromSchema = sampleRequestFromSchema;
|
|
@@ -0,0 +1,14 @@
|
|
|
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.sampleResponseFromSchema = void 0;
|
|
10
|
+
const createSchemaExample_1 = require("./createSchemaExample");
|
|
11
|
+
const sampleResponseFromSchema = (schema = {}) => {
|
|
12
|
+
return (0, createSchemaExample_1.sampleFromSchema)(schema, { type: "response" });
|
|
13
|
+
};
|
|
14
|
+
exports.sampleResponseFromSchema = sampleResponseFromSchema;
|
|
@@ -0,0 +1,231 @@
|
|
|
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.sampleFromSchema = 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
|
+
null: {
|
|
40
|
+
default: () => "null",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
function shouldExcludeProperty(prop, context) {
|
|
44
|
+
if (prop.deprecated) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (context.type === "request") {
|
|
48
|
+
return prop.readOnly === true;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return prop.writeOnly === true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function sampleFromProp(name, prop, obj, context) {
|
|
55
|
+
// Handle resolved circular props
|
|
56
|
+
if (typeof prop === "object" && Object.keys(prop).length === 0) {
|
|
57
|
+
obj[name] = prop;
|
|
58
|
+
return obj;
|
|
59
|
+
}
|
|
60
|
+
// TODO: handle discriminators
|
|
61
|
+
if (prop.oneOf) {
|
|
62
|
+
obj[name] = (0, exports.sampleFromSchema)(prop.oneOf[0], context);
|
|
63
|
+
}
|
|
64
|
+
else if (prop.anyOf) {
|
|
65
|
+
obj[name] = (0, exports.sampleFromSchema)(prop.anyOf[0], context);
|
|
66
|
+
}
|
|
67
|
+
else if (prop.allOf) {
|
|
68
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(prop);
|
|
69
|
+
sampleFromProp(name, mergedSchemas, obj, context);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
obj[name] = (0, exports.sampleFromSchema)(prop, context);
|
|
73
|
+
}
|
|
74
|
+
return obj;
|
|
75
|
+
}
|
|
76
|
+
const sampleFromSchema = (schema = {}, context) => {
|
|
77
|
+
try {
|
|
78
|
+
// deep copy schema before processing
|
|
79
|
+
let schemaCopy = JSON.parse(JSON.stringify(schema));
|
|
80
|
+
let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
|
|
81
|
+
if (example !== undefined) {
|
|
82
|
+
return example;
|
|
83
|
+
}
|
|
84
|
+
if (oneOf) {
|
|
85
|
+
if (properties) {
|
|
86
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, oneOf[0]);
|
|
87
|
+
delete combinedSchemas.oneOf;
|
|
88
|
+
return (0, exports.sampleFromSchema)(combinedSchemas, context);
|
|
89
|
+
}
|
|
90
|
+
// Just go with first schema
|
|
91
|
+
return (0, exports.sampleFromSchema)(oneOf[0], context);
|
|
92
|
+
}
|
|
93
|
+
if (anyOf) {
|
|
94
|
+
if (properties) {
|
|
95
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, anyOf[0]);
|
|
96
|
+
delete combinedSchemas.anyOf;
|
|
97
|
+
return (0, exports.sampleFromSchema)(combinedSchemas, context);
|
|
98
|
+
}
|
|
99
|
+
// Just go with first schema
|
|
100
|
+
return (0, exports.sampleFromSchema)(anyOf[0], context);
|
|
101
|
+
}
|
|
102
|
+
if (allOf) {
|
|
103
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(schemaCopy);
|
|
104
|
+
if (mergedSchemas.properties) {
|
|
105
|
+
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
106
|
+
if (shouldExcludeProperty(value, context)) {
|
|
107
|
+
delete mergedSchemas.properties[key];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (properties) {
|
|
112
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, mergedSchemas);
|
|
113
|
+
delete combinedSchemas.allOf;
|
|
114
|
+
return (0, exports.sampleFromSchema)(combinedSchemas, context);
|
|
115
|
+
}
|
|
116
|
+
return (0, exports.sampleFromSchema)(mergedSchemas, context);
|
|
117
|
+
}
|
|
118
|
+
if (!type) {
|
|
119
|
+
if (properties) {
|
|
120
|
+
type = "object";
|
|
121
|
+
}
|
|
122
|
+
else if (items) {
|
|
123
|
+
type = "array";
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (type === "object") {
|
|
130
|
+
let obj = {};
|
|
131
|
+
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
132
|
+
if (prop.properties) {
|
|
133
|
+
for (const [key, value] of Object.entries(prop.properties)) {
|
|
134
|
+
if (shouldExcludeProperty(value, context)) {
|
|
135
|
+
delete prop.properties[key];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (prop.items && prop.items.properties) {
|
|
140
|
+
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
141
|
+
if (shouldExcludeProperty(value, context)) {
|
|
142
|
+
delete prop.items.properties[key];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (shouldExcludeProperty(prop, context)) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
// Resolve schema from prop recursively
|
|
150
|
+
obj = sampleFromProp(name, prop, obj, context);
|
|
151
|
+
}
|
|
152
|
+
return obj;
|
|
153
|
+
}
|
|
154
|
+
if (type === "array") {
|
|
155
|
+
if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
|
|
156
|
+
return processArrayItems(items, "anyOf", context);
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
|
|
159
|
+
return processArrayItems(items, "oneOf", context);
|
|
160
|
+
}
|
|
161
|
+
return normalizeArray((0, exports.sampleFromSchema)(items, context));
|
|
162
|
+
}
|
|
163
|
+
if (schemaCopy.enum) {
|
|
164
|
+
if (schemaCopy.default) {
|
|
165
|
+
return schemaCopy.default;
|
|
166
|
+
}
|
|
167
|
+
return normalizeArray(schemaCopy.enum)[0];
|
|
168
|
+
}
|
|
169
|
+
if (shouldExcludeProperty(schemaCopy, context)) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
return primitive(schemaCopy);
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
console.error(chalk_1.default.yellow("WARNING: failed to create example from schema object:", err));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
exports.sampleFromSchema = sampleFromSchema;
|
|
180
|
+
function primitive(schema = {}) {
|
|
181
|
+
let { type, format } = schema;
|
|
182
|
+
if (type === undefined) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
// If type is an array, use the first type
|
|
186
|
+
if (Array.isArray(type)) {
|
|
187
|
+
type = type[0];
|
|
188
|
+
if (type === undefined) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Use schema default if available, otherwise use type default
|
|
193
|
+
if (schema.default !== undefined) {
|
|
194
|
+
return schema.default;
|
|
195
|
+
}
|
|
196
|
+
const typeConfig = primitives[type];
|
|
197
|
+
if (typeConfig) {
|
|
198
|
+
if (format !== undefined && typeConfig[format] !== undefined) {
|
|
199
|
+
return typeConfig[format](schema);
|
|
200
|
+
}
|
|
201
|
+
if (typeConfig.default !== undefined) {
|
|
202
|
+
return typeConfig.default(schema);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return "Unknown Type: " + schema.type;
|
|
206
|
+
}
|
|
207
|
+
function normalizeArray(arr) {
|
|
208
|
+
if (Array.isArray(arr)) {
|
|
209
|
+
return arr;
|
|
210
|
+
}
|
|
211
|
+
return [arr];
|
|
212
|
+
}
|
|
213
|
+
function processArrayItems(items, schemaType, context) {
|
|
214
|
+
const itemsArray = items[schemaType];
|
|
215
|
+
return itemsArray.map((item) => {
|
|
216
|
+
// If items has properties, merge them with each item
|
|
217
|
+
if (items.properties) {
|
|
218
|
+
const combinedSchema = {
|
|
219
|
+
...item,
|
|
220
|
+
properties: {
|
|
221
|
+
...items.properties, // Common properties from parent
|
|
222
|
+
...item.properties, // Specific properties from this anyOf/oneOf item
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
// Remove anyOf/oneOf to prevent infinite recursion when calling sampleFromSchema
|
|
226
|
+
delete combinedSchema[schemaType];
|
|
227
|
+
return (0, exports.sampleFromSchema)(combinedSchema, context);
|
|
228
|
+
}
|
|
229
|
+
return (0, exports.sampleFromSchema)(item, context);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
@@ -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, siteDir?: string): Promise<[ApiMetadata[], TagObject[][], TagGroupObject[]]>;
|
|
10
|
+
export declare function processOpenapiFile(openapiData: OpenApiObject, options: APIOptions, sidebarOptions: SidebarOptions, siteDir?: string): Promise<[ApiMetadata[], TagObject[], TagGroupObject[]]>;
|
|
11
|
+
export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
|
|
12
|
+
export {};
|