docusaurus-plugin-openapi-docs 0.0.0-348 → 0.0.0-351
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/lib/index.d.ts +3 -0
- package/lib/index.js +194 -0
- package/lib/markdown/createContactInfo.d.ts +2 -0
- package/lib/markdown/createContactInfo.js +49 -0
- package/lib/markdown/createDeprecationNotice.d.ts +6 -0
- package/lib/markdown/createDeprecationNotice.js +19 -0
- package/lib/markdown/createDescription.d.ts +1 -0
- package/lib/markdown/createDescription.js +16 -0
- package/lib/markdown/createDetails.d.ts +2 -0
- package/lib/markdown/createDetails.js +18 -0
- package/lib/markdown/createDetailsSummary.d.ts +2 -0
- package/lib/markdown/createDetailsSummary.js +18 -0
- package/lib/markdown/createLicense.d.ts +2 -0
- package/lib/markdown/createLicense.js +33 -0
- package/lib/markdown/createParamsDetails.d.ts +7 -0
- package/lib/markdown/createParamsDetails.js +44 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +6 -0
- package/lib/markdown/createRequestBodyDetails.js +14 -0
- package/lib/markdown/createSchemaDetails.d.ts +14 -0
- package/lib/markdown/createSchemaDetails.js +244 -0
- package/lib/markdown/createStatusCodes.d.ts +6 -0
- package/lib/markdown/createStatusCodes.js +47 -0
- package/lib/markdown/createTermsOfService.d.ts +1 -0
- package/lib/markdown/createTermsOfService.js +32 -0
- package/lib/markdown/createVersionBadge.d.ts +1 -0
- package/lib/markdown/createVersionBadge.js +20 -0
- package/lib/markdown/index.d.ts +3 -0
- package/lib/markdown/index.js +49 -0
- package/lib/markdown/schema.d.ts +3 -0
- package/lib/markdown/schema.js +100 -0
- package/lib/markdown/schema.test.d.ts +1 -0
- package/lib/markdown/schema.test.js +171 -0
- package/lib/markdown/utils.d.ts +7 -0
- package/lib/markdown/utils.js +33 -0
- package/lib/openapi/createExample.d.ts +2 -0
- package/lib/openapi/createExample.js +113 -0
- package/lib/openapi/index.d.ts +1 -0
- package/lib/openapi/index.js +12 -0
- package/lib/openapi/openapi.d.ts +11 -0
- package/lib/openapi/openapi.js +231 -0
- package/lib/openapi/openapi.test.d.ts +1 -0
- package/lib/openapi/openapi.test.js +33 -0
- package/lib/openapi/types.d.ts +334 -0
- package/{src/markdown/createRequestBodyTable.ts → lib/openapi/types.js} +2 -11
- package/lib/options.d.ts +4 -0
- package/lib/options.js +18 -0
- package/lib/sidebars/index.d.ts +3 -0
- package/lib/sidebars/index.js +89 -0
- package/lib/types.d.ts +68 -0
- package/{src/markdown/createFullWidthTable.ts → lib/types.js} +2 -10
- package/package.json +2 -2
- package/src/markdown/createContactInfo.ts +48 -0
- package/src/markdown/createLicense.ts +32 -0
- package/src/markdown/createTermsOfService.ts +30 -0
- package/src/markdown/index.ts +8 -1
- package/src/openapi/types.ts +2 -0
- package/src/markdown/createParamsTable.ts +0 -102
- package/src/markdown/createSchemaTable.ts +0 -275
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
const schema_1 = require("./schema");
|
|
10
|
+
describe("getQualifierMessage", () => {
|
|
11
|
+
it("should render nothing", () => {
|
|
12
|
+
const actual = (0, schema_1.getQualifierMessage)({});
|
|
13
|
+
expect(actual).toBeUndefined();
|
|
14
|
+
});
|
|
15
|
+
//
|
|
16
|
+
// minLength + maxLength
|
|
17
|
+
//
|
|
18
|
+
it("should render minLength", () => {
|
|
19
|
+
const expected = "**Possible values:** 1 ≤ length";
|
|
20
|
+
const actual = (0, schema_1.getQualifierMessage)({ minLength: 1 });
|
|
21
|
+
expect(actual).toBe(expected);
|
|
22
|
+
});
|
|
23
|
+
it("should render maxLength", () => {
|
|
24
|
+
const expected = "**Possible values:** length ≤ 40";
|
|
25
|
+
const actual = (0, schema_1.getQualifierMessage)({ maxLength: 40 });
|
|
26
|
+
expect(actual).toBe(expected);
|
|
27
|
+
});
|
|
28
|
+
it("should render minLength and maxLength", () => {
|
|
29
|
+
const expected = "**Possible values:** 1 ≤ length ≤ 40";
|
|
30
|
+
const actual = (0, schema_1.getQualifierMessage)({ minLength: 1, maxLength: 40 });
|
|
31
|
+
expect(actual).toBe(expected);
|
|
32
|
+
});
|
|
33
|
+
//
|
|
34
|
+
// pattern
|
|
35
|
+
//
|
|
36
|
+
it("should render pattern", () => {
|
|
37
|
+
const expected = "**Possible values:** Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
38
|
+
const actual = (0, schema_1.getQualifierMessage)({ pattern: "^[a-zA-Z0-9_-]*$" });
|
|
39
|
+
expect(actual).toBe(expected);
|
|
40
|
+
});
|
|
41
|
+
it("should render multiple string qualifiers", () => {
|
|
42
|
+
const expected = "**Possible values:** 1 ≤ length ≤ 40, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
43
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
44
|
+
minLength: 1,
|
|
45
|
+
maxLength: 40,
|
|
46
|
+
pattern: "^[a-zA-Z0-9_-]*$",
|
|
47
|
+
});
|
|
48
|
+
expect(actual).toBe(expected);
|
|
49
|
+
});
|
|
50
|
+
//
|
|
51
|
+
// enum
|
|
52
|
+
//
|
|
53
|
+
it("should render enum", () => {
|
|
54
|
+
const expected = "**Possible values:** [`cat`, `dog`, `mouse`]";
|
|
55
|
+
const actual = (0, schema_1.getQualifierMessage)({ enum: ["cat", "dog", "mouse"] });
|
|
56
|
+
expect(actual).toBe(expected);
|
|
57
|
+
});
|
|
58
|
+
//
|
|
59
|
+
// minimum + maximum + exclusiveMinimum + exclusiveMaximum
|
|
60
|
+
//
|
|
61
|
+
it("should render minimum", () => {
|
|
62
|
+
const expected = "**Possible values:** 1 ≤ value";
|
|
63
|
+
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1 });
|
|
64
|
+
expect(actual).toBe(expected);
|
|
65
|
+
});
|
|
66
|
+
it("should render maximum", () => {
|
|
67
|
+
const expected = "**Possible values:** value ≤ 40";
|
|
68
|
+
const actual = (0, schema_1.getQualifierMessage)({ maximum: 40 });
|
|
69
|
+
expect(actual).toBe(expected);
|
|
70
|
+
});
|
|
71
|
+
it("should render numeric exclusiveMinimum", () => {
|
|
72
|
+
const expected = "**Possible values:** 1 < value";
|
|
73
|
+
const actual = (0, schema_1.getQualifierMessage)({ exclusiveMinimum: 1 });
|
|
74
|
+
expect(actual).toBe(expected);
|
|
75
|
+
});
|
|
76
|
+
it("should render numeric exclusiveMaximum", () => {
|
|
77
|
+
const expected = "**Possible values:** value < 40";
|
|
78
|
+
const actual = (0, schema_1.getQualifierMessage)({ exclusiveMaximum: 40 });
|
|
79
|
+
expect(actual).toBe(expected);
|
|
80
|
+
});
|
|
81
|
+
it("should render boolean exclusiveMinimum", () => {
|
|
82
|
+
const expected = "**Possible values:** 1 < value";
|
|
83
|
+
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: true });
|
|
84
|
+
expect(actual).toBe(expected);
|
|
85
|
+
});
|
|
86
|
+
it("should render boolean exclusiveMaximum", () => {
|
|
87
|
+
const expected = "**Possible values:** value < 40";
|
|
88
|
+
const actual = (0, schema_1.getQualifierMessage)({ maximum: 40, exclusiveMaximum: true });
|
|
89
|
+
expect(actual).toBe(expected);
|
|
90
|
+
});
|
|
91
|
+
it("should render minimum when exclusiveMinimum is false", () => {
|
|
92
|
+
const expected = "**Possible values:** 1 ≤ value";
|
|
93
|
+
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: false });
|
|
94
|
+
expect(actual).toBe(expected);
|
|
95
|
+
});
|
|
96
|
+
it("should render maximum when exclusiveMaximum is false", () => {
|
|
97
|
+
const expected = "**Possible values:** value ≤ 40";
|
|
98
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
99
|
+
maximum: 40,
|
|
100
|
+
exclusiveMaximum: false,
|
|
101
|
+
});
|
|
102
|
+
expect(actual).toBe(expected);
|
|
103
|
+
});
|
|
104
|
+
it("should render minimum and maximum", () => {
|
|
105
|
+
const expected = "**Possible values:** 1 ≤ value ≤ 40";
|
|
106
|
+
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, maximum: 40 });
|
|
107
|
+
expect(actual).toBe(expected);
|
|
108
|
+
});
|
|
109
|
+
it("should render boolean exclusiveMinimum and maximum", () => {
|
|
110
|
+
const expected = "**Possible values:** 1 < value ≤ 40";
|
|
111
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
112
|
+
minimum: 1,
|
|
113
|
+
maximum: 40,
|
|
114
|
+
exclusiveMinimum: true,
|
|
115
|
+
});
|
|
116
|
+
expect(actual).toBe(expected);
|
|
117
|
+
});
|
|
118
|
+
it("should render minimum and boolean exclusiveMaximum", () => {
|
|
119
|
+
const expected = "**Possible values:** 1 ≤ value < 40";
|
|
120
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
121
|
+
minimum: 1,
|
|
122
|
+
maximum: 40,
|
|
123
|
+
exclusiveMaximum: true,
|
|
124
|
+
});
|
|
125
|
+
expect(actual).toBe(expected);
|
|
126
|
+
});
|
|
127
|
+
it("should render numeric exclusiveMinimum and maximum", () => {
|
|
128
|
+
const expected = "**Possible values:** 1 < value ≤ 40";
|
|
129
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
130
|
+
exclusiveMinimum: 1,
|
|
131
|
+
maximum: 40,
|
|
132
|
+
});
|
|
133
|
+
expect(actual).toBe(expected);
|
|
134
|
+
});
|
|
135
|
+
it("should render minimum and numeric exclusiveMaximum", () => {
|
|
136
|
+
const expected = "**Possible values:** 1 ≤ value < 40";
|
|
137
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
138
|
+
minimum: 1,
|
|
139
|
+
exclusiveMaximum: 40,
|
|
140
|
+
});
|
|
141
|
+
expect(actual).toBe(expected);
|
|
142
|
+
});
|
|
143
|
+
it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
|
|
144
|
+
const expected = "**Possible values:** 1 < value < 40";
|
|
145
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
146
|
+
exclusiveMinimum: 1,
|
|
147
|
+
maximum: 40,
|
|
148
|
+
exclusiveMaximum: true,
|
|
149
|
+
});
|
|
150
|
+
expect(actual).toBe(expected);
|
|
151
|
+
});
|
|
152
|
+
it("should render nothing with empty boolean exclusiveMinimum", () => {
|
|
153
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
154
|
+
exclusiveMinimum: true,
|
|
155
|
+
});
|
|
156
|
+
expect(actual).toBeUndefined();
|
|
157
|
+
});
|
|
158
|
+
it("should render nothing with empty boolean exclusiveMaximum", () => {
|
|
159
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
160
|
+
exclusiveMaximum: true,
|
|
161
|
+
});
|
|
162
|
+
expect(actual).toBeUndefined();
|
|
163
|
+
});
|
|
164
|
+
it("should render nothing with empty boolean exclusiveMinimum and exclusiveMaximum", () => {
|
|
165
|
+
const actual = (0, schema_1.getQualifierMessage)({
|
|
166
|
+
exclusiveMinimum: true,
|
|
167
|
+
exclusiveMaximum: true,
|
|
168
|
+
});
|
|
169
|
+
expect(actual).toBeUndefined();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type Children = string | undefined | (string | undefined)[];
|
|
2
|
+
export declare type Props = Record<string, any> & {
|
|
3
|
+
children?: Children;
|
|
4
|
+
};
|
|
5
|
+
export declare function create(tag: string, props: Props): string;
|
|
6
|
+
export declare function guard<T>(value: T | undefined, cb: (value: T) => Children): string;
|
|
7
|
+
export declare function render(children: Children): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
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.render = exports.guard = exports.create = void 0;
|
|
10
|
+
function create(tag, props) {
|
|
11
|
+
const { children, ...rest } = props;
|
|
12
|
+
let propString = "";
|
|
13
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
14
|
+
propString += ` ${key}={${JSON.stringify(value)}}`;
|
|
15
|
+
}
|
|
16
|
+
return `<${tag}${propString}>${render(children)}</${tag}>`;
|
|
17
|
+
}
|
|
18
|
+
exports.create = create;
|
|
19
|
+
function guard(value, cb) {
|
|
20
|
+
if (value) {
|
|
21
|
+
const children = cb(value);
|
|
22
|
+
return render(children);
|
|
23
|
+
}
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
exports.guard = guard;
|
|
27
|
+
function render(children) {
|
|
28
|
+
if (Array.isArray(children)) {
|
|
29
|
+
return children.filter((c) => c !== undefined).join("");
|
|
30
|
+
}
|
|
31
|
+
return children !== null && children !== void 0 ? children : "";
|
|
32
|
+
}
|
|
33
|
+
exports.render = render;
|
|
@@ -0,0 +1,113 @@
|
|
|
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.sampleFromSchema = void 0;
|
|
10
|
+
const primitives = {
|
|
11
|
+
string: {
|
|
12
|
+
default: () => "string",
|
|
13
|
+
email: () => "user@example.com",
|
|
14
|
+
date: () => new Date().toISOString().substring(0, 10),
|
|
15
|
+
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
16
|
+
hostname: () => "example.com",
|
|
17
|
+
ipv4: () => "198.51.100.42",
|
|
18
|
+
ipv6: () => "2001:0db8:5b96:0000:0000:426f:8e17:642a",
|
|
19
|
+
},
|
|
20
|
+
number: {
|
|
21
|
+
default: () => 0,
|
|
22
|
+
float: () => 0.0,
|
|
23
|
+
},
|
|
24
|
+
integer: {
|
|
25
|
+
default: () => 0,
|
|
26
|
+
},
|
|
27
|
+
boolean: {
|
|
28
|
+
default: (schema) => typeof schema.default === "boolean" ? schema.default : true,
|
|
29
|
+
},
|
|
30
|
+
object: {},
|
|
31
|
+
array: {},
|
|
32
|
+
};
|
|
33
|
+
const sampleFromSchema = (schema = {}) => {
|
|
34
|
+
let { type, example, allOf, properties, items } = schema;
|
|
35
|
+
if (example !== undefined) {
|
|
36
|
+
return example;
|
|
37
|
+
}
|
|
38
|
+
if (allOf) {
|
|
39
|
+
// TODO: We are just assuming it will always be an object for now
|
|
40
|
+
let obj = {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {},
|
|
43
|
+
required: [], // NOTE: We shouldn't need to worry about required
|
|
44
|
+
};
|
|
45
|
+
for (let item of allOf) {
|
|
46
|
+
if (item.properties) {
|
|
47
|
+
obj.properties = {
|
|
48
|
+
...obj.properties,
|
|
49
|
+
...item.properties,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return (0, exports.sampleFromSchema)(obj);
|
|
54
|
+
}
|
|
55
|
+
if (!type) {
|
|
56
|
+
if (properties) {
|
|
57
|
+
type = "object";
|
|
58
|
+
}
|
|
59
|
+
else if (items) {
|
|
60
|
+
type = "array";
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (type === "object") {
|
|
67
|
+
let obj = {};
|
|
68
|
+
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
69
|
+
if (prop.deprecated) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
obj[name] = (0, exports.sampleFromSchema)(prop);
|
|
73
|
+
}
|
|
74
|
+
return obj;
|
|
75
|
+
}
|
|
76
|
+
if (type === "array") {
|
|
77
|
+
if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
|
|
78
|
+
return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleFromSchema)(item));
|
|
79
|
+
}
|
|
80
|
+
if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
|
|
81
|
+
return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleFromSchema)(item));
|
|
82
|
+
}
|
|
83
|
+
return [(0, exports.sampleFromSchema)(items)];
|
|
84
|
+
}
|
|
85
|
+
if (schema.enum) {
|
|
86
|
+
if (schema.default) {
|
|
87
|
+
return schema.default;
|
|
88
|
+
}
|
|
89
|
+
return normalizeArray(schema.enum)[0];
|
|
90
|
+
}
|
|
91
|
+
return primitive(schema);
|
|
92
|
+
};
|
|
93
|
+
exports.sampleFromSchema = sampleFromSchema;
|
|
94
|
+
function primitive(schema = {}) {
|
|
95
|
+
let { type, format } = schema;
|
|
96
|
+
if (type === undefined) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
let fn = primitives[type].default;
|
|
100
|
+
if (format !== undefined) {
|
|
101
|
+
fn = primitives[type][format] || fn;
|
|
102
|
+
}
|
|
103
|
+
if (fn) {
|
|
104
|
+
return fn(schema);
|
|
105
|
+
}
|
|
106
|
+
return "Unknown Type: " + schema.type;
|
|
107
|
+
}
|
|
108
|
+
function normalizeArray(arr) {
|
|
109
|
+
if (Array.isArray(arr)) {
|
|
110
|
+
return arr;
|
|
111
|
+
}
|
|
112
|
+
return [arr];
|
|
113
|
+
}
|
|
@@ -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,11 @@
|
|
|
1
|
+
import { ApiMetadata } from "../types";
|
|
2
|
+
import { OpenApiObjectWithRef } from "./types";
|
|
3
|
+
interface OpenApiFiles {
|
|
4
|
+
source: string;
|
|
5
|
+
sourceDirName: string;
|
|
6
|
+
data: OpenApiObjectWithRef;
|
|
7
|
+
}
|
|
8
|
+
export declare function readOpenapiFiles(openapiPath: string, _options: {}): Promise<OpenApiFiles[]>;
|
|
9
|
+
export declare function processOpenapiFiles(files: OpenApiFiles[]): Promise<ApiMetadata[]>;
|
|
10
|
+
export declare function processOpenapiFile(openapiDataWithRefs: OpenApiObjectWithRef): Promise<ApiMetadata[]>;
|
|
11
|
+
export {};
|
|
@@ -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.processOpenapiFile = exports.processOpenapiFiles = exports.readOpenapiFiles = void 0;
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
const openapi_to_postmanv2_1 = __importDefault(require("@paloaltonetworks/openapi-to-postmanv2"));
|
|
16
|
+
const postman_collection_1 = __importDefault(require("@paloaltonetworks/postman-collection"));
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
20
|
+
const json_refs_1 = __importDefault(require("json-refs"));
|
|
21
|
+
const lodash_1 = require("lodash");
|
|
22
|
+
const createExample_1 = require("./createExample");
|
|
23
|
+
/**
|
|
24
|
+
* Finds any reference objects in the OpenAPI definition and resolves them to a finalized value.
|
|
25
|
+
*/
|
|
26
|
+
async function resolveRefs(openapiData) {
|
|
27
|
+
const { resolved } = await json_refs_1.default.resolveRefs(openapiData);
|
|
28
|
+
return resolved;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convenience function for converting raw JSON to a Postman Collection object.
|
|
32
|
+
*/
|
|
33
|
+
function jsonToCollection(data) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
let schemaPack = new openapi_to_postmanv2_1.default.SchemaPack({ type: "json", data }, { schemaFaker: false });
|
|
36
|
+
schemaPack.computedOptions.schemaFaker = false;
|
|
37
|
+
schemaPack.convert((_err, conversionResult) => {
|
|
38
|
+
if (!conversionResult.result) {
|
|
39
|
+
return reject(conversionResult.reason);
|
|
40
|
+
}
|
|
41
|
+
return resolve(new postman_collection_1.default.Collection(conversionResult.output[0].data));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a Postman Collection object from an OpenAPI definition.
|
|
47
|
+
*/
|
|
48
|
+
async function createPostmanCollection(openapiData) {
|
|
49
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
50
|
+
const data = JSON.parse(JSON.stringify(openapiData));
|
|
51
|
+
// Including `servers` breaks postman, so delete all of them.
|
|
52
|
+
delete data.servers;
|
|
53
|
+
for (let pathItemObject of Object.values(data.paths)) {
|
|
54
|
+
delete pathItemObject.servers;
|
|
55
|
+
(_a = pathItemObject.get) === null || _a === void 0 ? true : delete _a.servers;
|
|
56
|
+
(_b = pathItemObject.put) === null || _b === void 0 ? true : delete _b.servers;
|
|
57
|
+
(_c = pathItemObject.post) === null || _c === void 0 ? true : delete _c.servers;
|
|
58
|
+
(_d = pathItemObject.delete) === null || _d === void 0 ? true : delete _d.servers;
|
|
59
|
+
(_e = pathItemObject.options) === null || _e === void 0 ? true : delete _e.servers;
|
|
60
|
+
(_f = pathItemObject.head) === null || _f === void 0 ? true : delete _f.servers;
|
|
61
|
+
(_g = pathItemObject.patch) === null || _g === void 0 ? true : delete _g.servers;
|
|
62
|
+
(_h = pathItemObject.trace) === null || _h === void 0 ? true : delete _h.servers;
|
|
63
|
+
}
|
|
64
|
+
return await jsonToCollection(data);
|
|
65
|
+
}
|
|
66
|
+
function createItems(openapiData) {
|
|
67
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
68
|
+
// TODO: Find a better way to handle this
|
|
69
|
+
let items = [];
|
|
70
|
+
// Only create an info page if we have a description.
|
|
71
|
+
if (openapiData.info.description) {
|
|
72
|
+
const infoPage = {
|
|
73
|
+
type: "info",
|
|
74
|
+
id: "introduction",
|
|
75
|
+
unversionedId: "introduction",
|
|
76
|
+
title: "Introduction",
|
|
77
|
+
description: openapiData.info.description,
|
|
78
|
+
slug: "/introduction",
|
|
79
|
+
frontMatter: {},
|
|
80
|
+
info: {
|
|
81
|
+
...openapiData.info,
|
|
82
|
+
title: (_a = openapiData.info.title) !== null && _a !== void 0 ? _a : "Introduction",
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
items.push(infoPage);
|
|
86
|
+
}
|
|
87
|
+
for (let [path, pathObject] of Object.entries(openapiData.paths)) {
|
|
88
|
+
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
89
|
+
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
90
|
+
const title = (_c = (_b = operationObject.summary) !== null && _b !== void 0 ? _b : operationObject.operationId) !== null && _c !== void 0 ? _c : "Missing summary";
|
|
91
|
+
if (operationObject.description === undefined) {
|
|
92
|
+
operationObject.description =
|
|
93
|
+
(_e = (_d = operationObject.summary) !== null && _d !== void 0 ? _d : operationObject.operationId) !== null && _e !== void 0 ? _e : "";
|
|
94
|
+
}
|
|
95
|
+
const baseId = (0, lodash_1.kebabCase)(title);
|
|
96
|
+
const servers = (_g = (_f = operationObject.servers) !== null && _f !== void 0 ? _f : pathObject.servers) !== null && _g !== void 0 ? _g : openapiData.servers;
|
|
97
|
+
const security = (_h = operationObject.security) !== null && _h !== void 0 ? _h : openapiData.security;
|
|
98
|
+
// Add security schemes so we know how to handle security.
|
|
99
|
+
const securitySchemes = (_j = openapiData.components) === null || _j === void 0 ? void 0 : _j.securitySchemes;
|
|
100
|
+
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
101
|
+
if (securitySchemes) {
|
|
102
|
+
for (let securityScheme of Object.values(securitySchemes)) {
|
|
103
|
+
if (securityScheme.type === "http") {
|
|
104
|
+
securityScheme.scheme = securityScheme.scheme.toLowerCase();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
let jsonRequestBodyExample;
|
|
109
|
+
const body = (_l = (_k = operationObject.requestBody) === null || _k === void 0 ? void 0 : _k.content) === null || _l === void 0 ? void 0 : _l["application/json"];
|
|
110
|
+
if (body === null || body === void 0 ? void 0 : body.schema) {
|
|
111
|
+
jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(body.schema);
|
|
112
|
+
}
|
|
113
|
+
// TODO: Don't include summary temporarilly
|
|
114
|
+
const { summary, ...defaults } = operationObject;
|
|
115
|
+
const apiPage = {
|
|
116
|
+
type: "api",
|
|
117
|
+
id: baseId,
|
|
118
|
+
unversionedId: baseId,
|
|
119
|
+
title: title,
|
|
120
|
+
description: description !== null && description !== void 0 ? description : "",
|
|
121
|
+
slug: "/" + baseId,
|
|
122
|
+
frontMatter: {},
|
|
123
|
+
api: {
|
|
124
|
+
...defaults,
|
|
125
|
+
tags: (_m = operationObject.tags) === null || _m === void 0 ? void 0 : _m.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
|
|
126
|
+
method,
|
|
127
|
+
path,
|
|
128
|
+
servers,
|
|
129
|
+
security,
|
|
130
|
+
securitySchemes,
|
|
131
|
+
jsonRequestBodyExample,
|
|
132
|
+
info: openapiData.info,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
items.push(apiPage);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return items;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Attach Postman Request objects to the corresponding ApiItems.
|
|
142
|
+
*/
|
|
143
|
+
function bindCollectionToApiItems(items, postmanCollection) {
|
|
144
|
+
postmanCollection.forEachItem((item) => {
|
|
145
|
+
const method = item.request.method.toLowerCase();
|
|
146
|
+
const path = item.request.url
|
|
147
|
+
.getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
|
|
148
|
+
.replace(/:([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
|
|
149
|
+
const apiItem = items.find((item) => {
|
|
150
|
+
if (item.type === "info") {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return item.api.path === path && item.api.method === method;
|
|
154
|
+
});
|
|
155
|
+
if ((apiItem === null || apiItem === void 0 ? void 0 : apiItem.type) === "api") {
|
|
156
|
+
apiItem.api.postman = item.request;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async function readOpenapiFiles(openapiPath, _options) {
|
|
161
|
+
const stat = await fs_extra_1.default.lstat(openapiPath);
|
|
162
|
+
if (stat.isDirectory()) {
|
|
163
|
+
console.warn(chalk_1.default.yellow("WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."));
|
|
164
|
+
// TODO: Add config for inlcude/ignore
|
|
165
|
+
const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
|
|
166
|
+
cwd: openapiPath,
|
|
167
|
+
ignore: utils_1.GlobExcludeDefault,
|
|
168
|
+
});
|
|
169
|
+
const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
|
|
170
|
+
return Promise.all(sources.map(async (source) => {
|
|
171
|
+
// TODO: make a function for this
|
|
172
|
+
const fullPath = path_1.default.join(openapiPath, source);
|
|
173
|
+
const openapiString = await fs_extra_1.default.readFile(fullPath, "utf-8");
|
|
174
|
+
const data = js_yaml_1.default.load(openapiString);
|
|
175
|
+
return {
|
|
176
|
+
source: fullPath,
|
|
177
|
+
sourceDirName: path_1.default.dirname(source),
|
|
178
|
+
data,
|
|
179
|
+
};
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
const openapiString = await fs_extra_1.default.readFile(openapiPath, "utf-8");
|
|
183
|
+
const data = js_yaml_1.default.load(openapiString);
|
|
184
|
+
return [
|
|
185
|
+
{
|
|
186
|
+
source: openapiPath,
|
|
187
|
+
sourceDirName: ".",
|
|
188
|
+
data,
|
|
189
|
+
},
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
exports.readOpenapiFiles = readOpenapiFiles;
|
|
193
|
+
async function processOpenapiFiles(files) {
|
|
194
|
+
const promises = files.map(async (file) => {
|
|
195
|
+
const items = await processOpenapiFile(file.data);
|
|
196
|
+
return items.map((item) => ({
|
|
197
|
+
...item,
|
|
198
|
+
}));
|
|
199
|
+
});
|
|
200
|
+
const metadata = await Promise.all(promises);
|
|
201
|
+
const items = metadata.flat();
|
|
202
|
+
return items;
|
|
203
|
+
}
|
|
204
|
+
exports.processOpenapiFiles = processOpenapiFiles;
|
|
205
|
+
async function processOpenapiFile(openapiDataWithRefs) {
|
|
206
|
+
const openapiData = await resolveRefs(openapiDataWithRefs);
|
|
207
|
+
const postmanCollection = await createPostmanCollection(openapiData);
|
|
208
|
+
const items = createItems(openapiData);
|
|
209
|
+
bindCollectionToApiItems(items, postmanCollection);
|
|
210
|
+
return items;
|
|
211
|
+
}
|
|
212
|
+
exports.processOpenapiFile = processOpenapiFile;
|
|
213
|
+
// order for picking items as a display name of tags
|
|
214
|
+
const tagDisplayNameProperties = ["x-displayName", "name"];
|
|
215
|
+
function getTagDisplayName(tagName, tags) {
|
|
216
|
+
var _a;
|
|
217
|
+
// find the very own tagObject
|
|
218
|
+
const tagObject = (_a = tags.find((tagObject) => tagObject.name === tagName)) !== null && _a !== void 0 ? _a : {
|
|
219
|
+
// if none found, just fake one
|
|
220
|
+
name: tagName,
|
|
221
|
+
};
|
|
222
|
+
// return the first found and filled value from the property list
|
|
223
|
+
for (const property of tagDisplayNameProperties) {
|
|
224
|
+
const displayName = tagObject[property];
|
|
225
|
+
if (typeof displayName === "string") {
|
|
226
|
+
return displayName;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// always default to the tagName
|
|
230
|
+
return tagName;
|
|
231
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const _1 = require(".");
|
|
14
|
+
// npx jest packages/docusaurus-plugin-openapi/src/openapi/openapi.test.ts --watch
|
|
15
|
+
describe("openapi", () => {
|
|
16
|
+
describe("readOpenapiFiles", () => {
|
|
17
|
+
it("readOpenapiFiles", async () => {
|
|
18
|
+
const results = await (0, _1.readOpenapiFiles)(path_1.default.join(__dirname, "__fixtures__/examples"), {});
|
|
19
|
+
const categoryMeta = results.find((x) => x.source.endsWith("_category_.json"));
|
|
20
|
+
expect(categoryMeta).toBeFalsy();
|
|
21
|
+
// console.log(results);
|
|
22
|
+
const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
|
|
23
|
+
expect(yaml).toBeTruthy();
|
|
24
|
+
expect(yaml === null || yaml === void 0 ? void 0 : yaml.sourceDirName).toBe(".");
|
|
25
|
+
const froyo = results.find((x) => x.source.endsWith("froyo.yaml"));
|
|
26
|
+
expect(froyo).toBeTruthy();
|
|
27
|
+
expect(froyo === null || froyo === void 0 ? void 0 : froyo.sourceDirName).toBe("yogurtstore");
|
|
28
|
+
const nested = results.find((x) => x.source.endsWith("nested.yaml"));
|
|
29
|
+
expect(nested).toBeTruthy();
|
|
30
|
+
expect(nested === null || nested === void 0 ? void 0 : nested.sourceDirName).toBe("yogurtstore/nested");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|