docusaurus-plugin-openapi-docs 1.1.2 → 1.1.5
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 +1 -1
- package/lib/markdown/createLogo.d.ts +2 -0
- package/lib/markdown/createLogo.js +19 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +9 -2
- package/lib/markdown/createRequestBodyDetails.js +2 -2
- package/lib/markdown/createRequestSchema.d.ts +21 -0
- package/lib/markdown/createRequestSchema.js +680 -0
- package/lib/markdown/{createSchemaDetails.d.ts → createResponseSchema.d.ts} +2 -2
- package/lib/markdown/{createSchemaDetails.js → createResponseSchema.js} +289 -48
- package/lib/markdown/createStatusCodes.js +117 -4
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/index.js +12 -3
- package/lib/markdown/schema.js +50 -14
- package/lib/markdown/schema.test.js +18 -18
- package/lib/openapi/createExample.js +27 -14
- package/lib/openapi/openapi.d.ts +1 -1
- package/lib/openapi/openapi.js +30 -19
- package/lib/openapi/types.d.ts +8 -1
- package/lib/openapi/utils/loadAndResolveSpec.js +13 -0
- package/lib/sidebars/index.d.ts +1 -1
- package/lib/sidebars/index.js +14 -5
- package/lib/types.d.ts +1 -1
- package/package.json +8 -8
- package/src/markdown/createLogo.ts +21 -0
- package/src/markdown/createRequestBodyDetails.ts +11 -4
- package/src/markdown/createRequestSchema.ts +848 -0
- package/src/markdown/{createSchemaDetails.ts → createResponseSchema.ts} +350 -54
- package/src/markdown/createStatusCodes.ts +149 -9
- package/src/markdown/index.ts +34 -3
- package/src/markdown/schema.test.ts +18 -18
- package/src/markdown/schema.ts +60 -14
- package/src/openapi/createExample.ts +31 -14
- package/src/openapi/openapi.ts +21 -13
- package/src/openapi/types.ts +9 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +13 -0
- package/src/sidebars/index.ts +17 -7
- package/src/types.ts +1 -1
package/lib/markdown/schema.js
CHANGED
|
@@ -54,19 +54,39 @@ function getQualifierMessage(schema) {
|
|
|
54
54
|
if (!schema) {
|
|
55
55
|
return undefined;
|
|
56
56
|
}
|
|
57
|
-
if (schema.items
|
|
57
|
+
if (schema.items &&
|
|
58
|
+
schema.minItems === undefined &&
|
|
59
|
+
schema.maxItems === undefined) {
|
|
58
60
|
return getQualifierMessage(schema.items);
|
|
59
61
|
}
|
|
60
62
|
let message = "**Possible values:** ";
|
|
61
63
|
let qualifierGroups = [];
|
|
64
|
+
if (schema.items && schema.items.enum) {
|
|
65
|
+
if (schema.items.enum) {
|
|
66
|
+
qualifierGroups.push(`[${schema.items.enum.map((e) => `\`${e}\``).join(", ")}]`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
62
69
|
if (schema.minLength || schema.maxLength) {
|
|
63
70
|
let lengthQualifier = "";
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
let minLength;
|
|
72
|
+
let maxLength;
|
|
73
|
+
if (schema.minLength && schema.minLength > 1) {
|
|
74
|
+
minLength = `\`>= ${schema.minLength} characters\``;
|
|
75
|
+
}
|
|
76
|
+
if (schema.minLength && schema.minLength === 1) {
|
|
77
|
+
minLength = `\`non-empty\``;
|
|
66
78
|
}
|
|
67
|
-
lengthQualifier += "length";
|
|
68
79
|
if (schema.maxLength) {
|
|
69
|
-
|
|
80
|
+
maxLength = `\`<= ${schema.maxLength} characters\``;
|
|
81
|
+
}
|
|
82
|
+
if (minLength && !maxLength) {
|
|
83
|
+
lengthQualifier += minLength;
|
|
84
|
+
}
|
|
85
|
+
if (maxLength && !minLength) {
|
|
86
|
+
lengthQualifier += maxLength;
|
|
87
|
+
}
|
|
88
|
+
if (minLength && maxLength) {
|
|
89
|
+
lengthQualifier += `${minLength} and ${maxLength}`;
|
|
70
90
|
}
|
|
71
91
|
qualifierGroups.push(lengthQualifier);
|
|
72
92
|
}
|
|
@@ -75,38 +95,54 @@ function getQualifierMessage(schema) {
|
|
|
75
95
|
typeof schema.exclusiveMinimum === "number" ||
|
|
76
96
|
typeof schema.exclusiveMaximum === "number") {
|
|
77
97
|
let minmaxQualifier = "";
|
|
98
|
+
let minimum;
|
|
99
|
+
let maximum;
|
|
78
100
|
if (typeof schema.exclusiveMinimum === "number") {
|
|
79
|
-
|
|
101
|
+
minimum = `\`> ${schema.exclusiveMinimum}\``;
|
|
80
102
|
}
|
|
81
103
|
else if (schema.minimum && !schema.exclusiveMinimum) {
|
|
82
|
-
|
|
104
|
+
minimum = `\`>= ${schema.minimum}\``;
|
|
83
105
|
}
|
|
84
106
|
else if (schema.minimum && schema.exclusiveMinimum === true) {
|
|
85
|
-
|
|
107
|
+
minimum = `\`> ${schema.minimum}\``;
|
|
86
108
|
}
|
|
87
|
-
minmaxQualifier += "value";
|
|
88
109
|
if (typeof schema.exclusiveMaximum === "number") {
|
|
89
|
-
|
|
110
|
+
maximum = `\`< ${schema.exclusiveMaximum}\``;
|
|
90
111
|
}
|
|
91
112
|
else if (schema.maximum && !schema.exclusiveMaximum) {
|
|
92
|
-
|
|
113
|
+
maximum = `\`<= ${schema.maximum}\``;
|
|
93
114
|
}
|
|
94
115
|
else if (schema.maximum && schema.exclusiveMaximum === true) {
|
|
95
|
-
|
|
116
|
+
maximum = `\`< ${schema.maximum}\``;
|
|
117
|
+
}
|
|
118
|
+
if (minimum && !maximum) {
|
|
119
|
+
minmaxQualifier += minimum;
|
|
120
|
+
}
|
|
121
|
+
if (maximum && !minimum) {
|
|
122
|
+
minmaxQualifier += maximum;
|
|
123
|
+
}
|
|
124
|
+
if (minimum && maximum) {
|
|
125
|
+
minmaxQualifier += `${minimum} and ${maximum}`;
|
|
96
126
|
}
|
|
97
127
|
qualifierGroups.push(minmaxQualifier);
|
|
98
128
|
}
|
|
99
129
|
if (schema.pattern) {
|
|
100
130
|
qualifierGroups.push(`Value must match regular expression \`${schema.pattern}\``);
|
|
101
131
|
}
|
|
132
|
+
// Check if discriminator mapping
|
|
133
|
+
const discriminator = schema;
|
|
134
|
+
if (discriminator.mapping) {
|
|
135
|
+
const values = Object.keys(discriminator.mapping);
|
|
136
|
+
qualifierGroups.push(`[${values.map((e) => `\`${e}\``).join(", ")}]`);
|
|
137
|
+
}
|
|
102
138
|
if (schema.enum) {
|
|
103
139
|
qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
|
|
104
140
|
}
|
|
105
141
|
if (schema.minItems) {
|
|
106
|
-
qualifierGroups.push(
|
|
142
|
+
qualifierGroups.push(`\`>= ${schema.minItems}\``);
|
|
107
143
|
}
|
|
108
144
|
if (schema.maxItems) {
|
|
109
|
-
qualifierGroups.push(
|
|
145
|
+
qualifierGroups.push(`\`<= ${schema.maxItems}\``);
|
|
110
146
|
}
|
|
111
147
|
if (qualifierGroups.length === 0) {
|
|
112
148
|
return undefined;
|
|
@@ -16,17 +16,17 @@ describe("getQualifierMessage", () => {
|
|
|
16
16
|
// minLength + maxLength
|
|
17
17
|
//
|
|
18
18
|
it("should render minLength", () => {
|
|
19
|
-
const expected = "**Possible values:**
|
|
19
|
+
const expected = "**Possible values:** `non-empty`";
|
|
20
20
|
const actual = (0, schema_1.getQualifierMessage)({ minLength: 1 });
|
|
21
21
|
expect(actual).toBe(expected);
|
|
22
22
|
});
|
|
23
23
|
it("should render maxLength", () => {
|
|
24
|
-
const expected = "**Possible values:**
|
|
24
|
+
const expected = "**Possible values:** `<= 40 characters`";
|
|
25
25
|
const actual = (0, schema_1.getQualifierMessage)({ maxLength: 40 });
|
|
26
26
|
expect(actual).toBe(expected);
|
|
27
27
|
});
|
|
28
28
|
it("should render minLength and maxLength", () => {
|
|
29
|
-
const expected = "**Possible values:**
|
|
29
|
+
const expected = "**Possible values:** `non-empty` and `<= 40 characters`";
|
|
30
30
|
const actual = (0, schema_1.getQualifierMessage)({ minLength: 1, maxLength: 40 });
|
|
31
31
|
expect(actual).toBe(expected);
|
|
32
32
|
});
|
|
@@ -39,7 +39,7 @@ describe("getQualifierMessage", () => {
|
|
|
39
39
|
expect(actual).toBe(expected);
|
|
40
40
|
});
|
|
41
41
|
it("should render multiple string qualifiers", () => {
|
|
42
|
-
const expected = "**Possible values:**
|
|
42
|
+
const expected = "**Possible values:** `non-empty` and `<= 40 characters`, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
43
43
|
const actual = (0, schema_1.getQualifierMessage)({
|
|
44
44
|
minLength: 1,
|
|
45
45
|
maxLength: 40,
|
|
@@ -59,42 +59,42 @@ describe("getQualifierMessage", () => {
|
|
|
59
59
|
// minimum + maximum + exclusiveMinimum + exclusiveMaximum
|
|
60
60
|
//
|
|
61
61
|
it("should render minimum", () => {
|
|
62
|
-
const expected = "**Possible values:** 1
|
|
62
|
+
const expected = "**Possible values:** `>= 1`";
|
|
63
63
|
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1 });
|
|
64
64
|
expect(actual).toBe(expected);
|
|
65
65
|
});
|
|
66
66
|
it("should render maximum", () => {
|
|
67
|
-
const expected = "**Possible values:**
|
|
67
|
+
const expected = "**Possible values:** `<= 40`";
|
|
68
68
|
const actual = (0, schema_1.getQualifierMessage)({ maximum: 40 });
|
|
69
69
|
expect(actual).toBe(expected);
|
|
70
70
|
});
|
|
71
71
|
it("should render numeric exclusiveMinimum", () => {
|
|
72
|
-
const expected = "**Possible values:** 1
|
|
72
|
+
const expected = "**Possible values:** `> 1`";
|
|
73
73
|
const actual = (0, schema_1.getQualifierMessage)({ exclusiveMinimum: 1 });
|
|
74
74
|
expect(actual).toBe(expected);
|
|
75
75
|
});
|
|
76
76
|
it("should render numeric exclusiveMaximum", () => {
|
|
77
|
-
const expected = "**Possible values:**
|
|
77
|
+
const expected = "**Possible values:** `< 40`";
|
|
78
78
|
const actual = (0, schema_1.getQualifierMessage)({ exclusiveMaximum: 40 });
|
|
79
79
|
expect(actual).toBe(expected);
|
|
80
80
|
});
|
|
81
81
|
it("should render boolean exclusiveMinimum", () => {
|
|
82
|
-
const expected = "**Possible values:** 1
|
|
82
|
+
const expected = "**Possible values:** `> 1`";
|
|
83
83
|
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: true });
|
|
84
84
|
expect(actual).toBe(expected);
|
|
85
85
|
});
|
|
86
86
|
it("should render boolean exclusiveMaximum", () => {
|
|
87
|
-
const expected = "**Possible values:**
|
|
87
|
+
const expected = "**Possible values:** `< 40`";
|
|
88
88
|
const actual = (0, schema_1.getQualifierMessage)({ maximum: 40, exclusiveMaximum: true });
|
|
89
89
|
expect(actual).toBe(expected);
|
|
90
90
|
});
|
|
91
91
|
it("should render minimum when exclusiveMinimum is false", () => {
|
|
92
|
-
const expected = "**Possible values:** 1
|
|
92
|
+
const expected = "**Possible values:** `>= 1`";
|
|
93
93
|
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: false });
|
|
94
94
|
expect(actual).toBe(expected);
|
|
95
95
|
});
|
|
96
96
|
it("should render maximum when exclusiveMaximum is false", () => {
|
|
97
|
-
const expected = "**Possible values:**
|
|
97
|
+
const expected = "**Possible values:** `<= 40`";
|
|
98
98
|
const actual = (0, schema_1.getQualifierMessage)({
|
|
99
99
|
maximum: 40,
|
|
100
100
|
exclusiveMaximum: false,
|
|
@@ -102,12 +102,12 @@ describe("getQualifierMessage", () => {
|
|
|
102
102
|
expect(actual).toBe(expected);
|
|
103
103
|
});
|
|
104
104
|
it("should render minimum and maximum", () => {
|
|
105
|
-
const expected = "**Possible values:** 1
|
|
105
|
+
const expected = "**Possible values:** `>= 1` and `<= 40`";
|
|
106
106
|
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, maximum: 40 });
|
|
107
107
|
expect(actual).toBe(expected);
|
|
108
108
|
});
|
|
109
109
|
it("should render boolean exclusiveMinimum and maximum", () => {
|
|
110
|
-
const expected = "**Possible values:** 1
|
|
110
|
+
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
111
111
|
const actual = (0, schema_1.getQualifierMessage)({
|
|
112
112
|
minimum: 1,
|
|
113
113
|
maximum: 40,
|
|
@@ -116,7 +116,7 @@ describe("getQualifierMessage", () => {
|
|
|
116
116
|
expect(actual).toBe(expected);
|
|
117
117
|
});
|
|
118
118
|
it("should render minimum and boolean exclusiveMaximum", () => {
|
|
119
|
-
const expected = "**Possible values:** 1
|
|
119
|
+
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
120
120
|
const actual = (0, schema_1.getQualifierMessage)({
|
|
121
121
|
minimum: 1,
|
|
122
122
|
maximum: 40,
|
|
@@ -125,7 +125,7 @@ describe("getQualifierMessage", () => {
|
|
|
125
125
|
expect(actual).toBe(expected);
|
|
126
126
|
});
|
|
127
127
|
it("should render numeric exclusiveMinimum and maximum", () => {
|
|
128
|
-
const expected = "**Possible values:** 1
|
|
128
|
+
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
129
129
|
const actual = (0, schema_1.getQualifierMessage)({
|
|
130
130
|
exclusiveMinimum: 1,
|
|
131
131
|
maximum: 40,
|
|
@@ -133,7 +133,7 @@ describe("getQualifierMessage", () => {
|
|
|
133
133
|
expect(actual).toBe(expected);
|
|
134
134
|
});
|
|
135
135
|
it("should render minimum and numeric exclusiveMaximum", () => {
|
|
136
|
-
const expected = "**Possible values:** 1
|
|
136
|
+
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
137
137
|
const actual = (0, schema_1.getQualifierMessage)({
|
|
138
138
|
minimum: 1,
|
|
139
139
|
exclusiveMaximum: 40,
|
|
@@ -141,7 +141,7 @@ describe("getQualifierMessage", () => {
|
|
|
141
141
|
expect(actual).toBe(expected);
|
|
142
142
|
});
|
|
143
143
|
it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
|
|
144
|
-
const expected = "**Possible values:** 1
|
|
144
|
+
const expected = "**Possible values:** `> 1` and `< 40`";
|
|
145
145
|
const actual = (0, schema_1.getQualifierMessage)({
|
|
146
146
|
exclusiveMinimum: 1,
|
|
147
147
|
maximum: 40,
|
|
@@ -11,11 +11,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sampleFromSchema = void 0;
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const createRequestSchema_1 = require("../markdown/createRequestSchema");
|
|
14
15
|
const primitives = {
|
|
15
16
|
string: {
|
|
16
17
|
default: () => "string",
|
|
17
18
|
email: () => "user@example.com",
|
|
18
19
|
date: () => new Date().toISOString().substring(0, 10),
|
|
20
|
+
"date-time": () => new Date().toISOString().substring(0, 10),
|
|
19
21
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
20
22
|
hostname: () => "example.com",
|
|
21
23
|
ipv4: () => "198.51.100.42",
|
|
@@ -41,21 +43,15 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
41
43
|
return example;
|
|
42
44
|
}
|
|
43
45
|
if (allOf) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (let item of allOf) {
|
|
51
|
-
if (item.properties) {
|
|
52
|
-
obj.properties = {
|
|
53
|
-
...obj.properties,
|
|
54
|
-
...item.properties,
|
|
55
|
-
};
|
|
46
|
+
const { mergedSchemas } = (0, createRequestSchema_1.mergeAllOf)(allOf);
|
|
47
|
+
if (mergedSchemas.properties) {
|
|
48
|
+
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
49
|
+
if (value.readOnly && value.readOnly === true) {
|
|
50
|
+
delete mergedSchemas.properties[key];
|
|
51
|
+
}
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
|
-
return (0, exports.sampleFromSchema)(
|
|
54
|
+
return (0, exports.sampleFromSchema)(mergedSchemas);
|
|
59
55
|
}
|
|
60
56
|
if (!type) {
|
|
61
57
|
if (properties) {
|
|
@@ -71,6 +67,20 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
71
67
|
if (type === "object") {
|
|
72
68
|
let obj = {};
|
|
73
69
|
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
70
|
+
if (prop.properties) {
|
|
71
|
+
for (const [key, value] of Object.entries(prop.properties)) {
|
|
72
|
+
if (value.readOnly && value.readOnly === true) {
|
|
73
|
+
delete prop.properties[key];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (prop.items && prop.items.properties) {
|
|
78
|
+
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
79
|
+
if (value.readOnly && value.readOnly === true) {
|
|
80
|
+
delete prop.items.properties[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
74
84
|
if (prop.deprecated) {
|
|
75
85
|
continue;
|
|
76
86
|
}
|
|
@@ -93,6 +103,9 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
93
103
|
}
|
|
94
104
|
return normalizeArray(schema.enum)[0];
|
|
95
105
|
}
|
|
106
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
96
109
|
return primitive(schema);
|
|
97
110
|
}
|
|
98
111
|
catch (err) {
|
|
@@ -106,7 +119,7 @@ function primitive(schema = {}) {
|
|
|
106
119
|
if (type === undefined) {
|
|
107
120
|
return;
|
|
108
121
|
}
|
|
109
|
-
let fn = primitives[type].default;
|
|
122
|
+
let fn = schema.default ? () => schema.default : primitives[type].default;
|
|
110
123
|
if (format !== undefined) {
|
|
111
124
|
fn = primitives[type][format] || fn;
|
|
112
125
|
}
|
package/lib/openapi/openapi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface OpenApiFiles {
|
|
|
6
6
|
data: OpenApiObject;
|
|
7
7
|
}
|
|
8
8
|
export declare function readOpenapiFiles(openapiPath: string, options: APIOptions): Promise<OpenApiFiles[]>;
|
|
9
|
-
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
9
|
+
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
|
|
10
10
|
export declare function processOpenapiFile(openapiData: OpenApiObject, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
11
11
|
export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
|
|
12
12
|
export {};
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -16,7 +16,8 @@ const openapi_to_postmanv2_1 = __importDefault(require("@paloaltonetworks/openap
|
|
|
16
16
|
const postman_collection_1 = __importDefault(require("@paloaltonetworks/postman-collection"));
|
|
17
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
18
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
|
-
const
|
|
19
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
20
|
+
const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
|
|
20
21
|
const index_1 = require("../index");
|
|
21
22
|
const createExample_1 = require("./createExample");
|
|
22
23
|
const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
|
|
@@ -41,7 +42,7 @@ function jsonToCollection(data) {
|
|
|
41
42
|
async function createPostmanCollection(openapiData) {
|
|
42
43
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
44
|
// Create copy of openapiData
|
|
44
|
-
const data =
|
|
45
|
+
const data = (0, cloneDeep_1.default)(openapiData);
|
|
45
46
|
// Including `servers` breaks postman, so delete all of them.
|
|
46
47
|
delete data.servers;
|
|
47
48
|
for (let pathItemObject of Object.values(data.paths)) {
|
|
@@ -58,10 +59,10 @@ async function createPostmanCollection(openapiData) {
|
|
|
58
59
|
return await jsonToCollection(data);
|
|
59
60
|
}
|
|
60
61
|
function createItems(openapiData, sidebarOptions) {
|
|
61
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
62
63
|
// TODO: Find a better way to handle this
|
|
63
64
|
let items = [];
|
|
64
|
-
const infoId = (0,
|
|
65
|
+
const infoId = (0, kebabCase_1.default)(openapiData.info.title);
|
|
65
66
|
if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
|
|
66
67
|
// Only create an tag pages if categoryLinkSource set to tag.
|
|
67
68
|
const tags = (_a = openapiData.tags) !== null && _a !== void 0 ? _a : [];
|
|
@@ -72,14 +73,13 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
72
73
|
.map((tag) => {
|
|
73
74
|
var _a;
|
|
74
75
|
const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
|
|
75
|
-
const tagId = (0,
|
|
76
|
+
const tagId = (0, kebabCase_1.default)(tag.name);
|
|
76
77
|
const tagPage = {
|
|
77
78
|
type: "tag",
|
|
78
79
|
id: tagId,
|
|
79
80
|
unversionedId: tagId,
|
|
80
81
|
title: description !== null && description !== void 0 ? description : "",
|
|
81
82
|
description: description !== null && description !== void 0 ? description : "",
|
|
82
|
-
slug: "/" + tagId,
|
|
83
83
|
frontMatter: {},
|
|
84
84
|
tag: {
|
|
85
85
|
...tag,
|
|
@@ -96,13 +96,14 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
96
96
|
unversionedId: infoId,
|
|
97
97
|
title: openapiData.info.title,
|
|
98
98
|
description: openapiData.info.description,
|
|
99
|
-
slug: "/" + infoId,
|
|
100
99
|
frontMatter: {},
|
|
101
100
|
securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
|
|
102
101
|
info: {
|
|
103
102
|
...openapiData.info,
|
|
104
|
-
tags:
|
|
105
|
-
title: (
|
|
103
|
+
tags: openapiData.tags,
|
|
104
|
+
title: (_c = openapiData.info.title) !== null && _c !== void 0 ? _c : "Introduction",
|
|
105
|
+
logo: openapiData.info["x-logo"],
|
|
106
|
+
darkLogo: openapiData.info["x-dark-logo"],
|
|
106
107
|
},
|
|
107
108
|
};
|
|
108
109
|
items.push(infoPage);
|
|
@@ -110,18 +111,18 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
110
111
|
for (let [path, pathObject] of Object.entries(openapiData.paths)) {
|
|
111
112
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
112
113
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
113
|
-
const title = (
|
|
114
|
+
const title = (_e = (_d = operationObject.summary) !== null && _d !== void 0 ? _d : operationObject.operationId) !== null && _e !== void 0 ? _e : "Missing summary";
|
|
114
115
|
if (operationObject.description === undefined) {
|
|
115
116
|
operationObject.description =
|
|
116
|
-
(
|
|
117
|
+
(_g = (_f = operationObject.summary) !== null && _f !== void 0 ? _f : operationObject.operationId) !== null && _g !== void 0 ? _g : "";
|
|
117
118
|
}
|
|
118
119
|
const baseId = operationObject.operationId
|
|
119
|
-
? (0,
|
|
120
|
-
: (0,
|
|
121
|
-
const servers = (
|
|
122
|
-
const security = (
|
|
120
|
+
? (0, kebabCase_1.default)(operationObject.operationId)
|
|
121
|
+
: (0, kebabCase_1.default)(operationObject.summary);
|
|
122
|
+
const servers = (_j = (_h = operationObject.servers) !== null && _h !== void 0 ? _h : pathObject.servers) !== null && _j !== void 0 ? _j : openapiData.servers;
|
|
123
|
+
const security = (_k = operationObject.security) !== null && _k !== void 0 ? _k : openapiData.security;
|
|
123
124
|
// Add security schemes so we know how to handle security.
|
|
124
|
-
const securitySchemes = (
|
|
125
|
+
const securitySchemes = (_l = openapiData.components) === null || _l === void 0 ? void 0 : _l.securitySchemes;
|
|
125
126
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
126
127
|
if (securitySchemes) {
|
|
127
128
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -131,10 +132,21 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
let jsonRequestBodyExample;
|
|
134
|
-
const body = (
|
|
135
|
+
const body = (_o = (_m = operationObject.requestBody) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o["application/json"];
|
|
135
136
|
if (body === null || body === void 0 ? void 0 : body.schema) {
|
|
136
137
|
jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(body.schema);
|
|
137
138
|
}
|
|
139
|
+
// Handle vendor JSON media types
|
|
140
|
+
const bodyContent = (_p = operationObject.requestBody) === null || _p === void 0 ? void 0 : _p.content;
|
|
141
|
+
if (bodyContent) {
|
|
142
|
+
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
143
|
+
if (firstBodyContentKey.endsWith("+json")) {
|
|
144
|
+
const firstBody = bodyContent[firstBodyContentKey];
|
|
145
|
+
if (firstBody === null || firstBody === void 0 ? void 0 : firstBody.schema) {
|
|
146
|
+
jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(firstBody.schema);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
138
150
|
// TODO: Don't include summary temporarilly
|
|
139
151
|
const { summary, ...defaults } = operationObject;
|
|
140
152
|
const apiPage = {
|
|
@@ -144,11 +156,10 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
144
156
|
unversionedId: baseId,
|
|
145
157
|
title: title,
|
|
146
158
|
description: description !== null && description !== void 0 ? description : "",
|
|
147
|
-
slug: "/" + baseId,
|
|
148
159
|
frontMatter: {},
|
|
149
160
|
api: {
|
|
150
161
|
...defaults,
|
|
151
|
-
tags:
|
|
162
|
+
tags: operationObject.tags,
|
|
152
163
|
method,
|
|
153
164
|
path,
|
|
154
165
|
servers,
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -30,7 +30,14 @@ export interface InfoObject {
|
|
|
30
30
|
contact?: ContactObject;
|
|
31
31
|
license?: LicenseObject;
|
|
32
32
|
version: string;
|
|
33
|
-
tags?:
|
|
33
|
+
tags?: TagObject[];
|
|
34
|
+
"x-logo"?: LogoObject;
|
|
35
|
+
"x-dark-logo"?: LogoObject;
|
|
36
|
+
logo?: LogoObject;
|
|
37
|
+
darkLogo?: LogoObject;
|
|
38
|
+
}
|
|
39
|
+
export interface LogoObject {
|
|
40
|
+
url?: string;
|
|
34
41
|
}
|
|
35
42
|
export interface ContactObject {
|
|
36
43
|
name?: string;
|
|
@@ -15,6 +15,7 @@ const openapi_core_1 = require("@redocly/openapi-core");
|
|
|
15
15
|
const chalk_1 = __importDefault(require("chalk"));
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
const swagger2openapi_1 = require("swagger2openapi");
|
|
18
|
+
const OpenAPIParser_1 = require("./services/OpenAPIParser");
|
|
18
19
|
function serializer(replacer, cycleReplacer) {
|
|
19
20
|
var stack = [], keys = [];
|
|
20
21
|
if (cycleReplacer === undefined)
|
|
@@ -24,6 +25,18 @@ function serializer(replacer, cycleReplacer) {
|
|
|
24
25
|
return value.title ? `circular(${value.title})` : "circular()";
|
|
25
26
|
};
|
|
26
27
|
return function (key, value) {
|
|
28
|
+
// Resolve discriminator ref pointers
|
|
29
|
+
if ((value === null || value === void 0 ? void 0 : value.discriminator) !== undefined) {
|
|
30
|
+
const parser = new OpenAPIParser_1.OpenAPIParser(stack[0]);
|
|
31
|
+
for (let [k, v] of Object.entries(value.discriminator.mapping)) {
|
|
32
|
+
const discriminator = k;
|
|
33
|
+
if (typeof v === "string" && v.charAt(0) === "#") {
|
|
34
|
+
const ref = v;
|
|
35
|
+
const resolvedRef = parser.byRef(ref);
|
|
36
|
+
value.discriminator.mapping[discriminator] = resolvedRef;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
27
40
|
if (stack.length > 0) {
|
|
28
41
|
// @ts-ignore
|
|
29
42
|
var thisPos = stack.indexOf(this);
|
package/lib/sidebars/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
2
2
|
import { TagObject } from "../openapi/types";
|
|
3
3
|
import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
|
|
4
|
-
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[], docPath: string): ProcessedSidebar;
|
|
4
|
+
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[][], docPath: string): ProcessedSidebar;
|
package/lib/sidebars/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
12
13
|
const clsx_1 = __importDefault(require("clsx"));
|
|
13
14
|
const lodash_1 = require("lodash");
|
|
14
15
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
@@ -32,9 +33,16 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
32
33
|
};
|
|
33
34
|
});
|
|
34
35
|
// TODO: make sure we only take the first tag
|
|
35
|
-
const
|
|
36
|
+
const operationTags = (0, uniq_1.default)(apiItems
|
|
36
37
|
.flatMap((item) => item.api.tags)
|
|
37
38
|
.filter((item) => !!item));
|
|
39
|
+
// Only include operation tags that are globally defined
|
|
40
|
+
const apiTags = [];
|
|
41
|
+
tags.flat().forEach((tag) => {
|
|
42
|
+
if (operationTags.includes(tag.name)) {
|
|
43
|
+
apiTags.push(tag.name);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
38
46
|
const basePath = docPath
|
|
39
47
|
? outputDir.split(docPath)[1].replace(/^\/+/g, "")
|
|
40
48
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
@@ -65,11 +73,12 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
65
73
|
}
|
|
66
74
|
const tagged = apiTags
|
|
67
75
|
.map((tag) => {
|
|
76
|
+
var _a;
|
|
68
77
|
// Map info object to tag
|
|
69
78
|
const taggedInfoObject = intros.find((i) => i.tags ? i.tags.includes(tag) : undefined);
|
|
70
79
|
const tagObject = tags.flat().find((t) => {
|
|
71
80
|
var _a;
|
|
72
|
-
return (_a =
|
|
81
|
+
return (_a = tag === t.name) !== null && _a !== void 0 ? _a : {
|
|
73
82
|
name: tag,
|
|
74
83
|
description: `${tag} Index`,
|
|
75
84
|
};
|
|
@@ -98,13 +107,13 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
98
107
|
type: "generated-index",
|
|
99
108
|
title: tag,
|
|
100
109
|
slug: label
|
|
101
|
-
? "/category
|
|
102
|
-
: "/category
|
|
110
|
+
? path_1.default.join("/category", basePath, (0, lodash_1.kebabCase)(label), (0, lodash_1.kebabCase)(tag))
|
|
111
|
+
: path_1.default.join("/category", basePath, (0, lodash_1.kebabCase)(tag)),
|
|
103
112
|
};
|
|
104
113
|
}
|
|
105
114
|
return {
|
|
106
115
|
type: "category",
|
|
107
|
-
label: tag,
|
|
116
|
+
label: (_a = tagObject === null || tagObject === void 0 ? void 0 : tagObject["x-displayName"]) !== null && _a !== void 0 ? _a : tag,
|
|
108
117
|
link: linkConfig,
|
|
109
118
|
collapsible: sidebarCollapsible,
|
|
110
119
|
collapsed: sidebarCollapsed,
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-plugin-openapi-docs",
|
|
3
3
|
"description": "OpenAPI plugin for Docusaurus.",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"watch": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@docusaurus/module-type-aliases": "2.0.
|
|
32
|
-
"@docusaurus/types": "2.0.
|
|
31
|
+
"@docusaurus/module-type-aliases": "2.0.1",
|
|
32
|
+
"@docusaurus/types": "2.0.1",
|
|
33
33
|
"@types/fs-extra": "^9.0.13",
|
|
34
34
|
"@types/js-yaml": "^4.0.5",
|
|
35
35
|
"@types/json-pointer": "^1.0.31",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@apidevtools/json-schema-ref-parser": "^9.0.9",
|
|
43
|
-
"@docusaurus/mdx-loader": "2.0.
|
|
44
|
-
"@docusaurus/plugin-content-docs": "2.0.
|
|
45
|
-
"@docusaurus/utils": "2.0.
|
|
46
|
-
"@docusaurus/utils-validation": "2.0.
|
|
43
|
+
"@docusaurus/mdx-loader": "2.0.1",
|
|
44
|
+
"@docusaurus/plugin-content-docs": "2.0.1",
|
|
45
|
+
"@docusaurus/utils": "2.0.1",
|
|
46
|
+
"@docusaurus/utils-validation": "2.0.1",
|
|
47
47
|
"@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
|
|
48
48
|
"@paloaltonetworks/postman-collection": "^4.1.0",
|
|
49
49
|
"@redocly/openapi-core": "^1.0.0-beta.103",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=14"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "21d33582a9fcac2ddd23443497af910982b36dae"
|
|
71
71
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { LogoObject } from "../openapi/types";
|
|
9
|
+
import { create, guard } from "./utils";
|
|
10
|
+
|
|
11
|
+
export function createLogo(
|
|
12
|
+
logo: LogoObject | undefined,
|
|
13
|
+
darkLogo: LogoObject | undefined
|
|
14
|
+
) {
|
|
15
|
+
return guard(logo || darkLogo, () => [
|
|
16
|
+
create("ApiLogo", {
|
|
17
|
+
logo: logo,
|
|
18
|
+
darkLogo: darkLogo,
|
|
19
|
+
}),
|
|
20
|
+
]);
|
|
21
|
+
}
|