docusaurus-plugin-openapi-docs 0.0.0-408 → 0.0.0-411
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/markdown/createLogo.d.ts +2 -0
- package/lib/markdown/createLogo.js +19 -0
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/index.js +4 -1
- package/lib/markdown/schema.js +36 -13
- package/lib/markdown/schema.test.js +18 -18
- package/lib/openapi/openapi.js +9 -6
- package/lib/openapi/types.d.ts +7 -0
- package/package.json +2 -2
- package/src/markdown/createLogo.ts +21 -0
- package/src/markdown/index.ts +14 -1
- package/src/markdown/schema.test.ts +18 -18
- package/src/markdown/schema.ts +40 -13
- package/src/openapi/openapi.ts +5 -2
- package/src/openapi/types.ts +8 -0
|
@@ -0,0 +1,19 @@
|
|
|
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.createLogo = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
function createLogo(logo, darkLogo) {
|
|
12
|
+
return (0, utils_1.guard)(logo || darkLogo, () => [
|
|
13
|
+
(0, utils_1.create)("ApiLogo", {
|
|
14
|
+
logo: logo,
|
|
15
|
+
darkLogo: darkLogo,
|
|
16
|
+
}),
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
exports.createLogo = createLogo;
|
package/lib/markdown/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
|
|
2
2
|
export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }: ApiPageMetadata): string;
|
|
3
|
-
export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, securitySchemes, }: InfoPageMetadata): string;
|
|
3
|
+
export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, }: InfoPageMetadata): string;
|
|
4
4
|
export declare function createTagPageMD({ tag: { description } }: TagPageMetadata): string;
|
package/lib/markdown/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const createContactInfo_1 = require("./createContactInfo");
|
|
|
13
13
|
const createDeprecationNotice_1 = require("./createDeprecationNotice");
|
|
14
14
|
const createDescription_1 = require("./createDescription");
|
|
15
15
|
const createLicense_1 = require("./createLicense");
|
|
16
|
+
const createLogo_1 = require("./createLogo");
|
|
16
17
|
const createParamsDetails_1 = require("./createParamsDetails");
|
|
17
18
|
const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
|
|
18
19
|
const createStatusCodes_1 = require("./createStatusCodes");
|
|
@@ -39,12 +40,14 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
39
40
|
]);
|
|
40
41
|
}
|
|
41
42
|
exports.createApiPageMD = createApiPageMD;
|
|
42
|
-
function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, securitySchemes, }) {
|
|
43
|
+
function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, }) {
|
|
43
44
|
return (0, utils_1.render)([
|
|
45
|
+
`import ApiLogo from "@theme/ApiLogo";\n`,
|
|
44
46
|
`import Tabs from "@theme/Tabs";\n`,
|
|
45
47
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
46
48
|
(0, createVersionBadge_1.createVersionBadge)(version),
|
|
47
49
|
`# ${(0, lodash_1.escape)(title)}\n\n`,
|
|
50
|
+
(0, createLogo_1.createLogo)(logo, darkLogo),
|
|
48
51
|
(0, createDescription_1.createDescription)(description),
|
|
49
52
|
(0, createAuthentication_1.createAuthentication)(securitySchemes),
|
|
50
53
|
(0, createContactInfo_1.createContactInfo)(contact),
|
package/lib/markdown/schema.js
CHANGED
|
@@ -61,12 +61,25 @@ function getQualifierMessage(schema) {
|
|
|
61
61
|
let qualifierGroups = [];
|
|
62
62
|
if (schema.minLength || schema.maxLength) {
|
|
63
63
|
let lengthQualifier = "";
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
let minLength;
|
|
65
|
+
let maxLength;
|
|
66
|
+
if (schema.minLength && schema.minLength > 1) {
|
|
67
|
+
minLength = `\`>= ${schema.minLength} characters\``;
|
|
68
|
+
}
|
|
69
|
+
if (schema.minLength && schema.minLength === 1) {
|
|
70
|
+
minLength = `\`non-empty\``;
|
|
66
71
|
}
|
|
67
|
-
lengthQualifier += "length";
|
|
68
72
|
if (schema.maxLength) {
|
|
69
|
-
|
|
73
|
+
maxLength = `\`<= ${schema.maxLength} characters\``;
|
|
74
|
+
}
|
|
75
|
+
if (minLength && !maxLength) {
|
|
76
|
+
lengthQualifier += minLength;
|
|
77
|
+
}
|
|
78
|
+
if (maxLength && !minLength) {
|
|
79
|
+
lengthQualifier += maxLength;
|
|
80
|
+
}
|
|
81
|
+
if (minLength && maxLength) {
|
|
82
|
+
lengthQualifier += `${minLength} and ${maxLength}`;
|
|
70
83
|
}
|
|
71
84
|
qualifierGroups.push(lengthQualifier);
|
|
72
85
|
}
|
|
@@ -75,24 +88,34 @@ function getQualifierMessage(schema) {
|
|
|
75
88
|
typeof schema.exclusiveMinimum === "number" ||
|
|
76
89
|
typeof schema.exclusiveMaximum === "number") {
|
|
77
90
|
let minmaxQualifier = "";
|
|
91
|
+
let minimum;
|
|
92
|
+
let maximum;
|
|
78
93
|
if (typeof schema.exclusiveMinimum === "number") {
|
|
79
|
-
|
|
94
|
+
minimum = `\`> ${schema.exclusiveMinimum}\``;
|
|
80
95
|
}
|
|
81
96
|
else if (schema.minimum && !schema.exclusiveMinimum) {
|
|
82
|
-
|
|
97
|
+
minimum = `\`>= ${schema.minimum}\``;
|
|
83
98
|
}
|
|
84
99
|
else if (schema.minimum && schema.exclusiveMinimum === true) {
|
|
85
|
-
|
|
100
|
+
minimum = `\`> ${schema.minimum}\``;
|
|
86
101
|
}
|
|
87
|
-
minmaxQualifier += "value";
|
|
88
102
|
if (typeof schema.exclusiveMaximum === "number") {
|
|
89
|
-
|
|
103
|
+
maximum = `\`< ${schema.exclusiveMaximum}\``;
|
|
90
104
|
}
|
|
91
105
|
else if (schema.maximum && !schema.exclusiveMaximum) {
|
|
92
|
-
|
|
106
|
+
maximum = `\`<= ${schema.maximum}\``;
|
|
93
107
|
}
|
|
94
108
|
else if (schema.maximum && schema.exclusiveMaximum === true) {
|
|
95
|
-
|
|
109
|
+
maximum = `\`< ${schema.maximum}\``;
|
|
110
|
+
}
|
|
111
|
+
if (minimum && !maximum) {
|
|
112
|
+
minmaxQualifier += minimum;
|
|
113
|
+
}
|
|
114
|
+
if (maximum && !minimum) {
|
|
115
|
+
minmaxQualifier += maximum;
|
|
116
|
+
}
|
|
117
|
+
if (minimum && maximum) {
|
|
118
|
+
minmaxQualifier += `${minimum} and ${maximum}`;
|
|
96
119
|
}
|
|
97
120
|
qualifierGroups.push(minmaxQualifier);
|
|
98
121
|
}
|
|
@@ -109,10 +132,10 @@ function getQualifierMessage(schema) {
|
|
|
109
132
|
qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
|
|
110
133
|
}
|
|
111
134
|
if (schema.minItems) {
|
|
112
|
-
qualifierGroups.push(
|
|
135
|
+
qualifierGroups.push(`\`>= ${schema.minItems}\``);
|
|
113
136
|
}
|
|
114
137
|
if (schema.maxItems) {
|
|
115
|
-
qualifierGroups.push(
|
|
138
|
+
qualifierGroups.push(`\`<= ${schema.maxItems}\``);
|
|
116
139
|
}
|
|
117
140
|
if (qualifierGroups.length === 0) {
|
|
118
141
|
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,
|
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)) {
|
|
@@ -61,7 +62,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
61
62
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
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,7 +73,7 @@ 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,
|
|
@@ -101,6 +102,8 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
101
102
|
...openapiData.info,
|
|
102
103
|
tags: (_c = openapiData.tags) === null || _c === void 0 ? void 0 : _c.map((tagName) => { var _a; return getTagDisplayName(tagName.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
|
|
103
104
|
title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
|
|
105
|
+
logo: openapiData.info["x-logo"],
|
|
106
|
+
darkLogo: openapiData.info["x-dark-logo"],
|
|
104
107
|
},
|
|
105
108
|
};
|
|
106
109
|
items.push(infoPage);
|
|
@@ -114,8 +117,8 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
114
117
|
(_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
|
|
115
118
|
}
|
|
116
119
|
const baseId = operationObject.operationId
|
|
117
|
-
? (0,
|
|
118
|
-
: (0,
|
|
120
|
+
? (0, kebabCase_1.default)(operationObject.operationId)
|
|
121
|
+
: (0, kebabCase_1.default)(operationObject.summary);
|
|
119
122
|
const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
|
|
120
123
|
const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
|
|
121
124
|
// Add security schemes so we know how to handle security.
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -31,6 +31,13 @@ export interface InfoObject {
|
|
|
31
31
|
license?: LicenseObject;
|
|
32
32
|
version: string;
|
|
33
33
|
tags?: String[];
|
|
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;
|
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": "0.0.0-
|
|
4
|
+
"version": "0.0.0-411",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=14"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "f3967eda19d631760dc9e7f9e5a358897964f0a7"
|
|
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
|
+
}
|
package/src/markdown/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { createContactInfo } from "./createContactInfo";
|
|
|
18
18
|
import { createDeprecationNotice } from "./createDeprecationNotice";
|
|
19
19
|
import { createDescription } from "./createDescription";
|
|
20
20
|
import { createLicense } from "./createLicense";
|
|
21
|
+
import { createLogo } from "./createLogo";
|
|
21
22
|
import { createParamsDetails } from "./createParamsDetails";
|
|
22
23
|
import { createRequestBodyDetails } from "./createRequestBodyDetails";
|
|
23
24
|
import { createStatusCodes } from "./createStatusCodes";
|
|
@@ -56,14 +57,26 @@ export function createApiPageMD({
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
export function createInfoPageMD({
|
|
59
|
-
info: {
|
|
60
|
+
info: {
|
|
61
|
+
title,
|
|
62
|
+
version,
|
|
63
|
+
description,
|
|
64
|
+
contact,
|
|
65
|
+
license,
|
|
66
|
+
termsOfService,
|
|
67
|
+
logo,
|
|
68
|
+
darkLogo,
|
|
69
|
+
},
|
|
60
70
|
securitySchemes,
|
|
61
71
|
}: InfoPageMetadata) {
|
|
62
72
|
return render([
|
|
73
|
+
`import ApiLogo from "@theme/ApiLogo";\n`,
|
|
63
74
|
`import Tabs from "@theme/Tabs";\n`,
|
|
64
75
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
76
|
+
|
|
65
77
|
createVersionBadge(version),
|
|
66
78
|
`# ${escape(title)}\n\n`,
|
|
79
|
+
createLogo(logo, darkLogo),
|
|
67
80
|
createDescription(description),
|
|
68
81
|
createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
|
|
69
82
|
createContactInfo(contact as ContactObject),
|
|
@@ -17,19 +17,19 @@ describe("getQualifierMessage", () => {
|
|
|
17
17
|
// minLength + maxLength
|
|
18
18
|
//
|
|
19
19
|
it("should render minLength", () => {
|
|
20
|
-
const expected = "**Possible values:**
|
|
20
|
+
const expected = "**Possible values:** `non-empty`";
|
|
21
21
|
const actual = getQualifierMessage({ minLength: 1 });
|
|
22
22
|
expect(actual).toBe(expected);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it("should render maxLength", () => {
|
|
26
|
-
const expected = "**Possible values:**
|
|
26
|
+
const expected = "**Possible values:** `<= 40 characters`";
|
|
27
27
|
const actual = getQualifierMessage({ maxLength: 40 });
|
|
28
28
|
expect(actual).toBe(expected);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
it("should render minLength and maxLength", () => {
|
|
32
|
-
const expected = "**Possible values:**
|
|
32
|
+
const expected = "**Possible values:** `non-empty` and `<= 40 characters`";
|
|
33
33
|
const actual = getQualifierMessage({ minLength: 1, maxLength: 40 });
|
|
34
34
|
expect(actual).toBe(expected);
|
|
35
35
|
});
|
|
@@ -46,7 +46,7 @@ describe("getQualifierMessage", () => {
|
|
|
46
46
|
|
|
47
47
|
it("should render multiple string qualifiers", () => {
|
|
48
48
|
const expected =
|
|
49
|
-
"**Possible values:**
|
|
49
|
+
"**Possible values:** `non-empty` and `<= 40 characters`, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
50
50
|
const actual = getQualifierMessage({
|
|
51
51
|
minLength: 1,
|
|
52
52
|
maxLength: 40,
|
|
@@ -68,49 +68,49 @@ describe("getQualifierMessage", () => {
|
|
|
68
68
|
// minimum + maximum + exclusiveMinimum + exclusiveMaximum
|
|
69
69
|
//
|
|
70
70
|
it("should render minimum", () => {
|
|
71
|
-
const expected = "**Possible values:** 1
|
|
71
|
+
const expected = "**Possible values:** `>= 1`";
|
|
72
72
|
const actual = getQualifierMessage({ minimum: 1 });
|
|
73
73
|
expect(actual).toBe(expected);
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
it("should render maximum", () => {
|
|
77
|
-
const expected = "**Possible values:**
|
|
77
|
+
const expected = "**Possible values:** `<= 40`";
|
|
78
78
|
const actual = getQualifierMessage({ maximum: 40 });
|
|
79
79
|
expect(actual).toBe(expected);
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it("should render numeric exclusiveMinimum", () => {
|
|
83
|
-
const expected = "**Possible values:** 1
|
|
83
|
+
const expected = "**Possible values:** `> 1`";
|
|
84
84
|
const actual = getQualifierMessage({ exclusiveMinimum: 1 });
|
|
85
85
|
expect(actual).toBe(expected);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
it("should render numeric exclusiveMaximum", () => {
|
|
89
|
-
const expected = "**Possible values:**
|
|
89
|
+
const expected = "**Possible values:** `< 40`";
|
|
90
90
|
const actual = getQualifierMessage({ exclusiveMaximum: 40 });
|
|
91
91
|
expect(actual).toBe(expected);
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it("should render boolean exclusiveMinimum", () => {
|
|
95
|
-
const expected = "**Possible values:** 1
|
|
95
|
+
const expected = "**Possible values:** `> 1`";
|
|
96
96
|
const actual = getQualifierMessage({ minimum: 1, exclusiveMinimum: true });
|
|
97
97
|
expect(actual).toBe(expected);
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
it("should render boolean exclusiveMaximum", () => {
|
|
101
|
-
const expected = "**Possible values:**
|
|
101
|
+
const expected = "**Possible values:** `< 40`";
|
|
102
102
|
const actual = getQualifierMessage({ maximum: 40, exclusiveMaximum: true });
|
|
103
103
|
expect(actual).toBe(expected);
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
it("should render minimum when exclusiveMinimum is false", () => {
|
|
107
|
-
const expected = "**Possible values:** 1
|
|
107
|
+
const expected = "**Possible values:** `>= 1`";
|
|
108
108
|
const actual = getQualifierMessage({ minimum: 1, exclusiveMinimum: false });
|
|
109
109
|
expect(actual).toBe(expected);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
it("should render maximum when exclusiveMaximum is false", () => {
|
|
113
|
-
const expected = "**Possible values:**
|
|
113
|
+
const expected = "**Possible values:** `<= 40`";
|
|
114
114
|
const actual = getQualifierMessage({
|
|
115
115
|
maximum: 40,
|
|
116
116
|
exclusiveMaximum: false,
|
|
@@ -119,13 +119,13 @@ describe("getQualifierMessage", () => {
|
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
it("should render minimum and maximum", () => {
|
|
122
|
-
const expected = "**Possible values:** 1
|
|
122
|
+
const expected = "**Possible values:** `>= 1` and `<= 40`";
|
|
123
123
|
const actual = getQualifierMessage({ minimum: 1, maximum: 40 });
|
|
124
124
|
expect(actual).toBe(expected);
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
it("should render boolean exclusiveMinimum and maximum", () => {
|
|
128
|
-
const expected = "**Possible values:** 1
|
|
128
|
+
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
129
129
|
const actual = getQualifierMessage({
|
|
130
130
|
minimum: 1,
|
|
131
131
|
maximum: 40,
|
|
@@ -135,7 +135,7 @@ describe("getQualifierMessage", () => {
|
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
it("should render minimum and boolean exclusiveMaximum", () => {
|
|
138
|
-
const expected = "**Possible values:** 1
|
|
138
|
+
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
139
139
|
const actual = getQualifierMessage({
|
|
140
140
|
minimum: 1,
|
|
141
141
|
maximum: 40,
|
|
@@ -145,7 +145,7 @@ describe("getQualifierMessage", () => {
|
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
it("should render numeric exclusiveMinimum and maximum", () => {
|
|
148
|
-
const expected = "**Possible values:** 1
|
|
148
|
+
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
149
149
|
const actual = getQualifierMessage({
|
|
150
150
|
exclusiveMinimum: 1,
|
|
151
151
|
maximum: 40,
|
|
@@ -154,7 +154,7 @@ describe("getQualifierMessage", () => {
|
|
|
154
154
|
});
|
|
155
155
|
|
|
156
156
|
it("should render minimum and numeric exclusiveMaximum", () => {
|
|
157
|
-
const expected = "**Possible values:** 1
|
|
157
|
+
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
158
158
|
const actual = getQualifierMessage({
|
|
159
159
|
minimum: 1,
|
|
160
160
|
exclusiveMaximum: 40,
|
|
@@ -163,7 +163,7 @@ describe("getQualifierMessage", () => {
|
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
|
|
166
|
-
const expected = "**Possible values:** 1
|
|
166
|
+
const expected = "**Possible values:** `> 1` and `< 40`";
|
|
167
167
|
const actual = getQualifierMessage({
|
|
168
168
|
exclusiveMinimum: 1,
|
|
169
169
|
maximum: 40,
|
package/src/markdown/schema.ts
CHANGED
|
@@ -74,13 +74,28 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
|
|
|
74
74
|
|
|
75
75
|
if (schema.minLength || schema.maxLength) {
|
|
76
76
|
let lengthQualifier = "";
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
let minLength;
|
|
78
|
+
let maxLength;
|
|
79
|
+
if (schema.minLength && schema.minLength > 1) {
|
|
80
|
+
minLength = `\`>= ${schema.minLength} characters\``;
|
|
81
|
+
}
|
|
82
|
+
if (schema.minLength && schema.minLength === 1) {
|
|
83
|
+
minLength = `\`non-empty\``;
|
|
79
84
|
}
|
|
80
|
-
lengthQualifier += "length";
|
|
81
85
|
if (schema.maxLength) {
|
|
82
|
-
|
|
86
|
+
maxLength = `\`<= ${schema.maxLength} characters\``;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (minLength && !maxLength) {
|
|
90
|
+
lengthQualifier += minLength;
|
|
83
91
|
}
|
|
92
|
+
if (maxLength && !minLength) {
|
|
93
|
+
lengthQualifier += maxLength;
|
|
94
|
+
}
|
|
95
|
+
if (minLength && maxLength) {
|
|
96
|
+
lengthQualifier += `${minLength} and ${maxLength}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
qualifierGroups.push(lengthQualifier);
|
|
85
100
|
}
|
|
86
101
|
|
|
@@ -91,21 +106,33 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
|
|
|
91
106
|
typeof schema.exclusiveMaximum === "number"
|
|
92
107
|
) {
|
|
93
108
|
let minmaxQualifier = "";
|
|
109
|
+
let minimum;
|
|
110
|
+
let maximum;
|
|
94
111
|
if (typeof schema.exclusiveMinimum === "number") {
|
|
95
|
-
|
|
112
|
+
minimum = `\`> ${schema.exclusiveMinimum}\``;
|
|
96
113
|
} else if (schema.minimum && !schema.exclusiveMinimum) {
|
|
97
|
-
|
|
114
|
+
minimum = `\`>= ${schema.minimum}\``;
|
|
98
115
|
} else if (schema.minimum && schema.exclusiveMinimum === true) {
|
|
99
|
-
|
|
116
|
+
minimum = `\`> ${schema.minimum}\``;
|
|
100
117
|
}
|
|
101
|
-
minmaxQualifier += "value";
|
|
102
118
|
if (typeof schema.exclusiveMaximum === "number") {
|
|
103
|
-
|
|
119
|
+
maximum = `\`< ${schema.exclusiveMaximum}\``;
|
|
104
120
|
} else if (schema.maximum && !schema.exclusiveMaximum) {
|
|
105
|
-
|
|
121
|
+
maximum = `\`<= ${schema.maximum}\``;
|
|
106
122
|
} else if (schema.maximum && schema.exclusiveMaximum === true) {
|
|
107
|
-
|
|
123
|
+
maximum = `\`< ${schema.maximum}\``;
|
|
108
124
|
}
|
|
125
|
+
|
|
126
|
+
if (minimum && !maximum) {
|
|
127
|
+
minmaxQualifier += minimum;
|
|
128
|
+
}
|
|
129
|
+
if (maximum && !minimum) {
|
|
130
|
+
minmaxQualifier += maximum;
|
|
131
|
+
}
|
|
132
|
+
if (minimum && maximum) {
|
|
133
|
+
minmaxQualifier += `${minimum} and ${maximum}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
109
136
|
qualifierGroups.push(minmaxQualifier);
|
|
110
137
|
}
|
|
111
138
|
|
|
@@ -127,11 +154,11 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
|
|
|
127
154
|
}
|
|
128
155
|
|
|
129
156
|
if (schema.minItems) {
|
|
130
|
-
qualifierGroups.push(
|
|
157
|
+
qualifierGroups.push(`\`>= ${schema.minItems}\``);
|
|
131
158
|
}
|
|
132
159
|
|
|
133
160
|
if (schema.maxItems) {
|
|
134
|
-
qualifierGroups.push(
|
|
161
|
+
qualifierGroups.push(`\`<= ${schema.maxItems}\``);
|
|
135
162
|
}
|
|
136
163
|
|
|
137
164
|
if (qualifierGroups.length === 0) {
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -13,7 +13,8 @@ import sdk from "@paloaltonetworks/postman-collection";
|
|
|
13
13
|
import Collection from "@paloaltonetworks/postman-collection";
|
|
14
14
|
import chalk from "chalk";
|
|
15
15
|
import fs from "fs-extra";
|
|
16
|
-
import
|
|
16
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
17
|
+
import kebabCase from "lodash/kebabCase";
|
|
17
18
|
|
|
18
19
|
import { isURL } from "../index";
|
|
19
20
|
import {
|
|
@@ -54,7 +55,7 @@ async function createPostmanCollection(
|
|
|
54
55
|
openapiData: OpenApiObject
|
|
55
56
|
): Promise<Collection> {
|
|
56
57
|
// Create copy of openapiData
|
|
57
|
-
const data =
|
|
58
|
+
const data = cloneDeep(openapiData) as OpenApiObject;
|
|
58
59
|
|
|
59
60
|
// Including `servers` breaks postman, so delete all of them.
|
|
60
61
|
delete data.servers;
|
|
@@ -127,6 +128,8 @@ function createItems(
|
|
|
127
128
|
getTagDisplayName(tagName.name!, openapiData.tags ?? [])
|
|
128
129
|
),
|
|
129
130
|
title: openapiData.info.title ?? "Introduction",
|
|
131
|
+
logo: openapiData.info["x-logo"]! as any,
|
|
132
|
+
darkLogo: openapiData.info["x-dark-logo"]! as any,
|
|
130
133
|
},
|
|
131
134
|
};
|
|
132
135
|
items.push(infoPage);
|
package/src/openapi/types.ts
CHANGED
|
@@ -42,6 +42,14 @@ export interface InfoObject {
|
|
|
42
42
|
license?: LicenseObject;
|
|
43
43
|
version: string;
|
|
44
44
|
tags?: String[];
|
|
45
|
+
"x-logo"?: LogoObject;
|
|
46
|
+
"x-dark-logo"?: LogoObject;
|
|
47
|
+
logo?: LogoObject;
|
|
48
|
+
darkLogo?: LogoObject;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface LogoObject {
|
|
52
|
+
url?: string;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
export interface ContactObject {
|